From 21c54c9228a63ac6c199b0a70603a72f6041586a Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 17 May 2017 11:26:59 +0300 Subject: [PATCH] Add getters for providers to Tree and TreeGrid --- .../HierarchicalDataCommunicator.java | 39 ++++++++++++------ server/src/main/java/com/vaadin/ui/Tree.java | 40 +++++++++++++++++++ .../src/main/java/com/vaadin/ui/TreeGrid.java | 9 +++++ 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java index ce6f7db13e..ca8ccc89dd 100644 --- a/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java +++ b/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java @@ -79,8 +79,7 @@ public class HierarchicalDataCommunicator extends DataCommunicator { */ public HierarchicalDataCommunicator() { super(); - dataProvider = new TreeDataProvider<>( - new TreeData<>()); + dataProvider = new TreeDataProvider<>(new TreeData<>()); } @Override @@ -226,24 +225,29 @@ public class HierarchicalDataCommunicator extends DataCommunicator { JsonObject hierarchyData = Json.createObject(); if (depth != -1) { - hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_DEPTH, depth); + hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_DEPTH, + depth); } boolean isLeaf = !getDataProvider().hasChildren(item); if (isLeaf) { - hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_LEAF, true); + hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_LEAF, + true); } else { String key = getKeyMapper().key(item); - hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_COLLAPSED, + hierarchyData.put( + HierarchicalDataCommunicatorConstants.ROW_COLLAPSED, mapper.isCollapsed(key)); - hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_LEAF, false); + hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_LEAF, + false); hierarchyData.put( HierarchicalDataCommunicatorConstants.ROW_COLLAPSE_ALLOWED, itemCollapseAllowedProvider.test(item)); } // add hierarchy information to row as metadata - dataObject.put(HierarchicalDataCommunicatorConstants.ROW_HIERARCHY_DESCRIPTION, + dataObject.put( + HierarchicalDataCommunicatorConstants.ROW_HIERARCHY_DESCRIPTION, hierarchyData); return dataObject; @@ -386,8 +390,7 @@ public class HierarchicalDataCommunicator extends DataCommunicator { } int collapsedSubTreeSize = mapper.collapse(collapsedRowKey, collapsedRowIndex); - getClientRpc().removeRows(collapsedRowIndex + 1, - collapsedSubTreeSize); + getClientRpc().removeRows(collapsedRowIndex + 1, collapsedSubTreeSize); // FIXME seems like a slight overkill to do this just for refreshing // expanded status @@ -435,8 +438,10 @@ public class HierarchicalDataCommunicator extends DataCommunicator { expandedNodeSize); rowKeysPendingExpand.remove(expandedRowKey); - boolean success = doPushRows(Range.withLength(expandedRowIndex + 1, - Math.min(expandedNodeSize, latestCacheSize)), expandedNodeSize); + boolean success = doPushRows( + Range.withLength(expandedRowIndex + 1, + Math.min(expandedNodeSize, latestCacheSize)), + expandedNodeSize); if (success) { // FIXME seems like a slight overkill to do this just for refreshing @@ -531,10 +536,20 @@ public class HierarchicalDataCommunicator extends DataCommunicator { /** * Returns parent index for the row or {@code null} * - * @param rowIndex the row index + * @param rowIndex + * the row index * @return the parent index or {@code null} for top-level items */ public Integer getParentIndex(int rowIndex) { return mapper.getParentIndex(rowIndex); } + + /** + * Gets the item collapse allowed provider. + * + * @return the item collapse allowed provider + */ + public ItemCollapseAllowedProvider getItemCollapseAllowedProvider() { + return itemCollapseAllowedProvider; + } } diff --git a/server/src/main/java/com/vaadin/ui/Tree.java b/server/src/main/java/com/vaadin/ui/Tree.java index 85a9e3a615..4ddd74caa4 100644 --- a/server/src/main/java/com/vaadin/ui/Tree.java +++ b/server/src/main/java/com/vaadin/ui/Tree.java @@ -539,6 +539,46 @@ public class Tree extends Composite treeGrid.setStyleGenerator(styleGenerator); } + /** + * Gets the item caption generator. + * + * @return the item caption generator + */ + public ItemCaptionGenerator getItemCaptionGenerator() { + return captionGenerator; + } + + /** + * Gets the item icon generator. + * + * @see IconGenerator + * + * @return the item icon generator + */ + public IconGenerator getItemIconGenerator() { + return iconProvider; + } + + /** + * Gets the item collapse allowed provider. + * + * @return the item collapse allowed provider + */ + public ItemCollapseAllowedProvider getItemCollapseAllowedProvider() { + return treeGrid.getItemCollapseAllowedProvider(); + } + + /** + * Gets the style generator. + * + * @see StyleGenerator + * + * @return the item style generator + */ + public StyleGenerator getStyleGenerator() { + return treeGrid.getStyleGenerator(); + } + /** * Adds an item click listener. The listener is called when an item of this * {@code Tree} is clicked. diff --git a/server/src/main/java/com/vaadin/ui/TreeGrid.java b/server/src/main/java/com/vaadin/ui/TreeGrid.java index e526f3b7cd..b73794e25a 100644 --- a/server/src/main/java/com/vaadin/ui/TreeGrid.java +++ b/server/src/main/java/com/vaadin/ui/TreeGrid.java @@ -548,4 +548,13 @@ public class TreeGrid extends Grid private void fireCollapseEvent(T item, boolean userOriginated) { fireEvent(new CollapseEvent<>(this, item, userOriginated)); } + + /** + * Gets the item collapse allowed provider. + * + * @return the item collapse allowed provider + */ + public ItemCollapseAllowedProvider getItemCollapseAllowedProvider() { + return getDataCommunicator().getItemCollapseAllowedProvider(); + } } -- 2.39.5