List of usage examples for javax.swing.tree TreePath getLastPathComponent
public Object getLastPathComponent()
From source file:org.kepler.gui.popups.OutlinePopupListener.java
/** * /* w w w . j a v a2 s. c om*/ * @param selPath * @param e */ private void handlePopupOutsideKar(TreePath selPath, MouseEvent e) { Object ob = selPath.getLastPathComponent(); if (isDebugging) log.debug(ob.getClass().getName()); if (ob instanceof NamedObj) { NamedObj no = (NamedObj) ob; String alternateLibraryPopupClassName = _getAlternateLibraryPopupClassName(no); if (alternateLibraryPopupClassName == null) { OutlineComponentPopup kcp = new OutlineComponentPopup(selPath, _aptree.getParentComponent()); kcp.initialize(); _aptree.add(kcp); _aptree.setSelectionPath(selPath); kcp.show(e.getComponent(), e.getX(), e.getY()); } else { try { Class<?> libraryPopupClass = Class.forName(alternateLibraryPopupClassName); Object object = libraryPopupClass.newInstance(); Method getPopupMethod = libraryPopupClass.getMethod("getPopup", JTree.class, MouseEvent.class, TreePath.class, Component.class); getPopupMethod.invoke(object, _aptree, e, selPath, _aptree.getParentComponent()); } catch (Exception w) { log.error("Error creating alternateGetLibraryPopup!", w); } } } }
From source file:org.kepler.gui.popups.OutlinePopupListener.java
/** * Description of the Method/* w ww . ja va 2s .c o m*/ * *@param e * Description of the Parameter */ private void maybeShowPopup(MouseEvent e) { if (isDebugging) log.debug("maybeShowPopup(" + e.toString() + ")"); if (e.isPopupTrigger() || _trigger) { _trigger = false; TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY()); if (isDebugging) log.debug(selPath.toString()); if ((selPath != null)) { // determine if this object is contained within a KAR // by checking all of the parent objects to see // if they are a KAREntityLibrary // do not check the object itself boolean inKAR = false; Object ob = null; for (int i = (selPath.getPathCount() - 2); i >= 0; i--) { ob = selPath.getPathComponent(i); if (ob instanceof KAREntityLibrary) { inKAR = true; break; } } ob = selPath.getLastPathComponent(); if (isDebugging) log.debug(ob.getClass().getName()); if (!inKAR) { handlePopupOutsideKar(selPath, e); } } } }
From source file:org.kuali.test.ui.components.sqlquerytree.SqlQueryTree.java
@Override public void mousePressed(MouseEvent e) { TreePath path = getPathForLocation(e.getX(), e.getY()); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node != null) { if (node.getUserObject() instanceof ColumnData) { ColumnData cd = (ColumnData) node.getUserObject(); if (cd.isSelected()) { columnsSelected--;//ww w. j a va 2 s . c o m } else { columnsSelected++; } cd.setSelected(!cd.isSelected()); getComponentAt(e.getPoint()).repaint(); e.consume(); } } } }
From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java
private DefaultMutableTreeNode getNodeAtPoint(Point pt) { DefaultMutableTreeNode retval = null; TreePath path = repositoryTree.getPathForLocation(pt.x, pt.y); if (path != null) { retval = (DefaultMutableTreeNode) path.getLastPathComponent(); }//from w w w .ja v a2 s . c om return retval; }
From source file:org.languagetool.gui.ConfigurationDialog.java
@NotNull private MouseAdapter getMouseAdapter() { return new MouseAdapter() { private void handlePopupEvent(MouseEvent e) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; }//ww w . j a v a2 s. c om DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); TreePath[] paths = tree.getSelectionPaths(); boolean isSelected = false; if (paths != null) { for (TreePath selectionPath : paths) { if (selectionPath.equals(path)) { isSelected = true; } } } if (!isSelected) { tree.setSelectionPath(path); } if (node.isLeaf()) { JPopupMenu popup = new JPopupMenu(); JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu")); aboutRuleMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent(); Rule rule = node.getRule(); Language lang = config.getLanguage(); if (lang == null) { lang = Languages.getLanguageForLocale(Locale.getDefault()); } Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"), rule.getDescription(), rule, rule.getUrl(), messages, lang.getShortCodeWithCountryAndVariant()); } }); popup.add(aboutRuleMenuItem); popup.show(tree, e.getX(), e.getY()); } } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { handlePopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { handlePopupEvent(e); } } }; }
From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java
/** * Gets the currently selected tree node. * * @return The currently selected tree node. *//* w ww . j av a 2 s . co m*/ protected DefaultMutableTreeNode getSelectedNode() { DefaultMutableTreeNode node = null; TreePath path = getSelectionPath(); if (path != null) { node = (DefaultMutableTreeNode) path.getLastPathComponent(); } return node; }
From source file:org.nuclos.client.explorer.ExplorerNode.java
static void createExpandendPathsForTree(TreePath path, JTree tree, List<String> lstExpandedPathsResult) { final ExplorerNode<?> explorernode = (ExplorerNode<?>) path.getLastPathComponent(); boolean isExpanded = tree.isExpanded(path); if (isExpanded) { lstExpandedPathsResult.add(explorernode.getIdentifierPath()); for (int i = 0; i < explorernode.getChildCount(); i++) { final ExplorerNode<?> explorernodeChild = (ExplorerNode<?>) explorernode.getChildAt(i); createExpandendPathsForTree(path.pathByAddingChild(explorernodeChild), tree, lstExpandedPathsResult); }/*from w ww . j a v a2s. co m*/ } }
From source file:org.nuclos.client.ui.collect.searcheditor.SearchEditorController.java
/** * event: a mouse event occured on a node in the <code>view</code> * @param selPath the path of the node where the mouse event occured. * @param ev//from ww w. j av a 2 s .c o m */ private void mouseEventOnNode(TreePath selPath, MouseEvent ev) { final SearchConditionTreeNode node = (SearchConditionTreeNode) selPath.getLastPathComponent(); final JTree tree = (JTree) ev.getComponent(); // select the node: tree.setSelectionPath(selPath); if (ev.isPopupTrigger()) { // show popup menu: final JPopupMenu popupMenu = this.getPopupMenu(node, tree); if (popupMenu != null) { popupMenu.show(ev.getComponent(), ev.getX(), ev.getY()); } } else if (ev.getID() == MouseEvent.MOUSE_CLICKED) { if (ev.getButton() == MouseEvent.BUTTON1) { if (ev.getClickCount() == 2) { if (this.clctfproviderfactory == null) { throw new IllegalStateException( "No CollectableFieldsProviderFactory was defined for the search editor."); } // perform the node's default action: final Action actDefault = node.getDefaultTreeNodeAction(tree, this.clcteRoot, this.clctfproviderfactory, this.additionalFields); if (actDefault != null) { actDefault.actionPerformed(null); } } } } }
From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java
/** * Processes node selection regardless of whether a new node was selected, or an * already selected node was clicked again. Normally called from event listener * methods./* w ww . j a v a 2 s . co m*/ */ public void processSelection(TreePath path) { if (path == null) { return; } DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Object[] data = getUserObjects(currentNode); if (data.length == 0) { // this should clear the right-side panel mediator.fireDomainDisplayEvent(new DomainDisplayEvent(this, null)); return; } Object obj = data[data.length - 1]; if (obj instanceof DataDomain) { mediator.fireDomainDisplayEvent(new DomainDisplayEvent(this, (DataDomain) obj)); } else if (obj instanceof DataMap) { if (data.length == 3) { mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(this, (DataMap) obj, (DataDomain) data[data.length - 3], (DataNode) data[data.length - 2])); } else if (data.length == 2) { mediator.fireDataMapDisplayEvent( new DataMapDisplayEvent(this, (DataMap) obj, (DataDomain) data[data.length - 2])); } } else if (obj instanceof DataNode) { if (data.length == 2) { mediator.fireDataNodeDisplayEvent( new DataNodeDisplayEvent(this, (DataDomain) data[data.length - 2], (DataNode) obj)); } } else if (obj instanceof Entity) { EntityDisplayEvent e = new EntityDisplayEvent(this, (Entity) obj); e.setUnselectAttributes(true); if (data.length == 4) { e.setDataMap((DataMap) data[data.length - 2]); e.setDomain((DataDomain) data[data.length - 4]); e.setDataNode((DataNode) data[data.length - 3]); } else if (data.length == 3) { e.setDataMap((DataMap) data[data.length - 2]); e.setDomain((DataDomain) data[data.length - 3]); } if (obj instanceof ObjEntity) { mediator.fireObjEntityDisplayEvent(e); } else if (obj instanceof DbEntity) { mediator.fireDbEntityDisplayEvent(e); } } else if (obj instanceof Procedure) { ProcedureDisplayEvent e = new ProcedureDisplayEvent(this, (Procedure) obj, (DataMap) data[data.length - 2], (DataDomain) data[data.length - 3]); mediator.fireProcedureDisplayEvent(e); } else if (obj instanceof Query) { QueryDisplayEvent e = new QueryDisplayEvent(this, (Query) obj, (DataMap) data[data.length - 2], (DataDomain) data[data.length - 3]); mediator.fireQueryDisplayEvent(e); } }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Indique si un noeud est slectionn ou pas * * @param noeudATester Le noeud tester/*from w w w .java2 s. c om*/ * @param selectedPath La liste des noeuds slectionns * @return True si le noeud est slectionn, false sinon */ private boolean isNoeudSelected(final DefaultMutableTreeNode noeudATester, final TreePath[] selectedPath) { boolean isSelected = false; // parcours des categories for (TreePath path : selectedPath) { try { // Cette ligne plante quand on slectionne une catgorie complte d'ou le try-catch ! final DefaultMutableTreeNode unNoeudSelectionner = (DefaultMutableTreeNode) path.getPath()[2]; isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString()); } catch (ArrayIndexOutOfBoundsException ex) { // Quand on choisit une catgorie complte, il faut parcourir les noeuds de cette manire : // recup de la categorie final DefaultMutableTreeNode categ = (DefaultMutableTreeNode) path.getLastPathComponent(); // parcours des noeuds dans la catgorie for (int j = 0; j < categ.getChildCount(); j++) { final TreeNode unNoeudSelectionner = categ.getChildAt(j); isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString()); if (isSelected) { break; } } } // on sort de la boucle ds qu'on a la rponse if (isSelected) { break; } } return isSelected; }