summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/main/java/com/vaadin/ui/TreeGrid.java55
-rw-r--r--server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java6
2 files changed, 35 insertions, 26 deletions
diff --git a/server/src/main/java/com/vaadin/ui/TreeGrid.java b/server/src/main/java/com/vaadin/ui/TreeGrid.java
index 24c55fce2b..2ff026a758 100644
--- a/server/src/main/java/com/vaadin/ui/TreeGrid.java
+++ b/server/src/main/java/com/vaadin/ui/TreeGrid.java
@@ -85,8 +85,8 @@ public class TreeGrid<T> extends Grid<T>
* the bean type to use, not {@code null}
*/
public TreeGrid(Class<T> beanType) {
- this(BeanPropertySet.get(beanType),
- new HierarchicalDataCommunicator<>());
+ super(beanType, new HierarchicalDataCommunicator<>());
+ registerTreeGridRpc();
}
/**
@@ -120,30 +120,7 @@ public class TreeGrid<T> extends Grid<T>
protected TreeGrid(PropertySet<T> propertySet,
HierarchicalDataCommunicator<T> dataCommunicator) {
super(propertySet, dataCommunicator);
-
- registerRpc((NodeCollapseRpc) (rowKey, rowIndex, collapse,
- userOriginated) -> {
- T item = getDataCommunicator().getKeyMapper().get(rowKey);
- if (collapse && getDataCommunicator().isExpanded(item)) {
- getDataCommunicator().doCollapse(item, Optional.of(rowIndex));
- fireCollapseEvent(
- getDataCommunicator().getKeyMapper().get(rowKey),
- userOriginated);
- } else if (!collapse && !getDataCommunicator().isExpanded(item)) {
- getDataCommunicator().doExpand(item, Optional.of(rowIndex));
- fireExpandEvent(
- getDataCommunicator().getKeyMapper().get(rowKey),
- userOriginated);
- }
- });
-
- registerRpc((FocusParentRpc) (rowKey, cellIndex) -> {
- Integer parentIndex = getDataCommunicator().getParentIndex(
- getDataCommunicator().getKeyMapper().get(rowKey));
- if (parentIndex != null) {
- getRpcProxy(FocusRpc.class).focusCell(parentIndex, cellIndex);
- }
- });
+ registerTreeGridRpc();
}
/**
@@ -194,6 +171,32 @@ public class TreeGrid<T> extends Grid<T>
new HierarchicalDataCommunicator<>());
}
+ private void registerTreeGridRpc() {
+ registerRpc((NodeCollapseRpc) (rowKey, rowIndex, collapse,
+ userOriginated) -> {
+ T item = getDataCommunicator().getKeyMapper().get(rowKey);
+ if (collapse && getDataCommunicator().isExpanded(item)) {
+ getDataCommunicator().doCollapse(item, Optional.of(rowIndex));
+ fireCollapseEvent(
+ getDataCommunicator().getKeyMapper().get(rowKey),
+ userOriginated);
+ } else if (!collapse && !getDataCommunicator().isExpanded(item)) {
+ getDataCommunicator().doExpand(item, Optional.of(rowIndex));
+ fireExpandEvent(
+ getDataCommunicator().getKeyMapper().get(rowKey),
+ userOriginated);
+ }
+ });
+
+ registerRpc((FocusParentRpc) (rowKey, cellIndex) -> {
+ Integer parentIndex = getDataCommunicator().getParentIndex(
+ getDataCommunicator().getKeyMapper().get(rowKey));
+ if (parentIndex != null) {
+ getRpcProxy(FocusRpc.class).focusCell(parentIndex, cellIndex);
+ }
+ });
+ }
+
/**
* Adds an ExpandListener to this TreeGrid.
*
diff --git a/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java b/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java
index 18b6a31b0d..279f4fd24c 100644
--- a/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java
+++ b/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java
@@ -8,6 +8,7 @@ import org.junit.Test;
import com.vaadin.data.TreeData;
import com.vaadin.data.provider.TreeDataProvider;
+import com.vaadin.tests.data.bean.Person;
import com.vaadin.ui.Grid.Column;
import com.vaadin.ui.TreeGrid;
import com.vaadin.ui.renderers.TextRenderer;
@@ -59,4 +60,9 @@ public class TreeGridTest {
treeGrid.getHierarchyColumn());
}
+ @Test
+ public void testBeanTypeConstructor() {
+ TreeGrid<Person> treeGrid = new TreeGrid<>(Person.class);
+ assertEquals(Person.class, treeGrid.getBeanType());
+ }
}