summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-08-02 15:32:31 +0300
committerHenri Sara <henri.sara@gmail.com>2017-08-02 15:32:31 +0300
commit5b0accf49295cab4a494b2949d067ff7655d3c42 (patch)
tree2f932126a0665e92d865e1c9eba0c54f02c00036 /server/src
parent9153f1534aa78dc0c85c0a512f956d30c0e1c570 (diff)
downloadvaadin-framework-5b0accf49295cab4a494b2949d067ff7655d3c42.tar.gz
vaadin-framework-5b0accf49295cab4a494b2949d067ff7655d3c42.zip
Add automatic recalculation of Tree width on expand/collapse (#9767)
Fixes #9628
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main/java/com/vaadin/ui/Tree.java46
1 files changed, 42 insertions, 4 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Tree.java b/server/src/main/java/com/vaadin/ui/Tree.java
index ddf933cb01..aeb2dcfb6d 100644
--- a/server/src/main/java/com/vaadin/ui/Tree.java
+++ b/server/src/main/java/com/vaadin/ui/Tree.java
@@ -238,6 +238,7 @@ public class Tree<T> extends Composite
private ItemCaptionGenerator<T> captionGenerator = String::valueOf;
private IconGenerator<T> iconProvider = t -> null;
private final TreeRenderer renderer;
+ private boolean autoRecalculateWidth = true;
/**
* Constructs a new Tree Component.
@@ -259,10 +260,18 @@ public class Tree<T> extends Composite
treeGrid.setHeightUndefined();
treeGrid.setHeightMode(HeightMode.UNDEFINED);
- treeGrid.addExpandListener(e -> fireExpandEvent(e.getExpandedItem(),
- e.isUserOriginated()));
- treeGrid.addCollapseListener(e -> fireCollapseEvent(
- e.getCollapsedItem(), e.isUserOriginated()));
+ treeGrid.addExpandListener(e -> {
+ fireExpandEvent(e.getExpandedItem(), e.isUserOriginated());
+ if (autoRecalculateWidth) {
+ treeGrid.recalculateColumnWidths();
+ }
+ });
+ treeGrid.addCollapseListener(e -> {
+ fireCollapseEvent(e.getCollapsedItem(), e.isUserOriginated());
+ if (autoRecalculateWidth) {
+ treeGrid.recalculateColumnWidths();
+ }
+ });
treeGrid.addItemClickListener(e -> fireEvent(
new ItemClick<>(this, e.getItem(), e.getMouseEventDetails())));
}
@@ -790,6 +799,35 @@ public class Tree<T> extends Composite
}
/**
+ * Returns the current state of automatic width recalculation.
+ *
+ * @return {@code true} if enabled; {@code false} if disabled
+ *
+ * @since 8.1.1
+ */
+ public boolean isAutoRecalculateWidth() {
+ return autoRecalculateWidth;
+ }
+
+ /**
+ * Sets the automatic width recalculation on or off. This feature is on by
+ * default.
+ *
+ * @param autoRecalculateWidth
+ * {@code true} to enable recalculation; {@code false} to turn it
+ * off
+ *
+ * @since 8.1.1
+ */
+ public void setAutoRecalculateWidth(boolean autoRecalculateWidth) {
+ this.autoRecalculateWidth = autoRecalculateWidth;
+
+ treeGrid.getColumns().get(0)
+ .setMinimumWidthFromContent(autoRecalculateWidth);
+ treeGrid.recalculateColumnWidths();
+ }
+
+ /**
* Adds a context click listener that gets notified when a context click
* happens.
*