Beispiel #1
0
  private void goToSelectedNode(int mode) {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object value = node.getUserObject();

    // do nothing if clicked "foo (showing n occurrences in m files)"
    if (node.getParent() != resultTreeRoot && value instanceof HyperSearchNode) {
      HyperSearchNode n = (HyperSearchNode) value;
      Buffer buffer = n.getBuffer(view);
      if (buffer == null) return;

      EditPane pane;

      switch (mode) {
        case M_OPEN:
          pane = view.goToBuffer(buffer);
          break;
        case M_OPEN_NEW_VIEW:
          pane = jEdit.newView(view, buffer, false).getEditPane();
          break;
        case M_OPEN_NEW_PLAIN_VIEW:
          pane = jEdit.newView(view, buffer, true).getEditPane();
          break;
        case M_OPEN_NEW_SPLIT:
          pane = view.splitHorizontally();
          break;
        default:
          throw new IllegalArgumentException("Bad mode: " + mode);
      }

      n.goTo(pane);
    }
  } // }}}
Beispiel #2
0
 public static List<TreePath> collectExpandedPaths(final JTree tree, TreePath path) {
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   if (!tree.isExpanded(path)) return result;
   final Object lastPathComponent = path.getLastPathComponent();
   final TreeModel model = tree.getModel();
   if (model.isLeaf(lastPathComponent)) {
     result.add(path);
   } else {
     boolean pathWasAdded = false;
     for (int i = model.getChildCount(lastPathComponent) - 1; i >= 0; i--) {
       final TreePath childPath = path.pathByAddingChild(model.getChild(lastPathComponent, i));
       if (model.isLeaf(lastPathComponent)) {
         if (!pathWasAdded) {
           result.add(path);
           pathWasAdded = true;
         }
       } else if (tree.isExpanded(childPath)) {
         result.addAll(collectExpandedPaths(tree, childPath));
       } else {
         if (!pathWasAdded) {
           result.add(path);
           pathWasAdded = true;
         }
       }
     }
   }
   return result;
 }
Beispiel #3
0
  @Override
  public void valueChanged(TreeSelectionEvent e) {
    if (e.getSource() == colors && !locked) {
      TreeSelectionModel tsm = colors.getSelectionModel();
      TreePath tp[] = tsm.getSelectionPaths();
      if (tp == null) return;
      Vector<ClassedItem> tmp = new Vector<ClassedItem>();
      for (TreePath element : tp) {
        try {
          Object[] path = element.getPath();
          ClassedItem ci = new ClassedItem(path[1].toString(), path[2].toString());
          tmp.add(ci);
        } catch (Exception exp) {
          // User did not select a leafnode
        }
      }

      if (sceneElement instanceof NenyaImageSceneElement) {
        ((NenyaImageSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0]));
      }
      if (sceneElement instanceof NenyaTileSceneElement) {
        ((NenyaTileSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0]));
      }
      if (sceneElement instanceof NenyaComponentSceneElement) {
        ((NenyaComponentSceneElement) sceneElement)
            .getComponents()[itemList.getSelectedIndex()].setColorList(
                tmp.toArray(new ClassedItem[0]));
      }

      submitElement(sceneElement, null);
    } else {
      super.valueChanged(e);
    }
  }
Beispiel #4
0
 public void run() {
   if (getTree().isExpanded(t)) {
     expandedNodes.add(t.getLastPathComponent());
   } else {
     expandedNodes.remove(t.getLastPathComponent());
   }
 }
 @Override
 public void keyPressed(KeyEvent e) {
   TreePath path = myTree.getLeadSelectionPath();
   if (path == null) return;
   final Object lastComponent = path.getLastPathComponent();
   if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (lastComponent instanceof ParentNode) return;
     doOKAction();
     e.consume();
   } else if (e.getKeyCode() == KeyEvent.VK_INSERT) {
     if (lastComponent instanceof ElementNode) {
       final DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;
       if (!mySelectedNodes.contains(node)) {
         if (node.getNextNode() != null) {
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
         }
       } else {
         if (node.getNextNode() != null) {
           myTree.removeSelectionPath(new TreePath(node.getPath()));
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
           myTree.repaint();
         }
       }
       e.consume();
     }
   }
 }
Beispiel #6
0
    @Override
    public void actionPerformed(ActionEvent evt) {
      JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) evt.getSource();
      boolean curState = menuItem.isSelected();

      TreePath path = resultTree.getSelectionPath();
      DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();

      HyperSearchOperationNode operNodeObj = (HyperSearchOperationNode) operNode.getUserObject();
      if (curState) operNodeObj.cacheResultNodes(operNode);
      operNode.removeAllChildren();
      if (curState) {
        Exception excp = null;
        try {
          operNodeObj.insertTreeNodes(resultTree, operNode);
        } catch (Exception ex) {
          operNodeObj.restoreFlatNodes(resultTree, operNode);
          menuItem.setSelected(false);
          excp = ex;
        } finally {
          ((DefaultTreeModel) resultTree.getModel()).nodeStructureChanged(operNode);
          expandAllNodes(operNode);
          resultTree.scrollPathToVisible(new TreePath(operNode.getPath()));
        }
        if (excp != null) throw new RuntimeException(excp);
      } else operNodeObj.restoreFlatNodes(resultTree, operNode);

      operNodeObj.setTreeViewDisplayed(menuItem.isSelected());
    }
  private void updateSelectionFromTree() {
    TreePath[] treePaths = myTree.getSelectionPaths();
    if (treePaths != null) {
      List<NamedConfigurable> selectedConfigurables = new ArrayList<NamedConfigurable>();
      for (TreePath path : treePaths) {
        Object lastPathComponent = path.getLastPathComponent();
        if (lastPathComponent instanceof MyNode) {
          selectedConfigurables.add(((MyNode) lastPathComponent).getConfigurable());
        }
      }
      if (selectedConfigurables.size() > 1 && updateMultiSelection(selectedConfigurables)) {
        return;
      }
    }

    final TreePath path = myTree.getSelectionPath();
    if (path != null) {
      final Object lastPathComp = path.getLastPathComponent();
      if (!(lastPathComp instanceof MyNode)) return;
      final MyNode node = (MyNode) lastPathComp;
      setSelectedNode(node);
    } else {
      setSelectedNode(null);
    }
  }
  @NotNull
  public Change[] getSelectedChanges() {
    Set<Change> changes = new LinkedHashSet<Change>();

    final TreePath[] paths = getSelectionPaths();
    if (paths == null) {
      return new Change[0];
    }

    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent();
      changes.addAll(node.getAllChangesUnder());
    }

    if (changes.isEmpty()) {
      final List<VirtualFile> selectedModifiedWithoutEditing = getSelectedModifiedWithoutEditing();
      if (selectedModifiedWithoutEditing != null && !selectedModifiedWithoutEditing.isEmpty()) {
        for (VirtualFile file : selectedModifiedWithoutEditing) {
          AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file);
          if (vcs == null) continue;
          final VcsCurrentRevisionProxy before =
              VcsCurrentRevisionProxy.create(file, myProject, vcs.getKeyInstanceMethod());
          if (before != null) {
            ContentRevision afterRevision = new CurrentContentRevision(new FilePathImpl(file));
            changes.add(new Change(before, afterRevision, FileStatus.HIJACKED));
          }
        }
      }
    }

    return changes.toArray(new Change[changes.size()]);
  }
 private static boolean isMoveSupported(JTree tree, int dir) {
   final TreePath[] selectionPaths = tree.getSelectionPaths();
   if (selectionPaths != null) {
     DefaultMutableTreeNode parent = null;
     for (TreePath treePath : selectionPaths)
       if (treePath.getLastPathComponent() != null) {
         final DefaultMutableTreeNode node =
             (DefaultMutableTreeNode) treePath.getLastPathComponent();
         if (parent == null) {
           parent = (DefaultMutableTreeNode) node.getParent();
         }
         if (parent != node.getParent()) {
           return false;
         }
         if (dir > 0) {
           if (parent.getIndex(node) == parent.getChildCount() - 1) {
             return false;
           }
         } else {
           if (parent.getIndex(node) == 0) {
             return false;
           }
         }
       }
     return true;
   }
   return false;
 }
 @Override
 public void calcData(DataKey key, DataSink sink) {
   if (key == VcsDataKeys.CHANGES) {
     sink.put(VcsDataKeys.CHANGES, getSelectedChanges());
   } else if (key == VcsDataKeys.CHANGE_LEAD_SELECTION) {
     sink.put(VcsDataKeys.CHANGE_LEAD_SELECTION, getLeadSelection());
   } else if (key == VcsDataKeys.CHANGE_LISTS) {
     sink.put(VcsDataKeys.CHANGE_LISTS, getSelectedChangeLists());
   } else if (key == PlatformDataKeys.VIRTUAL_FILE_ARRAY) {
     sink.put(PlatformDataKeys.VIRTUAL_FILE_ARRAY, getSelectedFiles());
   } else if (key == PlatformDataKeys.NAVIGATABLE) {
     final VirtualFile[] files = getSelectedFiles();
     if (files.length == 1 && !files[0].isDirectory()) {
       sink.put(PlatformDataKeys.NAVIGATABLE, new OpenFileDescriptor(myProject, files[0], 0));
     }
   } else if (key == PlatformDataKeys.NAVIGATABLE_ARRAY) {
     sink.put(
         PlatformDataKeys.NAVIGATABLE_ARRAY,
         ChangesUtil.getNavigatableArray(myProject, getSelectedFiles()));
   } else if (key == PlatformDataKeys.DELETE_ELEMENT_PROVIDER) {
     final TreePath[] paths = getSelectionPaths();
     if (paths != null) {
       for (TreePath path : paths) {
         ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
         if (!(node.getUserObject() instanceof ChangeList)) {
           sink.put(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, new VirtualFileDeleteProvider());
           break;
         }
       }
     }
   } else if (key == PlatformDataKeys.COPY_PROVIDER) {
     sink.put(PlatformDataKeys.COPY_PROVIDER, myCopyProvider);
   } else if (key == UNVERSIONED_FILES_DATA_KEY) {
     sink.put(UNVERSIONED_FILES_DATA_KEY, getSelectedUnversionedFiles());
   } else if (key == VcsDataKeys.MODIFIED_WITHOUT_EDITING_DATA_KEY) {
     sink.put(VcsDataKeys.MODIFIED_WITHOUT_EDITING_DATA_KEY, getSelectedModifiedWithoutEditing());
   } else if (key == LOCALLY_DELETED_CHANGES) {
     sink.put(LOCALLY_DELETED_CHANGES, getSelectedLocallyDeletedChanges());
   } else if (key == MISSING_FILES_DATA_KEY) {
     sink.put(MISSING_FILES_DATA_KEY, getSelectedMissingFiles());
   } else if (VcsDataKeys.HAVE_LOCALLY_DELETED == key) {
     sink.put(VcsDataKeys.HAVE_LOCALLY_DELETED, haveLocallyDeleted());
   } else if (VcsDataKeys.HAVE_MODIFIED_WITHOUT_EDITING == key) {
     sink.put(VcsDataKeys.HAVE_MODIFIED_WITHOUT_EDITING, haveLocallyModified());
   } else if (VcsDataKeys.HAVE_SELECTED_CHANGES == key) {
     sink.put(VcsDataKeys.HAVE_SELECTED_CHANGES, haveSelectedChanges());
   } else if (key == HELP_ID_DATA_KEY) {
     sink.put(HELP_ID_DATA_KEY, ourHelpId);
   } else if (key == VcsDataKeys.CHANGES_IN_LIST_KEY) {
     final TreePath selectionPath = getSelectionPath();
     if (selectionPath != null && selectionPath.getPathCount() > 1) {
       ChangesBrowserNode<?> firstNode = (ChangesBrowserNode) selectionPath.getPathComponent(1);
       if (firstNode instanceof ChangesBrowserChangeListNode) {
         final List<Change> list = firstNode.getAllChangesUnder();
         sink.put(VcsDataKeys.CHANGES_IN_LIST_KEY, list);
       }
     }
   }
 }
Beispiel #11
0
 private static IndexTreePathState removeLastPathComponent(
     final DefaultTreeModel model, final TreePath pathToBeRemoved) {
   final IndexTreePathState selectionState = new IndexTreePathState(pathToBeRemoved);
   if (((MutableTreeNode) pathToBeRemoved.getLastPathComponent()).getParent() == null)
     return selectionState;
   model.removeNodeFromParent((MutableTreeNode) pathToBeRemoved.getLastPathComponent());
   return selectionState;
 }
Beispiel #12
0
 public static ActionCallback selectFirstNode(final JTree tree) {
   final TreeModel model = tree.getModel();
   final Object root = model.getRoot();
   TreePath selectionPath = new TreePath(root);
   if (!tree.isRootVisible() && model.getChildCount(root) > 0)
     selectionPath = selectionPath.pathByAddingChild(model.getChild(root, 0));
   return selectPath(tree, selectionPath);
 }
  @Nullable
  private Node getSelectedNode() {
    TreePath leadSelectionPath = myTree.getLeadSelectionPath();
    if (leadSelectionPath == null) return null;

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath.getLastPathComponent();
    return node instanceof Node ? (Node) node : null;
  }
Beispiel #14
0
 protected Transferable createTransferable(JComponent c) {
   JTree tree = (JTree) c;
   TreePath[] paths = tree.getSelectionPaths();
   if (paths == null || paths.length != 1) return null;
   TreePath path = tree.getSelectionPath();
   GroovyTreeNode groovyTreeNode = (GroovyTreeNode) path.getLastPathComponent();
   return new StringTransferable((String) (groovyTreeNode.node.getNodeValue()));
 }
Beispiel #15
0
 private static void expand(JTree tree, TreePath path, int levels) {
   if (levels == 0) return;
   tree.expandPath(path);
   TreeNode node = (TreeNode) path.getLastPathComponent();
   Enumeration children = node.children();
   while (children.hasMoreElements()) {
     expand(tree, path.pathByAddingChild(children.nextElement()), levels - 1);
   }
 }
Beispiel #16
0
 private static boolean areComponentsEqual(final TreePath[] paths, final int componentIndex) {
   if (paths[0].getPathCount() <= componentIndex) return false;
   final Object pathComponent = paths[0].getPathComponent(componentIndex);
   for (final TreePath treePath : paths) {
     if (treePath.getPathCount() <= componentIndex) return false;
     if (!pathComponent.equals(treePath.getPathComponent(componentIndex))) return false;
   }
   return true;
 }
Beispiel #17
0
 @Override
 public void actionPerformed(ActionEvent evt) {
   TreePath path = resultTree.getSelectionPath();
   DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();
   for (Enumeration e = operNode.children(); e.hasMoreElements(); ) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
     resultTree.collapsePath(new TreePath(node.getPath()));
   }
   resultTree.scrollPathToVisible(new TreePath(operNode.getPath()));
 }
Beispiel #18
0
 public void actionPerformed(ActionEvent event) {
   JTree tree = getTree();
   TreePath path = tree.getSelectionPath();
   if (path == null) {
     sheet.getLogger().warning("Warning: User must select a node to attach a new config to");
     // XXX add a message telling users to select a node
   } else {
     createAttrConfigForNode((Node) path.getLastPathComponent());
   }
 }
Beispiel #19
0
 public static TreePath findCommonPath(final TreePath[] treePaths) {
   LOG.assertTrue(areComponentsEqual(treePaths, 0));
   TreePath result = new TreePath(treePaths[0].getPathComponent(0));
   int pathIndex = 1;
   while (areComponentsEqual(treePaths, pathIndex)) {
     result = result.pathByAddingChild(treePaths[0].getPathComponent(pathIndex));
     pathIndex++;
   }
   return result;
 }
Beispiel #20
0
 @Override
 public void actionPerformed(ActionEvent evt) {
   TreePath path = resultTree.getSelectionPath();
   DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();
   ToStringNodes toStringNodes = new ToStringNodes();
   traverseNodes(operNode, toStringNodes);
   StringSelection selection = new StringSelection(toStringNodes.nodesString.toString());
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   clipboard.setContents(selection, null);
 }
 @Nullable
 public NamedConfigurable getSelectedConfigurable() {
   final TreePath selectionPath = myTree.getSelectionPath();
   if (selectionPath != null) {
     MyNode node = (MyNode) selectionPath.getLastPathComponent();
     final NamedConfigurable configurable = node.getConfigurable();
     LOG.assertTrue(configurable != null, "already disposed");
     return configurable;
   }
   return null;
 }
Beispiel #22
0
 public static void moveSelectedRow(final JTree tree, final int direction) {
   final TreePath selectionPath = tree.getSelectionPath();
   final DefaultMutableTreeNode treeNode =
       (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
   final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) treeNode.getParent();
   final int idx = parent.getIndex(treeNode);
   parent.remove(treeNode);
   parent.insert(treeNode, idx + direction);
   ((DefaultTreeModel) tree.getModel()).reload(parent);
   selectNode(tree, treeNode);
 }
Beispiel #23
0
 public void editSelected() {
   TreePath selected = tree.getSelectionPath();
   if (selected != null) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) selected.getLastPathComponent();
     Object obj = node.getUserObject();
     if (obj instanceof CavityDBObject) {
       CavityDBObject dbObj = (CavityDBObject) obj;
       new ObjectEditingFrame(new ObjectEditingPanel(dbObj));
     }
   }
 }
Beispiel #24
0
  public static void dropSelectionButUnderPoint(JTree tree, Point treePoint) {
    final TreePath toRetain = tree.getPathForLocation(treePoint.x, treePoint.y);
    if (toRetain == null) return;

    TreePath[] selection = tree.getSelectionModel().getSelectionPaths();
    selection = selection == null ? new TreePath[0] : selection;
    for (TreePath each : selection) {
      if (toRetain.equals(each)) continue;
      tree.getSelectionModel().removeSelectionPath(each);
    }
  }
Beispiel #25
0
 public static void unselect(JTree tree, final DefaultMutableTreeNode node) {
   final TreePath rootPath = new TreePath(node.getPath());
   final TreePath[] selectionPaths = tree.getSelectionPaths();
   if (selectionPaths != null) {
     for (TreePath selectionPath : selectionPaths) {
       if (selectionPath.getPathCount() > rootPath.getPathCount()
           && rootPath.isDescendant(selectionPath)) {
         tree.removeSelectionPath(selectionPath);
       }
     }
   }
 }
Beispiel #26
0
    @Override
    public void actionPerformed(ActionEvent evt) {
      TreePath path = resultTree.getSelectionPath();
      DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();
      HyperSearchFolderNode nodeObj = (HyperSearchFolderNode) operNode.getUserObject();

      String glob = "*";
      SearchFileSet dirList = SearchAndReplace.getSearchFileSet();
      if (dirList instanceof DirectoryListSet) glob = ((DirectoryListSet) dirList).getFileFilter();
      SearchAndReplace.setSearchFileSet(
          new DirectoryListSet(nodeObj.getNodeFile().getAbsolutePath(), glob, true));
      SearchDialog.showSearchDialog(view, null, SearchDialog.DIRECTORY);
    }
Beispiel #27
0
 @Override
 public void exportToClipboard(JComponent comp, Clipboard clip, int action)
     throws IllegalStateException {
   TreePath[] paths = resultTree.getSelectionPaths();
   ToStringNodes toStringNodes = new ToStringNodes();
   for (TreePath path : paths) {
     DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();
     toStringNodes.processNode(operNode);
   }
   StringSelection selection = new StringSelection(toStringNodes.nodesString.toString());
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   clipboard.setContents(selection, null);
 }
 private Pair<ElementNode, List<ElementNode>> storeSelection() {
   List<ElementNode> selectedNodes = new ArrayList<ElementNode>();
   TreePath[] paths = myTree.getSelectionPaths();
   if (paths != null) {
     for (TreePath path : paths) {
       selectedNodes.add((ElementNode) path.getLastPathComponent());
     }
   }
   TreePath leadSelectionPath = myTree.getLeadSelectionPath();
   return Pair.create(
       leadSelectionPath != null ? (ElementNode) leadSelectionPath.getLastPathComponent() : null,
       selectedNodes);
 }
 protected boolean haveSelectedFileType(final Object tag) {
   final TreePath[] paths = getSelectionPaths();
   if (paths != null) {
     for (TreePath path : paths) {
       if (path.getPathCount() > 1) {
         ChangesBrowserNode firstNode = (ChangesBrowserNode) path.getPathComponent(1);
         if ((tag == null || firstNode.getUserObject() == tag) && path.getPathCount() > 2) {
           return true;
         }
       }
     }
   }
   return false;
 }
 public void restore() {
   final UsageNode node = myUsageNodes.get(myUsage);
   if (node == NULL_NODE || node == null) {
     return;
   }
   final DefaultMutableTreeNode parentGroupingNode = (DefaultMutableTreeNode) node.getParent();
   if (parentGroupingNode != null) {
     final TreePath treePath = new TreePath(parentGroupingNode.getPath());
     myTree.expandPath(treePath);
     if (mySelected) {
       myTree.addSelectionPath(treePath.pathByAddingChild(node));
     }
   }
 }