List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:hr.fer.zemris.vhdllab.view.explorer.ProjectExplorerView.java
private MutableTreeNode addProject(Project project) { MutableTreeNode projectNode = insertNode(root, project); tree.requestFocusInWindow();/*from ww w . j a v a2 s .c om*/ tree.setSelectionPath(new TreePath(new Object[] { root, projectNode })); return projectNode; }
From source file:uk.co.markfrimston.tasktree.Main.java
protected void synchronise() { try {//from w w w. ja v a2s . c o m syncButton.setEnabled(false); taskTree.synchronise(this); // make top level tasks visible for (int i = 0; i < this.taskTree.getRoot().getChildCount(); i++) { tree.makeVisible( new TreePath(((DefaultMutableTreeNode) this.taskTree.getRoot().getChildAt(i)).getPath())); } } catch (Exception e) { error("Failed to synchronise: " + e.getClass().getName() + " - " + e.getMessage()); } finally { syncButton.setEnabled(true); } }
From source file:fxts.stations.ui.help.HelpPane.java
/** * This method is called when hyperlink activated. * * @param aUrl url to page.// w w w .j av a2s . c om */ public void onSelectContentByHyperlink(URL aUrl) { if (aUrl == null) { mLogger.debug("Hyperlink is null!"); return; } try { mHtmlPage.setPage(aUrl); String sUrl = getShortUrl(aUrl); if (sUrl != null) { //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); } else { //System.out.println("Contents not synchronized!"); } //setting browising by contents mContentTree.getIterator().setCurrentByUrl(sUrl); mUpButton.setEnabled(mContentTree.getIterator().hasPrevious()); mDownButton.setEnabled(mContentTree.getIterator().hasNext()); //saving at history String sId = mContentTree.getPageId(sUrl); mHistory.put(sId); mBackButton.setEnabled(mHistory.hasBackStep()); mForwardButton.setEnabled(mHistory.hasForwardStep()); //sets last opened page mCurrentPageId = sId; } else { mLogger.debug("Short url not found for full url = " + aUrl.toString()); } } catch (Exception e) { mLogger.error("Attempted to read a bad URL from hyperlink: " + aUrl); mHtmlPage.setText(mResMan.getString("IDS_HELP_WINDOW_NO_PAGE", "No page with url:") + aUrl.toString()); } }
From source file:gdt.jgui.entity.index.JIndexPanel.java
/** * Get the context menu./*from ww w. jav a 2 s .c om*/ * @return the context menu. */ @Override public JMenu getContextMenu() { menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { //System.out.println("IndexPanel:getConextMenu:menu selected"); menu.removeAll(); JMenuItem expandItem = new JMenuItem("Expand"); expandItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { expandAll(tree, new TreePath(rootNode), true); } }); menu.add(expandItem); JMenuItem collapseItem = new JMenuItem("Collapse"); collapseItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { expandAll(tree, new TreePath(rootNode), false); } }); menu.add(collapseItem); final TreePath[] tpa = tree.getSelectionPaths(); if (tpa != null && tpa.length > 0) { menu.addSeparator(); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cut = false; console.clipboard.clear(); DefaultMutableTreeNode node; String locator$; for (TreePath tp : tpa) { node = (DefaultMutableTreeNode) tp.getLastPathComponent(); locator$ = (String) node.getUserObject(); if (locator$ != null) console.clipboard.putString(locator$); } } }); menu.add(copyItem); JMenuItem cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cut = true; console.clipboard.clear(); DefaultMutableTreeNode node; String locator$; for (TreePath tp : tpa) { node = (DefaultMutableTreeNode) tp.getLastPathComponent(); locator$ = (String) node.getUserObject(); if (locator$ != null) console.clipboard.putString(locator$); } } }); menu.add(cutItem); JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { try { DefaultMutableTreeNode node; String locator$; String nodeKey$; for (TreePath tp : tpa) { node = (DefaultMutableTreeNode) tp.getLastPathComponent(); locator$ = (String) node.getUserObject(); nodeKey$ = Locator.getProperty(locator$, NODE_KEY); index.removeElementItem("index.title", nodeKey$); index.removeElementItem("index.jlocator", nodeKey$); } Entigrator entigrator = console.getEntigrator(entihome$); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } catch (Exception ee) { LOGGER.info(ee.toString()); } } } }); menu.add(deleteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
From source file:com.lp.client.frame.component.PanelDokumentenablage.java
private void refresh() throws ExceptionLP, Throwable { List<DocNodeBase> parts = fullDocPath.getDeepCopy().asDocNodeList(); boolean isSuche = wtfSuche.getText() != null && !"".equals(wtfSuche.getText()); DefaultMutableTreeNode dmtNode = null; Object[] toSelect = new Object[parts.size()]; if (parts.size() > 0) { dmtNode = new DefaultMutableTreeNode(parts.get(0)); toSelect[0] = dmtNode;// ww w .jav a2 s .c om treeModel = new DefaultTreeModel(dmtNode); treeModel.addTreeModelListener(this); } for (int i = 1; i < parts.size() && !isSuche; i++) { DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(parts.get(i)); toSelect[i] = toAdd; treeModel.insertNodeInto(toAdd, dmtNode, dmtNode.getChildCount()); dmtNode = toAdd; } TreePath treePath = new TreePath(toSelect); TreePath treePathOld = null; if (toSelect.length >= 2) { treePathOld = new TreePath(toSelect[toSelect.length - 2]); } else { treePathOld = new TreePath(toSelect); } // Value Changed damit die Buttons korrekt angezeigt werden valueChanged(new TreeSelectionEvent(tree, treePath, true, treePathOld, treePath)); if (isSuche) { setSearchedDocumentsOnTree(dmtNode, DelegateFactory.getInstance().getJCRDocDelegate().searchDocNodes(wtfSuche.getText())); for (int i = tree.getRowCount(); i > 0; i--) { tree.collapseRow(i); } } else if (dmtNode.getChildCount() == 0) { List<DocNodeBase> childDocNodes = DelegateFactory.getInstance().getJCRDocDelegate() .getDocNodeChildrenFromNode(fullDocPath); if (childDocNodes != null) { setDocNodesOnTree(dmtNode, childDocNodes, fullDocPath); tree.expandPath(treePath); } } tree.setSelectionPath(treePath); }
From source file:de.tor.tribes.ui.windows.DSWorkbenchSplashScreen.java
protected HIDE_RESULT hideSplash() { try {//from w w w . j a va2 s . c o m if (!new File(".").canWrite()) { try { throw new IOException( "Failed to access installation directory " + new File(".").getAbsolutePath()); } catch (Exception e) { showFatalError(e); return HIDE_RESULT.ERROR; } } File f = new File("./servers"); if (!f.exists() && !f.mkdir()) { try { throw new IOException( "Failed to create server directory at location " + new File(".").getAbsolutePath()); } catch (Exception e) { showFatalError(e); return HIDE_RESULT.ERROR; } } ProfileManager.getSingleton().loadProfiles(); if (ProfileManager.getSingleton().getProfiles().length == 0) { logger.debug("Starting first start wizard"); //first start wizard if (!new File("./hfsw").exists()) { logger.debug(" - Initializing first start wizard"); Map result = new HashMap<>(); try { WizardPanelProvider provider = new FirstStartWizard(); Wizard wizard = provider.createWizard(); logger.debug(" - Showing wizard"); result = (Map) WizardDisplayer.showWizard(wizard); logger.debug("Wizard finished with result " + result); } catch (Throwable t) { logger.error("Wizard exception", t); result = null; } logger.debug(" - Wizard has finished"); if (result == null) { logger.warn(" - Wizard returned no result. Startup will fail."); JOptionPaneHelper.showWarningBox(self, "Du musst die grundlegenden Einstellungen zumindest einmalig durchfhren,\n" + "um DS Workbench verwenden zu knnen. Bitte starte DS Workbench neu.", "Abbruch"); return HIDE_RESULT.ERROR; } else { logger.debug("Wizard result: " + result); } logger.debug("- First start wizard finished"); GlobalOptions.addProperty("proxySet", result.get("proxySet").toString()); GlobalOptions.addProperty("proxyHost", result.get("proxyHost").toString()); GlobalOptions.addProperty("proxyPort", result.get("proxyPort").toString()); GlobalOptions.addProperty("proxyType", result.get("proxyType").toString()); GlobalOptions.addProperty("proxyUser", result.get("proxyUser").toString()); GlobalOptions.addProperty("proxyPassword", result.get("proxyPassword").toString()); GlobalOptions.addProperty("default.server", result.get("server").toString()); GlobalOptions.addProperty("default.player", result.get("tribe.id").toString()); logger.debug("Creating initial profile"); UserProfile p = UserProfile.create(GlobalOptions.getProperty("default.server"), result.get("tribe.name").toString()); GlobalOptions.setSelectedProfile(p); GlobalOptions.addProperty("selected.profile", Long.toString(p.getProfileId())); logger.debug(" - Disabling first start wizard"); FileUtils.touch(new File("./hfsw")); GlobalOptions.saveProperties(); } } //load properties, cursors, skins, world decoration logger.debug("Adding startup listeners"); DataHolder.getSingleton().addDataHolderListener(this); DataHolder.getSingleton().addDataHolderListener(DSWorkbenchSettingsDialog.getSingleton()); GlobalOptions.addDataHolderListener(this); } catch (Exception e) { logger.error("Failed to initialize global options", e); showFatalError(e); return HIDE_RESULT.ERROR; } logger.debug("Starting profile selection"); boolean settingsRestored = false; ServerManager.loadServerList(DSWorkbenchSettingsDialog.getSingleton().getWebProxy()); try { //open profile selection if (ProfileManager.getSingleton().getProfiles().length == 0) { logger.debug("No profile exists, SettingsDialog will handle this"); //no profile found...this is handles by the settings validation } else if (ProfileManager.getSingleton().getProfiles().length == 1) { logger.debug("One profile exists. Using it..."); //only one single profile was found, use it UserProfile profile = ProfileManager.getSingleton().getProfiles()[0]; String server = profile.getServerId(); GlobalOptions.setSelectedServer(server); GlobalOptions.setSelectedProfile(profile); GlobalOptions.addProperty("default.server", server); GlobalOptions.addProperty("selected.profile", Long.toString(profile.getProfileId())); } else { logger.debug("More than one profiles exist. Showing selection dialog"); File f = new File("./servers"); List<String> servers = new LinkedList<>(); for (File server : f.listFiles()) { servers.add(server.getName()); } //sort server names Collections.sort(servers, new Comparator<String>() { @Override public int compare(String o1, String o2) { if (o1.length() < o2.length()) { return -1; } else if (o1.length() > o2.length()) { return 1; } return o1.compareTo(o2); } }); List<Object> path = new LinkedList<>(); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Profile"); long selectedProfile = GlobalOptions.getProperties().getLong("selected.profile"); path.add(root); for (String server : servers) { DefaultMutableTreeNode serverNode = new DefaultMutableTreeNode(server); boolean profileAdded = false; for (UserProfile profile : ProfileManager.getSingleton().getProfiles(server)) { DefaultMutableTreeNode profileNode = new DefaultMutableTreeNode(profile); if (profile.getProfileId() == selectedProfile) { path.add(serverNode); path.add(profileNode); } serverNode.add(profileNode); profileAdded = true; } if (profileAdded) { root.add(serverNode); } } jTree1.setModel(new DefaultTreeModel(root)); jTree1.setSelectionPath(new TreePath(path.toArray())); jTree1.scrollPathToVisible(new TreePath(path.toArray())); jTree1.setCellRenderer(new ProfileTreeNodeRenderer()); jProfileDialog.setVisible(true); } logger.debug("Profile selection finished"); //check settings DSWorkbenchSettingsDialog.getSingleton().restoreProperties(); settingsRestored = true; if (!DSWorkbenchSettingsDialog.getSingleton().checkSettings()) { logger.debug("Settings check in settings dialog failed"); logger.info("Reading user settings returned error(s)"); DSWorkbenchSettingsDialog.getSingleton().setBlocking(true); DSWorkbenchSettingsDialog.getSingleton().setVisible(true); } } catch (Exception e) { logger.warn("Failed to open profile manager", e); } if (!settingsRestored) { DSWorkbenchSettingsDialog.getSingleton().restoreProperties(); } // <editor-fold defaultstate="collapsed" desc=" Check for data updates "> logger.debug("Checking for application updates"); boolean checkForUpdates = GlobalOptions.getProperties().getBoolean("check.updates.on.startup"); try { if (!DataHolder.getSingleton().loadData(checkForUpdates)) { throw new Exception("loadData() returned 'false'. See log for more details."); } } catch (Exception e) { logger.error("Failed to load server data", e); showFatalError(e); return HIDE_RESULT.ERROR; } // </editor-fold> try { logger.debug("Initializing application window"); DSWorkbenchMainFrame.getSingleton().init(); logger.info("Showing application window"); DSWorkbenchMainFrame.getSingleton().setVisible(true); //check for version updates logger.info("Checking for DS Workbench update."); UpdateInfo info = GithubVersionCheck.getUpdateInformation(); switch (info.getStatus()) { case UPDATE_AVAILABLE: NotifierFrame.doNotification( "Eine neue DS Workbench Version ist verfgbar. Klick den grnen Punkt oben links, um auf die Download Seite zu gelangen. ", NotifierFrame.NOTIFY_UPDATE); default: logger.info("No update available or update check failed."); } try { ReportServer.getSingleton().start(GlobalOptions.getProperties().getInt("report.server.port")); } catch (Exception e) { logger.error("Failed to start report server", e); } // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(DSWorkbenchSimulatorFrame.getSingleton().getRootPane(), "pages.astar", GlobalOptions.getHelpBroker().getHelpSet()); GlobalOptions.getHelpBroker().enableHelpKey(DSWorkbenchMainFrame.getSingleton().getRootPane(), "index", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" Init A*Star Servers "> ServerManager.giveSimulatorServerList(); // </editor-fold> t.stopRunning(); setVisible(false); GlobalOptions.removeDataHolderListener(this); return HIDE_RESULT.SUCCESS; } catch (Throwable th) { logger.fatal("Fatal error while running DS Workbench", th); showFatalError(th); return HIDE_RESULT.ERROR; } }
From source file:gov.sandia.umf.platform.ui.jobs.RunPanel.java
public void delete() { TreePath[] paths = tree.getSelectionPaths(); if (paths.length < 1) return;//from w w w . j a va 2 s . co m boolean nextSelectionIsParent = false; NodeBase firstSelection = (NodeBase) paths[0].getLastPathComponent(); NodeBase lastSelection = (NodeBase) paths[paths.length - 1].getLastPathComponent(); NodeBase nextSelection = (NodeBase) lastSelection.getNextSibling(); if (nextSelection == null) nextSelection = (NodeBase) firstSelection.getPreviousSibling(); if (nextSelection == null) { nextSelection = (NodeBase) firstSelection.getParent(); nextSelectionIsParent = true; } for (TreePath path : paths) { final NodeBase node = (NodeBase) path.getLastPathComponent(); model.removeNodeFromParent(node); if (displayNode == node) { synchronized (displayText) { displayText.setText(""); } if (displayPane.getViewport().getView() != displayText) displayPane.setViewportView(displayText); } new Thread("RunPanel Delete") { public void run() { if (node instanceof NodeJob) { NodeJob job = (NodeJob) node; synchronized (running) { running.remove(job); } MDoc doc = (MDoc) job.source; ExecutionEnv env = ExecutionEnv.factory(doc.getOrDefault("localhost", "$metadata", "host")); String jobName = doc.key(); try { env.deleteJob(jobName); } // TODO: Also terminate execution, if possible. catch (Exception e) { } doc.delete(); } else if (node instanceof NodeFile) { ((NodeFile) node).path.delete(); } }; }.start(); } if (nextSelectionIsParent) { if (nextSelection.getChildCount() > 0) tree.setSelectionPath(new TreePath(((NodeBase) nextSelection.getChildAt(0)).getPath())); else if (nextSelection != root) tree.setSelectionPath(new TreePath(nextSelection.getPath())); } else { tree.setSelectionPath(new TreePath(nextSelection.getPath())); } }
From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java
public DefaultMutableTreeNode addNode(QueryMasterData node) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node); QueryMasterData tmpData = new QueryMasterData(); tmpData.name("working ......"); tmpData.tooltip("A tmp node"); tmpData.visualAttribute("LAO"); DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData); treeModel.insertNodeInto(childNode, top, top.getChildCount()); if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) { treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount()); }//from ww w . j a v a 2 s . co m jTree1.expandPath(new TreePath(top.getPath())); return childNode; }
From source file:eu.apenet.dpt.standalone.gui.APETabbedPane.java
private void expandFirstLevel() { TreeModel model = tree.getTreeTableModel(); TreePath root = new TreePath(model.getRoot()); tree.expandPath(root);//w ww. j a v a 2 s .c o m for (int i = 0; i < tree.getRowCount(); i++) { if (i > 20) break; tree.expandRow(i); } }
From source file:com.clough.android.adbv.view.MainFrame.java
private void refreshDatabase() { inputQuery = ""; invalidateInputOutput();/*from w w w .j a va 2s . co m*/ new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { Thread.sleep(100); } catch (InterruptedException ex) { } try { String tableNames = MainFrame.this.ioManager.getTableNames(); tableNameJSONArray = new JSONArray(tableNames); } catch (IOManagerException ex) { showDeviceDisconnectedDialog(); } return null; } @Override protected void done() { closeProgressDialog(); } }.execute(); showProgressDialog(true, 0, "Waiting for table list"); tableInfoTree.removeAll(); tableInfoTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); final DefaultMutableTreeNode databaseDMTN = new DefaultMutableTreeNode(databaseName); tableInfoTree.setModel(new DefaultTreeModel(databaseDMTN)); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { Thread.sleep(100); } catch (InterruptedException ex) { } try { tables = new String[tableNameJSONArray.length()]; queries = new String[tableNameJSONArray.length()]; columns = new String[tableNameJSONArray.length()][]; columnInfos = new String[tableNameJSONArray.length()][][]; for (int i = 0; i < tableNameJSONArray.length(); i++) { tables[i] = tableNameJSONArray.getJSONObject(i).getString("name"); DefaultMutableTreeNode tableDMTN = new DefaultMutableTreeNode(tables[i]); databaseDMTN.add(tableDMTN); queries[i] = tableNameJSONArray.getJSONObject(i).getString("sql"); String tableColumnInfo = MainFrame.this.ioManager.getTableColumnInfo(tables[i]); JSONArray columnJSONArray = new JSONArray(tableColumnInfo); columns[i] = new String[columnJSONArray.length()]; columnInfos[i] = new String[columnJSONArray.length()][]; for (int j = 0; j < columnJSONArray.length(); j++) { JSONObject columnJSONObject = columnJSONArray.getJSONObject(j); columns[i][j] = columnJSONObject.getString("name"); columnInfos[i][j] = new String[4]; DefaultMutableTreeNode columnDMTN = new DefaultMutableTreeNode(columns[i][j]); columnInfos[i][j][0] = "Column ID : " + String.valueOf(columnJSONObject.getInt("cid")); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][0])); columnInfos[i][j][1] = "Type : " + columnJSONObject.getString("type"); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][1])); columnInfos[i][j][2] = "Def value : " + String.valueOf(columnJSONObject.getString("dflt_value")); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][2])); columnInfos[i][j][3] = "Not NULL : " + String.valueOf((columnJSONObject.getInt("notnull") == 1)); columnDMTN.add(new DefaultMutableTreeNode(columnInfos[i][j][3])); tableDMTN.add(columnDMTN); } databaseDMTN.add(tableDMTN); waitingDialog.incrementProgressBar(); } } catch (IOManagerException ex) { showDeviceDisconnectedDialog(); } return null; } @Override protected void done() { closeProgressDialog(); } }.execute(); showProgressDialog(false, tableNameJSONArray.length(), "Getting info of " + tableNameJSONArray.length() + " tables"); tableInfoTree.expandPath(new TreePath((TreeNode) tableInfoTree.getModel().getRoot())); tableNameJSONArray = null; }