From 8d4518822770c79893aa06cfa22d275931f5b422 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Thu, 29 Aug 2013 14:26:04 +0300 Subject: [PATCH] Preserve open nodes in debug window hierarchy over refresh (#12472) Change-Id: Ib64f40db6e5568e236db410b0ad0ec2960be37f7 --- client/src/com/vaadin/client/SimpleTree.java | 8 +++ .../client/debug/internal/HierarchyPanel.java | 50 +++++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/client/src/com/vaadin/client/SimpleTree.java b/client/src/com/vaadin/client/SimpleTree.java index 7370496cb8..edfa23fb13 100644 --- a/client/src/com/vaadin/client/SimpleTree.java +++ b/client/src/com/vaadin/client/SimpleTree.java @@ -116,6 +116,14 @@ public class SimpleTree extends ComplexPanel implements HasDoubleClickHandlers { } } + public boolean isOpen() { + return "-".equals(handle.getInnerHTML()); + } + + public String getCaption() { + return text.getInnerText(); + } + public SimpleTree(String caption) { this(); setText(caption); diff --git a/client/src/com/vaadin/client/debug/internal/HierarchyPanel.java b/client/src/com/vaadin/client/debug/internal/HierarchyPanel.java index 759dbf00dd..755f076b7a 100644 --- a/client/src/com/vaadin/client/debug/internal/HierarchyPanel.java +++ b/client/src/com/vaadin/client/debug/internal/HierarchyPanel.java @@ -16,6 +16,7 @@ package com.vaadin.client.debug.internal; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import com.google.gwt.event.dom.client.ClickEvent; @@ -24,11 +25,13 @@ import com.google.gwt.event.dom.client.DoubleClickEvent; import com.google.gwt.event.dom.client.DoubleClickHandler; import com.google.gwt.event.dom.client.HasDoubleClickHandlers; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration; import com.vaadin.client.ApplicationConnection; +import com.vaadin.client.FastStringSet; import com.vaadin.client.ServerConnector; import com.vaadin.client.SimpleTree; import com.vaadin.client.Util; @@ -45,15 +48,21 @@ public class HierarchyPanel extends FlowPanel { private List listeners = new ArrayList(); public void update() { + // Try to keep track of currently open nodes and reopen them + FastStringSet openNodes = FastStringSet.create(); + Iterator it = iterator(); + while (it.hasNext()) { + collectOpenNodes(it.next(), openNodes); + } + clear(); - // TODO Clearing and rebuilding the contents is not optimal for UX as - // any previous expansions are lost. + SimplePanel trees = new SimplePanel(); for (ApplicationConnection application : ApplicationConfiguration .getRunningApplications()) { ServerConnector uiConnector = application.getUIConnector(); - Widget connectorTree = buildConnectorTree(uiConnector); + Widget connectorTree = buildConnectorTree(uiConnector, openNodes); trees.add(connectorTree); } @@ -61,7 +70,35 @@ public class HierarchyPanel extends FlowPanel { add(trees); } - private Widget buildConnectorTree(final ServerConnector connector) { + /** + * Adds the captions of all open (non-leaf) nodes in the hierarchy tree + * recursively. + * + * @param widget + * the widget in which to search for open nodes (if SimpleTree) + * @param openNodes + * the set in which open nodes should be added + */ + private void collectOpenNodes(Widget widget, FastStringSet openNodes) { + if (widget instanceof SimpleTree) { + SimpleTree tree = (SimpleTree) widget; + if (tree.isOpen()) { + openNodes.add(tree.getCaption()); + } else { + // no need to look inside closed nodes + return; + } + } + if (widget instanceof HasWidgets) { + Iterator it = ((HasWidgets) widget).iterator(); + while (it.hasNext()) { + collectOpenNodes(it.next(), openNodes); + } + } + } + + private Widget buildConnectorTree(final ServerConnector connector, + FastStringSet openNodes) { String connectorString = Util.getConnectorString(connector); List children = connector.getChildren(); @@ -88,7 +125,10 @@ public class HierarchyPanel extends FlowPanel { } }; for (ServerConnector child : children) { - tree.add(buildConnectorTree(child)); + tree.add(buildConnectorTree(child, openNodes)); + } + if (openNodes.contains(connectorString)) { + tree.open(false); } widget = tree; } -- 2.39.5