Browse Source

Allow reaching the wrapped Item through GeneratedPropertyItem (#20032)

Change-Id: Ic38c2803b3d83e76fa74d21490a4277c6037b950
feature/vaadin8-book-vol2
Anna Koskinen 8 years ago
parent
commit
4e869e05d3

+ 14
- 2
server/src/main/java/com/vaadin/data/util/GeneratedPropertyContainer.java View File

@@ -122,9 +122,11 @@ public class GeneratedPropertyContainer extends AbstractContainer implements
}

/**
* Item implementation for generated properties.
* Item implementation for generated properties, used to wrap the Item that
* belongs to the wrapped container. To reach that Item use
* {@link #getWrappedItem()}
*/
protected class GeneratedPropertyItem implements Item {
public class GeneratedPropertyItem implements Item {

private Item wrappedItem;
private Object itemId;
@@ -198,6 +200,16 @@ public class GeneratedPropertyContainer extends AbstractContainer implements
private GeneratedPropertyContainer getContainer() {
return GeneratedPropertyContainer.this;
}

/**
* Returns the wrapped Item that belongs to the wrapped container
*
* @return wrapped item.
* @since
*/
public Item getWrappedItem() {
return wrappedItem;
}
};

/**

+ 10
- 0
server/src/test/java/com/vaadin/data/util/GeneratedPropertyContainerTest.java View File

@@ -31,6 +31,7 @@ import com.vaadin.data.Container.PropertySetChangeEvent;
import com.vaadin.data.Container.PropertySetChangeListener;
import com.vaadin.data.Item;
import com.vaadin.data.sort.SortOrder;
import com.vaadin.data.util.GeneratedPropertyContainer.GeneratedPropertyItem;
import com.vaadin.data.util.filter.Compare;
import com.vaadin.data.util.filter.UnsupportedFilterException;

@@ -285,6 +286,15 @@ public class GeneratedPropertyContainerTest {
.getContainerPropertyIds().contains("foo"));
}

@Test
public void testGetWrappedItem() {
Object itemId = wrappedContainer.getItemIds().iterator().next();
Item wrappedItem = wrappedContainer.getItem(itemId);
GeneratedPropertyItem generatedPropertyItem = (GeneratedPropertyItem) container
.getItem(itemId);
assertEquals(wrappedItem, generatedPropertyItem.getWrappedItem());
}

private Indexed createContainer() {
wrappedContainer = new IndexedContainer();
wrappedContainer.addContainerProperty("foo", String.class, "foo");

Loading…
Cancel
Save