List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:de.rub.syssec.saaf.gui.editor.FileTree.java
public DefaultMutableTreeNode searchNode(String nodeStr, String lineNr) { DefaultMutableTreeNode node = null; @SuppressWarnings("unchecked") Enumeration<DefaultMutableTreeNode> e = ((DefaultMutableTreeNode) fileTree.getModel().getRoot()) .breadthFirstEnumeration();/*from w ww .ja va 2s . c om*/ while (e.hasMoreElements()) { node = (DefaultMutableTreeNode) e.nextElement(); String filepath = ""; for (int i = 0; i < node.getPath().length; i++) { filepath = filepath + File.separator + node.getPath()[i]; } if (filepath.startsWith(nodeStr)) { TreeNode[] nodes = node.getPath(); TreePath path = new TreePath(nodes); fileTree.scrollPathToVisible(path); fileTree.setSelectionPath(path); if (lineNr != null) { try { editor.goToLine(Integer.parseInt(lineNr)); } catch (Exception e1) { logger.warn("Problem during tree construction", e1); } } return node; } } return null; }
From source file:com.mirth.connect.client.ui.ChannelTreeTableModel.java
public void refresh() { MutableTreeTableNode root = (MutableTreeTableNode) getRoot(); if (root != null) { modelSupport.firePathChanged(new TreePath(root)); }/*from www . j a va 2s.c o m*/ }
From source file:mobac.gui.components.JMapSourceTree.java
/** * This method searches for a TreePath of a requested MapSouce * /*w w w.j a va2 s . c om*/ * @param mapSource * - analyzed mapSource object * @return TreePath of a specified MapSource or null otherwise */ private TreePath findTreePathOfMapSource(MapSource mapSource) { @SuppressWarnings("unchecked") Enumeration<ComparableTreeNode> rootDescendants = rootNode.depthFirstEnumeration(); while (rootDescendants.hasMoreElements()) { ComparableTreeNode descendantNode = rootDescendants.nextElement(); if (descendantNode.getUserObject().equals(mapSource)) { return new TreePath(descendantNode.getPath()); } } return null; }
From source file:fxts.stations.ui.help.HelpPane.java
/** * This method is called when new item selected at content tree * * @param aId identifer of the page.//from w ww . j a va 2s . c o m */ public void onSelectContent(String aId) { //if synchronizing of contents mode if (mContentSinchronize) { mContentSinchronize = false; return; } //check id if (aId == null) { mLogger.debug("Zero id of page."); return; } if (!mRepaintMode) { if (aId.equals(mCurrentPageId)) { return; } } //gets url of page by id String sUrl = mContentTree.getPageUrl(aId); if (sUrl == null) { //System.out.println("URL for page with id = " + asId + " not fond"); return; } //creates full url String sFullUrl = mContentTree.getHelpPrefix(); if (sFullUrl == null) { sFullUrl = ""; } sFullUrl += "/"; sFullUrl += mResMan.getLocale().toString(); sFullUrl += "/"; sFullUrl += sUrl; //loads url URL url; try { url = getClass().getClassLoader().getResource(sFullUrl); } catch (Exception e) { url = null; } //if localized help not presence if (url == null) { //creates full url to help on default language sFullUrl = mContentTree.getHelpPrefix(); if (sFullUrl == null) { sFullUrl = ""; } sFullUrl += "/"; sFullUrl += mResMan.getDefaultLocale().toString(); sFullUrl += "/"; sFullUrl += sUrl; //loads url to help on default language try { url = getClass().getClassLoader().getResource(sFullUrl); } catch (Exception e) { url = null; } //if help this page not presence even at default language if (url == null) { mLogger.debug("Page by url \"" + sFullUrl + "\" not found!"); mHtmlPage.setText(mResMan.getString("IDS_HELP_WINDOW_NO_PAGE", "No page with url = ") + sFullUrl); return; } } try { mHtmlPage.setPage(url); //sets last opened page mCurrentPageId = aId; //if browsing by contents if (mContentsBrowsing) { //sinchronize contenst JTree tree = mContentTree.getTree(); TreePath rootPath = new TreePath(mContentTree.getTree().getModel().getRoot()); TreePath path = mContentTree.findPathByUrl(rootPath, sUrl); if (path != null) { mContentSinchronize = true; tree.setSelectionPath(path); tree.scrollPathToVisible(path); } else { mLogger.debug("Contents not synchronized!"); } mContentsBrowsing = false; } else { //setting browising by contents mContentTree.getIterator().setCurrentByUrl(sUrl); mUpButton.setEnabled(mContentTree.getIterator().hasPrevious()); mDownButton.setEnabled(mContentTree.getIterator().hasNext()); } //saving at history if (mIsHistorycalStep) { mIsHistorycalStep = false; //sinchronize contenst JTree tree = mContentTree.getTree(); TreePath rootPath = new TreePath(mContentTree.getTree().getModel().getRoot()); TreePath path = mContentTree.findPathByUrl(rootPath, sUrl); if (path != null) { mContentSinchronize = true; tree.setSelectionPath(path); tree.scrollPathToVisible(path); } else { mLogger.debug("Contents not synchronized!"); } } else { if (!mRepaintMode) { mHistory.put(aId); mBackButton.setEnabled(mHistory.hasBackStep()); mForwardButton.setEnabled(mHistory.hasForwardStep()); } else { mRepaintMode = false; } } } catch (Exception e) { mLogger.debug("Attempted to read a bad URL: " + url); mHtmlPage.setText(mResMan.getString("IDS_HELP_WINDOW_NO_PAGE", "No page with url:") + url.toString()); } }
From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java
public SecurityPanel(SPServerInfo serverInfo, Action closeAction, Dialog d, ArchitectSession session) { this.closeAction = closeAction; splitpane = new JSplitPane(); panel = new JPanel(); ArchitectClientSideSession clientSideSession = ArchitectClientSideSession.getSecuritySessions() .get(serverInfo.getServerAddress()); //Displaying an indeterminate progress bar in place of the split pane //until the security session has loaded fully. if (clientSideSession.getUpdater().getRevision() <= 0) { JLabel messageLabel = new JLabel("Opening"); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref:grow, 5dlu, pref")); builder.setDefaultDialogBorder(); builder.append(messageLabel, 3); builder.nextLine();//from w w w . j av a2 s . c om builder.append(progressBar, 3); UpdateListener l = new UpdateListener() { @Override public void workspaceDeleted() { //do nothing } @Override public boolean updatePerformed(AbstractNetworkConflictResolver resolver) { panel.removeAll(); panel.add(splitpane); dialog.pack(); refreshTree(); return true; } @Override public boolean updateException(AbstractNetworkConflictResolver resolver, Throwable t) { //do nothing, the error will be handled elsewhere return true; } @Override public void preUpdatePerformed(AbstractNetworkConflictResolver resolver) { //do nothing } }; clientSideSession.getUpdater().addListener(l); panel.add(builder.getPanel()); } this.securityWorkspace = clientSideSession.getWorkspace(); this.username = serverInfo.getUsername(); this.dialog = d; this.session = session; try { digester = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } rootNode.add(usersNode); rootNode.add(groupsNode); rightSidePanel = new JPanel(); tree = new JTree(rootNode); tree.addTreeSelectionListener(treeListener); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setCellRenderer(new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); if (userObject instanceof User) { setIcon(USER_ICON); } else if (userObject instanceof Group) { setIcon(GROUP_ICON); } return this; } }); treePane = new JScrollPane(tree); treePane.setPreferredSize(new Dimension(200, treePane.getPreferredSize().height)); tree.addMouseListener(popupListener); splitpane.setRightComponent(rightSidePanel); splitpane.setLeftComponent(treePane); if (clientSideSession.getUpdater().getRevision() > 0) { panel.removeAll(); panel.add(splitpane); } refreshTree(); try { tree.setSelectionPath(new TreePath(usersNode.getFirstChild())); } catch (NoSuchElementException e) { } // This just means that the node has no children, so we cannot expand the path. }
From source file:edu.ku.brc.specify.tasks.subpane.security.NavigationTreeContextMenuMgr.java
/** * @param node//from ww w.ja va 2 s.c om */ private void addToAdminGroup(final DefaultMutableTreeNode node) { if (node != null) { Object userObject = node.getUserObject(); if (userObject != null) { FormDataObjIFace dmObject = ((DataModelObjBaseWrapper) userObject).getDataObj(); if (dmObject != null && dmObject instanceof SpecifyUser) { SpPrincipal adminPrin = null; DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); adminPrin = (SpPrincipal) session.getData(SpPrincipal.class, "name", "Administrator", DataProviderSessionIFace.CompareType.Equals); if (adminPrin != null) { SpecifyUser spUser = session.get(SpecifyUser.class, ((SpecifyUser) dmObject).getId()); spUser.addUserToSpPrincipalGroup(adminPrin); session.beginTransaction(); session.saveOrUpdate(spUser); session.saveOrUpdate(adminPrin); session.commit(); DefaultMutableTreeNode adminNode = getAdminTreeNode( (DefaultMutableTreeNode) treeMgr.getTree().getModel().getRoot()); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( new DataModelObjBaseWrapper(spUser)); DefaultTreeModel model = (DefaultTreeModel) getTree().getModel(); model.insertNodeInto(newNode, adminNode, adminNode.getChildCount()); model.nodeChanged(adminNode); model.nodeChanged(newNode); getTree().repaint(); getTree().setSelectionPath(new TreePath(newNode.getPath())); lastClickComp = null; updateBtnUI(); } } catch (final Exception e1) { e1.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(NavigationTreeMgr.class, e1); session.rollback(); } finally { if (session != null) { session.close(); } } } } } }
From source file:fxts.stations.ui.help.ContentTree.java
/** * Fires expanding of top nodes./* w w w . j a v a2 s . c om*/ */ private void expandTopNodes() { DefaultMutableTreeNode node; DefaultMutableTreeNode root; TreePath path; TreePath rootPath; root = (DefaultMutableTreeNode) mTree.getModel().getRoot(); rootPath = new TreePath(root); for (Enumeration enumeration = root.children(); enumeration.hasMoreElements();) { node = (DefaultMutableTreeNode) enumeration.nextElement(); //increase path path = rootPath.pathByAddingChild(node); //expands node mTree.expandPath(path); } }
From source file:uk.co.markfrimston.tasktree.Main.java
protected DefaultMutableTreeNode addTask(DefaultMutableTreeNode parent, int childPos, String name, boolean show) { DefaultMutableTreeNode newNode = taskTree.addTask(parent, childPos, name); if (show) {//www. jav a2 s . com tree.makeVisible(new TreePath(newNode.getPath())); } return newNode; }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath) { try {/* w w w . j a va 2 s . co m*/ root.removeAllChildren(); if (parentPath.length() > 0) parentPath += "."; Class clazz = Class.forName(classname, true, IReportManager.getInstance().getReportClassLoader()); java.beans.PropertyDescriptor[] pd = org.apache.commons.beanutils.PropertyUtils .getPropertyDescriptors(clazz); for (int nd = 0; nd < pd.length; ++nd) { String fieldName = pd[nd].getName(); if (pd[nd].getPropertyType() != null && pd[nd].getReadMethod() != null) { Class clazzRT = pd[nd].getPropertyType(); if (clazzRT.isPrimitive()) { clazzRT = MethodUtils.getPrimitiveWrapper(clazzRT); } String returnType = clazzRT.getName(); JRDesignField field = new JRDesignField(); field.setName(fieldName); field.setValueClassName(returnType); if (isPathOnDescription()) { field.setDescription(parentPath + fieldName); } else { field.setName(parentPath + fieldName); } TreeJRField jtf = new TreeJRField(); jtf.setField(field); jtf.setObj(pd[nd].getPropertyType()); boolean bChildrens = true; if (pd[nd].getPropertyType().isPrimitive() || pd[nd].getPropertyType().getName().startsWith("java.lang.")) { bChildrens = false; } root.add(new DefaultMutableTreeNode(jtf, bChildrens)); } } jTree1.expandPath(new TreePath(root.getPath())); jTree1.updateUI(); } catch (ClassNotFoundException cnf) { javax.swing.JOptionPane.showMessageDialog(this, Misc.formatString( //"messages.BeanInspectorPanel.classNotFoundError", I18n.getString("BeanInspectorPanel.Message.Error"), new Object[] { cnf.getMessage() }), I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } catch (Exception ex) { ex.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(), I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } }
From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java
private void refreshTree() { tree.setModel(new DefaultTreeModel(rootNode)); usersNode.removeAllChildren();/* ww w. j ava2s .c o m*/ for (User user : securityWorkspace.getChildren(User.class)) { usersNode.add(new DefaultMutableTreeNode(user)); } groupsNode.removeAllChildren(); for (Group group : securityWorkspace.getChildren(Group.class)) { groupsNode.add(new DefaultMutableTreeNode(group)); } tree.expandPath(new TreePath(usersNode.getPath())); tree.expandPath(new TreePath(groupsNode.getPath())); }