List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** * Filters the list of displayed items.//from w w w . java 2 s .co m * * @param insert Pass <code>true</code> when inserting new character * <code>false</code> when removing. */ private void filter(boolean insert) { String txt = filterArea.getText(); if (DEFAULT_FILTER_TEXT.equals(txt)) { return; } filterArea.setForeground(originalColor); List<TreeImageDisplay> ref; Iterator<TreeImageDisplay> i; TreeImageDisplay node, child; Object ho; String value; if (insert) { ref = availableItems; } else { ref = new ArrayList<TreeImageDisplay>(); for (TreeImageDisplay item : originalItems) { if (!isSelected(item)) { ref.add(item); } } for (TreeImageDisplay item : originalSelectedItems) { if (!isSelected(item) && !isChild(item)) { ref.add(item); } } } i = ref.iterator(); txt = txt.toLowerCase(); List<TreeImageDisplay> toKeep = new ArrayList<TreeImageDisplay>(); while (i.hasNext()) { node = i.next(); ho = node.getUserObject(); value = null; if (ho instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) ho; if (!TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace())) { value = tag.getTagValue(); } else { List l = node.getChildrenDisplay(); Iterator j = l.iterator(); while (j.hasNext()) { child = (TreeImageDisplay) j.next(); if (!isSelected(child)) { ho = child.getUserObject(); if (ho instanceof TagAnnotationData) { tag = (TagAnnotationData) ho; value = tag.getTagValue(); value = value.toLowerCase(); if (filterItem(value, txt, (DataObject) ho)) { toKeep.add(node); break; } } } } value = null; } } else if (ho instanceof FileAnnotationData) { value = ((FileAnnotationData) ho).getFileName(); } else if (ho instanceof DataObject) { value = node.getNodeName(); } if (value != null) { value = value.toLowerCase(); if (filterItem(value, txt, (DataObject) ho)) { toKeep.add(node); } } } availableItems.clear(); availableItems.addAll(toKeep); availableItems = sorter.sort(availableItems); populateTreeItems(availableItemsListbox, availableItems); //Select the first not //Get the first node. if (CollectionUtils.isNotEmpty(availableItems) && StringUtils.isNotBlank(txt)) { node = availableItems.get(0); TreePath path = null; if (node.hasChildrenDisplay() && node.getChildCount() > 0) { child = (TreeImageDisplay) node.getFirstChild(); path = new TreePath(child.getPath()); } else { path = new TreePath(node.getPath()); } if (path != null) { availableItemsListbox.setSelectionPath(path); availableItemsListbox.scrollPathToVisible(path); availableItemsListbox.repaint(); } } }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** * Updates the specified tree./*from w w w . j a va 2 s . co m*/ * * @param tree The tree to update. * @param nodes The collection of nodes to handle. */ private void populateTreeItems(JTree tree, List<TreeImageDisplay> nodes) { DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); TreeImageDisplay parent = (TreeImageDisplay) dtm.getRoot(); parent.removeAllChildrenDisplay(); parent.removeAllChildren(); Iterator<TreeImageDisplay> i = nodes.iterator(); TreeImageDisplay node, child; Iterator<TreeImageDisplay> j; Set<TreeImageDisplay> toExpand = new HashSet<TreeImageDisplay>(); while (i.hasNext()) { node = i.next(); node.setDisplayItems(false); Object ho = node.getUserObject(); if (ho instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) ho; if (!TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace()) || node.hasChildrenDisplay()) { dtm.insertNodeInto(node, parent, parent.getChildCount()); } } else { dtm.insertNodeInto(node, parent, parent.getChildCount()); } if (node.hasChildrenDisplay()) { node.removeAllChildren(); tree.expandPath(new TreePath(node.getPath())); Collection<TreeImageDisplay> l = node.getChildrenDisplay(); l = sorter.sort(l); j = l.iterator(); while (j.hasNext()) { child = j.next(); child.setDisplayItems(false); if (!isSelected(child) && !isFiltered(child)) { dtm.insertNodeInto(child, node, node.getChildCount()); toExpand.add(node); tree.expandPath(new TreePath(node.getPath())); } } } } dtm.reload(); i = toExpand.iterator(); while (i.hasNext()) { tree.expandPath(new TreePath(i.next().getPath())); } }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** * Adds the passed objects. Returns <code>true</code> to clear the text * and resets the default, <code>false</code> otherwise. * /* ww w. j av a 2 s .c o m*/ * @param toAdd The objects to add. * @return See above. */ boolean addObjects(List<DataObject> toAdd) { if (CollectionUtils.isEmpty(toAdd)) return true; Iterator<DataObject> i = toAdd.iterator(); DataObject data; TreeImageDisplay node = null; String desc = ""; String s = "", value; while (i.hasNext()) { data = i.next(); node = doesObjectExist(data, true); if (node != null) { if (data instanceof TagAnnotationData) { desc = ((TagAnnotationData) data).getTagDescription(); } break; } } //now check if the node is already selected. if (node != null) { //check the description for the txt data = (DataObject) node.getUserObject(); if (data instanceof TagAnnotationData) { value = ((TagAnnotationData) data).getTagDescription(); if (!desc.equals(value)) { s = " a different"; } } NotificationDialog msg = new NotificationDialog(view, "Add new tag", String.format( "A tag with the same name and%s description " + "already exists\nand is selected.", s), null); UIUtilities.centerAndShow(msg); return false; } if (node == null) { //warning i = toAdd.iterator(); while (i.hasNext()) { data = i.next(); node = doesObjectExist(data, false); if (node != null) { if (data instanceof TagAnnotationData) { desc = ((TagAnnotationData) data).getTagDescription(); } break; } } if (node != null) { //check the description for the txt data = (DataObject) node.getUserObject(); if (data instanceof TagAnnotationData) { value = ((TagAnnotationData) data).getTagDescription(); if (!desc.equals(value)) { s = " a different"; } } MessageBox msg = new MessageBox(view, "Add new tag", String.format("A tag with the same name and" + "%s description already exists.\n" + "Would you like to select the existing tag?", s)); int option = msg.centerMsgBox(); if (option == MessageBox.YES_OPTION) { availableItemsListbox.setSelectionPath(new TreePath(node.getPath())); addItem(); availableItemsListbox.requestFocus(); return true; } return false; } } //We create a new tag. i = toAdd.iterator(); DataObject ho; while (i.hasNext()) { ho = i.next(); node = TreeViewerTranslator.transformDataObject(ho); if (ho instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) ho; Set<DataObject> set = tag.getDataObjects(); List<TagAnnotationData> p = new ArrayList<TagAnnotationData>(); if (CollectionUtils.isNotEmpty(set)) { Iterator<DataObject> j = set.iterator(); DataObject d; while (j.hasNext()) { d = j.next(); if (d instanceof TagAnnotationData) { p.add((TagAnnotationData) d); } } } String txt = formatTooltip(tag, p, user); node.setToolTip(txt); } selectedItems.add(node); } sortLists(); populateTreeItems(selectedItemsListbox, selectedItems); onSelectionChange(); return true; }
From source file:org.parosproxy.paros.view.SiteMapPanel.java
public void expandRoot() { TreeNode root = (TreeNode) treeSite.getModel().getRoot(); if (rootTreePath == null || root != rootTreePath.getPathComponent(0)) { rootTreePath = new TreePath(root); }/* w w w .ja v a 2 s .c om*/ if (EventQueue.isDispatchThread()) { getTreeSite().expandPath(rootTreePath); return; } try { EventQueue.invokeLater(new Runnable() { public void run() { getTreeSite().expandPath(rootTreePath); } }); } catch (Exception e) { log.warn(e.getMessage(), e); } }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java
public void fireTreeDataChanged() { final TreeModelEvent event = new TreeModelEvent(this, new TreePath(root)); final TreeModelListener[] modelListeners = listenerList.getListeners(TreeModelListener.class); for (int i = 0; i < modelListeners.length; i++) { final TreeModelListener modelListener = modelListeners[i]; modelListener.treeStructureChanged(event); }/*ww w .jav a 2 s.c o m*/ }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java
public TreePath getTreePathForSelection(FileObject selectedFolder, final String selection) throws FileSystemException { if (root.getRoot() == null) { return null; }/*from w w w.j a v a2s .c om*/ if (root.getRoot().equals(selectedFolder)) { return new TreePath(root); } final LinkedList<Object> list = new LinkedList<Object>(); while (selectedFolder != null) { list.add(0, selectedFolder); final FileObject parent = selectedFolder.getParent(); if (selectedFolder.equals(parent)) { break; } if (root.getRoot().equals(parent)) { break; } selectedFolder = parent; } list.add(0, root); return new TreePath(list.toArray()); }
From source file:org.photovault.swingui.folderpane.FolderController.java
/** Expand the paths to those folders that have photos in model */// ww w . jav a 2 s . co m private void expandTreePaths() { for (PhotoFolder folder : expandedFolders) { Vector parents = new Vector(); // parents.add( nodeMapper.mapFolderToNode( folder ) ); while ((folder = folder.getParentFolder()) != null) { parents.add(0, nodeMapper.mapFolderToNode(folder)); } if (parents.size() > 0) { TreePath path = new TreePath(parents.toArray()); Iterator viewIter = views.iterator(); while (viewIter.hasNext()) { PhotoSelectionView view = (PhotoSelectionView) viewIter.next(); view.expandFolderTreePath(path); } } } }
From source file:org.piraso.ui.base.RequestTreeTopComponent.java
private void btnTargetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTargetActionPerformed SwingUtilities.invokeLater(new Runnable() { @Override/* w ww .j av a 2s . c o m*/ public void run() { if (lastActiveMonitor == null || lastActiveMonitor.getSelectedRequest() == null) { return; } if (!((TopComponent) lastActiveMonitor).isOpened()) { lastActiveMonitor = null; return; } RequestEntry entry = lastActiveMonitor.getSelectedRequest(); synchronized (delegateHandlers) { ContextMonitorHandler handler = delegateHandlers.get(lastActiveMonitor); Child child = handler.childMap.get(entry.getBaseRequestId()); if (child != null) { TreePath path = new TreePath(child.node.getPath()); jTree.getSelectionModel().setSelectionPath(path); jTree.expandPath(path); } } } }); }
From source file:org.rdv.ui.ChannelListPanel.java
private void selectRootNode() { tree.addSelectionPath(new TreePath(treeModel.getRoot())); }
From source file:org.rdv.ui.ChannelListPanel.java
private void selectNode(String nodeName) { ChannelTree.Node node = treeModel.getChannelTree().findNode(nodeName); if (node != null) { int depth = node.getDepth(); Object[] path = new Object[depth + 2]; path[0] = treeModel.getRoot();/* w ww. j a v a2 s .c o m*/ for (int i = path.length - 1; i > 0; i--) { path[i] = node; node = node.getParent(); } tree.addSelectionPath(new TreePath(path)); } }