Author: rwhitcomb Date: Thu Feb 8 01:41:49 2018 New Revision: 1823532 URL: http://svn.apache.org/viewvc?rev=1823532&view=rev Log: PIVOT-734: Several changes necessary to solve this (although all these may be a bit of overkill, at least the problem is solved): * The earlier changes mentioned in the JIRA issue involving when to load the children in the skin. * Two new calls to repaint in the case of "showEmptyBranchControls" is false. * The main thing: update "monitorBranch" to monitor the branch itself when called from "setSelectedPath" (if the node is indeed a branch) so that when updates are made the branch will get repainted, and the other changes will cause the correct branch control to actually get painted.
Modified: pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot734.java pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java Modified: pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot734.java URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot734.java?rev=1823532&r1=1823531&r2=1823532&view=diff ============================================================================== --- pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot734.java (original) +++ pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot734.java Thu Feb 8 01:41:49 2018 @@ -100,8 +100,7 @@ public class Pivot734 implements Applica @Override public void buttonPressed(Button button) { Object x = tree.getSelectedNode(); - System.out.println("remove a 'new branch' element under the selected element :: " - + x); + System.out.println("remove a 'new branch' element under the selected element :: " + x); if (x != null && x instanceof TreeBranch) { ((TreeBranch) x).remove(newBranch); Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java?rev=1823532&r1=1823531&r2=1823532&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTreeViewSkin.java Thu Feb 8 01:41:49 2018 @@ -388,7 +388,7 @@ public class TerraTreeViewSkin extends C */ @SuppressWarnings("unchecked") public void loadChildren() { - if (children == null) { + if (children == null || children.isEmpty()) { List<Object> dataLocal = (List<Object>) this.data; int count = dataLocal.getLength(); @@ -658,7 +658,7 @@ public class TerraTreeViewSkin extends C boolean showBranchControl = true; if (!showEmptyBranchControls) { branchInfo.loadChildren(); - showBranchControl = !branchInfo.children.isEmpty(); + showBranchControl = !(branchInfo.children == null || branchInfo.children.isEmpty()); } if (showBranchControl) { @@ -2072,6 +2072,12 @@ public class TerraTreeViewSkin extends C // Add the node to the visible nodes list addVisibleNode(branchInfo, index); + + // If the empty branch controls are not shown, then this event might + // need a repaint of the parent + if (!showEmptyBranchControls) { + repaintNode(branchInfo); + } } @Override @@ -2085,6 +2091,12 @@ public class TerraTreeViewSkin extends C if (branchInfo.children != null) { branchInfo.children.remove(index, count); } + + // If the empty branch controls are not shown, then this event might + // need a repaint of the parent + if (!showEmptyBranchControls) { + repaintNode(branchInfo); + } } @Override Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java?rev=1823532&r1=1823531&r2=1823532&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java Thu Feb 8 01:41:49 2018 @@ -305,13 +305,9 @@ public class TreeView extends Component private Path getPath() { Path path = new Path(); - BranchHandler handler = this; - - while (handler.parent != null) { + for (BranchHandler handler = this; handler.parent != null; handler = handler.parent) { int index = ((List<Object>) handler.parent.branchData).indexOf(handler.branchData); path.insert(index, 0); - - handler = handler.parent; } return path; @@ -910,7 +906,7 @@ public class TreeView extends Component } if (selectMode == SelectMode.SINGLE && selectedPaths.getLength() > 1) { - throw new IllegalArgumentException("Selection length is greater than 1."); + throw new IllegalArgumentException("Cannot select more than one path in SINGLE select mode."); } Sequence<Path> previousSelectedPaths = this.selectedPaths; @@ -924,8 +920,9 @@ public class TreeView extends Component for (int i = 0, n = selectedPaths.getLength(); i < n; i++) { Path path = selectedPaths.get(i); - // Monitor the path's parent - monitorBranch(new Path(path, path.getLength() - 1)); + // Monitor the branch itself, because if showEmptyBranchControls is false + // we need repaints as children are added/removed from this branch. + monitorBranch(path, true); // Update the selection this.selectedPaths.add(new ImmutablePath(path)); @@ -1016,7 +1013,7 @@ public class TreeView extends Component int index = selectedPaths.indexOf(path); if (index < 0) { // Monitor the path's parent - monitorBranch(new Path(path, path.getLength() - 1)); + monitorBranch(path, false); // Update the selection selectedPaths.add(new ImmutablePath(path)); @@ -1328,7 +1325,7 @@ public class TreeView extends Component if (checked) { // Monitor the path's parent - monitorBranch(new Path(path, path.getLength() - 1)); + monitorBranch(path, false); // Update the checked paths checkedPaths.add(new ImmutablePath(path)); @@ -1432,8 +1429,8 @@ public class TreeView extends Component int index = expandedPaths.indexOf(path); if (expanded && index < 0) { - // Monitor the branch - monitorBranch(path); + // Monitor the branch itself + monitorBranch(path, true); // Update the expanded paths expandedPaths.add(new ImmutablePath(path)); @@ -1542,13 +1539,17 @@ public class TreeView extends Component * node along the specified path. * * @param path A path leading to a nested branch node. + * @param includeSelf If <tt>true</tt> then include the last path element (if + * it is a branch), or <tt>false</tt> to just iterate to the parent branch in + * the path. * @throws IndexOutOfBoundsException If a path element is out of bounds. * @throws IllegalArgumentException If the path contains any leaf nodes. */ - private void monitorBranch(Path path) { + private void monitorBranch(Path path, boolean includeSelf) { BranchHandler parent = rootBranchHandler; - for (int i = 0, n = path.getLength(); i < n; i++) { + int n = includeSelf ? path.getLength() : path.getLength() - 1; + for (int i = 0; i < n; i++) { int index = path.get(i); if (index < 0 || index >= parent.getLength()) { throw new IndexOutOfBoundsException("Branch path out of bounds: " + path); @@ -1560,7 +1561,10 @@ public class TreeView extends Component List<?> parentBranchData = parent.getBranchData(); Object childData = parentBranchData.get(index); - if (!(childData instanceof List<?>)) { + if (childData == null || !(childData instanceof List<?>)) { + if (includeSelf && i == n - 1) { + return; + } throw new IllegalArgumentException("Unexpected leaf in branch path: " + path); }