コード例 #1
0
 @Override
 public Object getParentElement(final Object element) {
   NodeElement nodeElement = (NodeElement) element;
   return nodeElement.getForcedParent() != null
       ? nodeElement.getForcedParent()
       : myChild2Parent.get(nodeElement);
 }
コード例 #2
0
    @Nullable
    private Node remove(final NodeElement name, boolean removeRefToParent) {
      final Iterator<Node> kids = myChildElements.iterator();
      Node removed = null;
      while (kids.hasNext()) {
        Node each = kids.next();
        if (name.equals(each.myElement)) {
          kids.remove();
          removed = each;
          break;
        }
      }

      if (removeRefToParent) {
        myStructure.myChild2Parent.remove(name);
      }

      return removed;
    }
コード例 #3
0
  @Nullable
  private DefaultMutableTreeNode findNode(
      DefaultMutableTreeNode treeNode, NodeElement toFind, boolean shouldBeSelected) {
    final Object object = treeNode.getUserObject();
    Assert.assertNotNull(object);
    if (!(object instanceof NodeDescriptor)) return null;
    final NodeElement element = (NodeElement) ((NodeDescriptor) object).getElement();
    if (toFind.equals(element)) return treeNode;

    for (int i = 0; i < treeNode.getChildCount(); i++) {
      final DefaultMutableTreeNode result =
          findNode((DefaultMutableTreeNode) treeNode.getChildAt(i), toFind, shouldBeSelected);
      if (result != null) {
        if (shouldBeSelected) {
          final TreePath path = new TreePath(result.getPath());
          Assert.assertTrue("Path should be selected: " + path, myTree.isPathSelected(path));
        }
        return result;
      }
    }

    return null;
  }
コード例 #4
0
    public void delete() {
      final NodeElement parent = (NodeElement) myStructure.getParentElement(myElement);
      Assert.assertNotNull(myElement.toString(), parent);

      myStructure.getNodeFor(parent).remove(myElement, true);
    }
コード例 #5
0
 @Override
 public String toString() {
   return myElement.toString();
 }