UpdaterTreeNode extends DefaultMutableTreeNode implements Comparable<UpdaterTreeNode>, SdkUpdaterConfigPanel.MultiStateRow { @Override public final void cycleState() { if (getCurrentState() == null) { return; } if (getCurrentState() == PackageNodeModel.SelectedState.NOT_INSTALLED) { if (canHaveMixedState()) { setState(PackageNodeModel.SelectedState.MIXED); } else { setState(PackageNodeModel.SelectedState.INSTALLED); } } else if (getCurrentState() == PackageNodeModel.SelectedState.INSTALLED) { setState(PackageNodeModel.SelectedState.NOT_INSTALLED); } else { setState(PackageNodeModel.SelectedState.INSTALLED); } }  abstract PackageNodeModel.SelectedState getInitialState(); abstract PackageNodeModel.SelectedState getCurrentState(); final void resetState(); boolean includeInSummary(); boolean isPrimary(); @Override final void cycleState(); @NotNull String getStatusString(); @Override int compareTo(@NotNull UpdaterTreeNode o); void customizeRenderer(Renderer renderer,
                                JTree tree,
                                boolean selected,
                                boolean expanded,
                                boolean leaf,
                                int row,
                                boolean hasFocus);  }
@Test public void testParentTreeNodeState() throws Exception { ParentTreeNode node = new ParentTreeNode("foo"); addUnselectedChildren(node); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED)); node = new ParentTreeNode(new AndroidVersion(10, null)); addSelectedChildren(node); validateState(node, INSTALLED, INSTALLED, ImmutableList.of(INSTALLED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, INSTALLED, ImmutableList.of(INSTALLED, INSTALLED)); node = new ParentTreeNode(new AndroidVersion(10, null)); addMixedChildren(node); validateState(node, MIXED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED)); node.cycleState(); validateState(node, INSTALLED, MIXED, ImmutableList.of(INSTALLED, INSTALLED, INSTALLED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, MIXED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, MIXED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED)); }
@Test public void testMultiVersionTreeNodeState() throws Exception { List<DetailsTreeNode> children = getMultiVersionChildren(); MultiVersionTreeNode node = new MultiVersionTreeNode(children); children.forEach(node::add); validateState(node, MIXED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED)); node.cycleState(); validateState(node, INSTALLED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, MIXED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, MIXED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED)); children = getMultiVersionChildren(); children.add(createMultiVersionChild(false, true, "3.0")); node = new MultiVersionTreeNode(children); children.forEach(node::add); validateState(node, MIXED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, MIXED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, MIXED, MIXED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED, NOT_INSTALLED)); children = getMultiVersionChildren(); children.add(createMultiVersionChild(true, false,"3.0")); node = new MultiVersionTreeNode(children); children.forEach(node::add); validateState(node, INSTALLED, INSTALLED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, INSTALLED, ImmutableList.of(NOT_INSTALLED, INSTALLED, INSTALLED, MIXED, INSTALLED)); children = Lists.newArrayList(createMultiVersionChild(false, true, "1.0"), createMultiVersionChild(false, true, "2.0")); node = new MultiVersionTreeNode(children); children.forEach(node::add); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED)); }
@Test public void testSummaryTreeNodeState() throws Exception { TestTreeNode n1 = new TestTreeNode(NOT_INSTALLED, false); n1.setIncludeInSummary(true); TestTreeNode n2 = new TestTreeNode(NOT_INSTALLED, false); n2.setIncludeInSummary(true); TestTreeNode n3 = new TestTreeNode(NOT_INSTALLED, false); ImmutableSet<UpdaterTreeNode> children = ImmutableSet.of(n1, n2, n3); SummaryTreeNode node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children); children.forEach(node::add); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); n3 = new TestTreeNode(INSTALLED, false); children = ImmutableSet.of(n1, n2, n3); node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children); children.forEach(node::add); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, INSTALLED)); node.cycleState(); validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, INSTALLED)); n1 = new TestTreeNode(INSTALLED, false); n1.setIncludeInSummary(true); n2 = new TestTreeNode(INSTALLED, false); n2.setIncludeInSummary(true); n3 = new TestTreeNode(NOT_INSTALLED, false); children = ImmutableSet.of(n1, n2, n3); node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children); children.forEach(node::add); validateState(node, INSTALLED, INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED)); n2 = new TestTreeNode(NOT_INSTALLED, false); n2.setIncludeInSummary(true); children = ImmutableSet.of(n1, n2, n3); node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children); children.forEach(node::add); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); n2 = new TestTreeNode(MIXED, true); n2.setIncludeInSummary(true); children = ImmutableSet.of(n1, n2, n3); node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children); children.forEach(node::add); validateState(node, MIXED, MIXED, ImmutableList.of(INSTALLED, MIXED, NOT_INSTALLED)); node.cycleState(); validateState(node, INSTALLED, MIXED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, NOT_INSTALLED, MIXED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED)); node.cycleState(); validateState(node, MIXED, MIXED, ImmutableList.of(INSTALLED, MIXED, NOT_INSTALLED)); }