예제 #1
0
  // {{{ removeSelectedNode() method
  private void removeSelectedNode() {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    MutableTreeNode value = (MutableTreeNode) path.getLastPathComponent();

    if (path.getPathCount() > 1) {
      // Adjust selection so that repeating some removals
      // behave naturally.
      TreePath parentPath = path.getParentPath();
      MutableTreeNode parent = (MutableTreeNode) parentPath.getLastPathComponent();
      int removingIndex = parent.getIndex(value);
      int nextIndex = removingIndex + 1;
      if (nextIndex < parent.getChildCount()) {
        TreeNode next = parent.getChildAt(nextIndex);
        resultTree.setSelectionPath(parentPath.pathByAddingChild(next));
      } else {
        resultTree.setSelectionPath(parentPath);
      }

      resultTreeModel.removeNodeFromParent(value);
    }

    HyperSearchOperationNode.removeNodeFromCache(value);
    if (resultTreeRoot.getChildCount() == 0) {
      hideDockable();
    }
  } // }}}
예제 #2
0
파일: TreeView.java 프로젝트: jexp/idea2
  private void addJavacMessageImpl(AntMessage message) {
    MutableTreeNode parentNode = (MutableTreeNode) myParentPath.getLastPathComponent();
    MessageNode messageNode = new MessageNode(message, myProject, false);

    myTreeModel.insertNodeInto(messageNode, parentNode, parentNode.getChildCount());
    myMessageItems.add(messageNode);

    handleExpansion();
  }
예제 #3
0
파일: TreeView.java 프로젝트: jexp/idea2
  public Object addMessage(AntMessage message) {
    MessageNode messageNode = createMessageNode(message);

    MutableTreeNode parentNode = (MutableTreeNode) myParentPath.getLastPathComponent();
    myTreeModel.insertNodeInto(messageNode, parentNode, parentNode.getChildCount());
    myMessageItems.add(messageNode);

    handleExpansion();
    return messageNode;
  }
  /* Simple tree node factory method - set's parent and user object.
   */
  private DefaultMutableTreeNode makeNode(Object userObject, MutableTreeNode parent) {

    DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject);

    if (parent != null) {
      treeModel.insertNodeInto(node, parent, parent.getChildCount());
    }

    return node;
  }
예제 #5
0
 public void insertNode(GroupInfo[] groupInfos, MutableTreeNode parent) {
   boolean hasNode = false;
   for (GroupInfo info : groupInfos) {
     int childCount = parent.getChildCount();
     for (int i = 0; i < childCount; i++) {
       if (info.equals(parent.getChildAt(i).toString())) {
         hasNode = true;
         break;
       }
     }
     if (!hasNode || childCount == 0) {
       insertNodeInto(new VarNode(info), parent, childCount);
     }
   }
 }
  private ToolsGroup[] getGroupList() {
    ArrayList<ToolsGroup> result = new ArrayList<ToolsGroup>();
    MutableTreeNode root = (MutableTreeNode) myTree.getModel().getRoot();
    for (int i = 0; i < root.getChildCount(); i++) {
      final CheckedTreeNode node = (CheckedTreeNode) root.getChildAt(i);
      for (int j = 0; j < node.getChildCount(); j++) {
        final CheckedTreeNode toolNode = (CheckedTreeNode) node.getChildAt(j);
        ((Tool) toolNode.getUserObject()).setEnabled(toolNode.isChecked());
      }

      result.add((ToolsGroup) node.getUserObject());
    }

    return result.toArray(new ToolsGroup[result.size()]);
  }
예제 #7
0
파일: TreeView.java 프로젝트: jexp/idea2
  public void addException(AntMessage exception, boolean showFullTrace) {
    MessageNode exceptionRootNode = null;

    StringTokenizer tokenizer = new StringTokenizer(exception.getText(), "\r\n");
    while (tokenizer.hasMoreElements()) {
      String line = (String) tokenizer.nextElement();
      if (exceptionRootNode == null) {
        AntMessage newMessage =
            new AntMessage(
                exception.getType(),
                exception.getPriority(),
                line,
                exception.getFile(),
                exception.getLine(),
                exception.getColumn());
        exceptionRootNode = new MessageNode(newMessage, myProject, true);
        myMessageItems.add(exceptionRootNode);
      } else if (showFullTrace) {
        if (StringUtil.startsWithChar(line, '\t')) {
          line = line.substring(1);
        }

        HyperlinkUtil.PlaceInfo info = HyperlinkUtil.parseStackLine(myProject, '\t' + line);
        VirtualFile file = info != null ? info.getFile() : null;
        int lineNumber = info != null ? info.getLine() : 0;
        int column = info != null ? info.getColumn() : 1;
        AntMessage newMessage =
            new AntMessage(
                exception.getType(), exception.getPriority(), line, file, lineNumber, column);
        MessageNode child = new MessageNode(newMessage, myProject, false);
        exceptionRootNode.add(child);
        myMessageItems.add(child);
      }
    }
    if (exceptionRootNode == null) return;

    MutableTreeNode parentNode = (MutableTreeNode) myParentPath.getLastPathComponent();
    myTreeModel.insertNodeInto(exceptionRootNode, parentNode, parentNode.getChildCount());

    handleExpansion();
  }
예제 #8
0
    public void drop(final DropTargetDropEvent e) {
      _timerHover.stop(); // Prevent hover timer from doing an unwanted expandPath or collapsePath

      if (!isDropAcceptable(e)) {
        e.rejectDrop();
        return;
      }

      e.acceptDrop(e.getDropAction());

      final Transferable transferable = e.getTransferable();

      final DataFlavor[] flavors = transferable.getTransferDataFlavors();

      for (int i = 0; i < flavors.length; i++) {
        final DataFlavor flavor = flavors[i];
        if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) {
          try {
            final Point pt = e.getLocation();
            final TreePath pathTarget = getClosestPathForLocation(pt.x, pt.y);
            final TreePath pathSource = (TreePath) transferable.getTransferData(flavor);

            if ((pathTarget == null) || (pathSource == null)) {
              e.dropComplete(false);
              return;
            }

            final MutableTreeNode sourceNode = (MutableTreeNode) pathSource.getLastPathComponent();
            final MutableTreeNode oldParent = (MutableTreeNode) sourceNode.getParent();

            final MutableTreeNode targetNode = (MutableTreeNode) pathTarget.getLastPathComponent();
            final MutableTreeNode newParent = (MutableTreeNode) targetNode.getParent();

            if (!sourceNode.isLeaf() && (targetNode.getParent() == sourceNode)) {
              // trying to drag a folder into its own childs
              e.dropComplete(false);
              return;
            }

            final DefaultTreeModel model = (DefaultTreeModel) getModel();
            final TreePath pathNewChild = null;

            if (targetNode.isLeaf() || JDragTree.this.isCollapsed(pathTarget)) {
              // collapsed tree node or leaf
              // dropped on a leaf, insert into leaf's parent AFTER leaf
              int idx = newParent.getIndex(targetNode);
              if (idx < 0) {
                JDragTree.logger.warning("child not found in parent!!!");
                e.dropComplete(false);
                return;
              } else {
                idx++; // insert AFTER targetNode

                // remove node from oldParent ...
                final Object[] removedChilds = {sourceNode};
                final int[] childIndices = {oldParent.getIndex(sourceNode)};
                sourceNode.removeFromParent();
                model.nodesWereRemoved(oldParent, childIndices, removedChilds);

                // ... and insert into newParent
                if (idx >= newParent.getChildCount()) {
                  // newParent.add( sourceNode );
                  newParent.insert(sourceNode, newParent.getChildCount());
                  final int insertedIndex[] = {newParent.getChildCount() - 1};
                  model.nodesWereInserted(newParent, insertedIndex);
                } else {
                  newParent.insert(sourceNode, idx);
                  final int insertedIndex[] = {idx};
                  model.nodesWereInserted(newParent, insertedIndex);
                }
              }
            } else {
              // expanded node, insert UNDER the node (before first child)
              // remove node from oldParent ...
              final Object[] removedChilds = {sourceNode};
              final int[] childIndices = {oldParent.getIndex(sourceNode)};
              sourceNode.removeFromParent();
              model.nodesWereRemoved(oldParent, childIndices, removedChilds);
              // ... and add to newParent
              targetNode.insert(sourceNode, 0);
              final int insertedIndex[] = {0};
              model.nodesWereInserted(targetNode, insertedIndex);
            }

            if (pathNewChild != null)
              setSelectionPath(pathNewChild); // Mark this as the selected path in the tree
            break; // No need to check remaining flavors
          } catch (final UnsupportedFlavorException ufe) {
            JDragTree.logger.log(
                Level.SEVERE, "Exception thrown in drop(DropTargetDropEvent e)", ufe);
            e.dropComplete(false);
            return;
          } catch (final IOException ioe) {
            JDragTree.logger.log(
                Level.SEVERE, "Exception thrown in drop(DropTargetDropEvent e)", ioe);
            e.dropComplete(false);
            return;
          }
        }
      }
      e.dropComplete(true);
    }
예제 #9
0
파일: TreeUtil.java 프로젝트: jexp/idea2
 private static void addChildrenTo(final MutableTreeNode node, final List<TreeNode> children) {
   for (final Object aChildren : children) {
     final MutableTreeNode child = (MutableTreeNode) aChildren;
     node.insert(child, node.getChildCount());
   }
 }