MCTMutableTreeNode extends DefaultMutableTreeNode { @Override public void add(MutableTreeNode newChild) { super.add(newChild); View viewManifestation = View.class.cast(DefaultMutableTreeNode.class.cast(newChild).getUserObject()); if (viewManifestation != View.NULL_VIEW_MANIFESTATION) viewManifestation.putClientProperty(PARENT_CLIENT_PROPERTY_NAME, getParentTree()); } MCTMutableTreeNode();  MCTMutableTreeNode(JComponent userObject);  MCTMutableTreeNode(JComponent userObject, JTree parentTree);  MCTMutableTreeNode(JComponent userObject, boolean allowsChildren);  MCTMutableTreeNode(JComponent userObject, JTree parentTree, boolean allowsChildren); @Override void add(MutableTreeNode newChild); void setProxy(boolean isProxy); boolean isProxy(); boolean isVisible(); @Override TreeNode getChildAt(int index); @Override int getChildCount(); @Override void removeAllChildren(); void removeAllChildren(PropertyChangeListener listener); JTree getParentTree(); void setParentTree(JTree parentTree); void addChild(int index, MCTMutableTreeNode newNode, PropertyChangeListener listener); void refresh(MCTMutableTreeNode childNode); void refresh(); void removeChild(MCTMutableTreeNode childNode, PropertyChangeListener listener); TreePath getTreePath(); static final String PARENT_CLIENT_PROPERTY_NAME; }
@Test public void testAddChildrenAllowable() { MCTMutableTreeNode aChildNode= new MCTMutableTreeNode(mockViewManif, true); boolean exceptionThrown = false; try { MCTMutableTreeNode childrenProhibitedNode = new MCTMutableTreeNode(mockViewManif, false); childrenProhibitedNode.add(aChildNode); } catch (IllegalStateException e) { exceptionThrown = true; } assertTrue(exceptionThrown); exceptionThrown = false; try { MCTMutableTreeNode childrenAllowedNode = new MCTMutableTreeNode(mockViewManif, true); childrenAllowedNode.add(aChildNode); } catch (IllegalStateException e) { exceptionThrown = true; } assertFalse(exceptionThrown); }