List of usage examples for javax.swing.tree DefaultMutableTreeNode setUserObject
public void setUserObject(Object userObject)
userObject
. From source file:gdt.jgui.entity.JEntityDigestDisplay.java
private DefaultMutableTreeNode[] getFacetOpenItems() { String[] sa = listFacetOpenItems(); if (sa == null) return null; DefaultMutableTreeNode facetNode; JFacetOpenItem facetOpenItem;/*from w w w . j ava 2s . c o m*/ Properties locator; Entigrator entigrator = console.getEntigrator(entihome$); ArrayList<DefaultMutableTreeNode> nl = new ArrayList<DefaultMutableTreeNode>(); for (String aSa : sa) { try { // System.out.println("EntityDigestDisplay:getFacetOpenItems:foi="+aSa); facetOpenItem = (JFacetOpenItem) JConsoleHandler.getHandlerInstance(entigrator, aSa); locator = new Properties(); locator.setProperty(Locator.LOCATOR_TYPE, LOCATOR_TYPE_FACET); locator.setProperty(BaseHandler.HANDLER_CLASS, aSa); locator.setProperty(BaseHandler.HANDLER_SCOPE, JConsoleHandler.CONSOLE_SCOPE); locator.setProperty(Locator.LOCATOR_ICON, facetOpenItem.getFacetIcon()); locator.setProperty(Locator.LOCATOR_TITLE, facetOpenItem.getFacetName()); locator.setProperty(NODE_TYPE, NODE_TYPE_FACET_HEADER); facetNode = new DefaultMutableTreeNode(); facetNode.setUserObject(Locator.toString(locator)); nl.add(facetNode); instantiateFacetNode(facetNode); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } Collections.sort(nl, new NodeComparator()); return nl.toArray(new DefaultMutableTreeNode[0]); }
From source file:gdt.jgui.entity.fields.JFieldsFacetOpenItem.java
/** * Get children nodes of the facet node for the digest view. * @return the children nodes of the facet node. *///ww w .j a v a 2s . c o m @Override public DefaultMutableTreeNode[] getDigest() { try { //System.out.println("JFieldsFacetOpenItem:getDigest:locator="+locator$); Properties locator = Locator.toProperties(locator$); entihome$ = locator.getProperty(Entigrator.ENTIHOME); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); Core[] ca = entity.elementGet("field"); if (ca == null) return null; DefaultMutableTreeNode nameNode; DefaultMutableTreeNode valueNode; String locator$ = getLocator(); String nameLocator$; String valueLocator$; String nameIcon$ = icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "text.png"); String valueIcon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "equal.png"); ArrayList<DefaultMutableTreeNode> nl = new ArrayList<DefaultMutableTreeNode>(); for (Core aCa : ca) { nameNode = new DefaultMutableTreeNode(); nameLocator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, aCa.name); nameLocator$ = Locator.append(nameLocator$, Locator.LOCATOR_TYPE, FIELD_NAME); nameLocator$ = Locator.append(nameLocator$, FIELD_NAME, aCa.name); nameLocator$ = Locator.append(nameLocator$, Locator.LOCATOR_ICON, nameIcon$); nameLocator$ = Locator.append(nameLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_FIELD_NAME); if (entihome$ != null) nameLocator$ = Locator.append(nameLocator$, Entigrator.ENTIHOME, entihome$); nameLocator$ = Locator.append(nameLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_FIELD_VALUE); if (entityKey$ != null) nameLocator$ = Locator.append(nameLocator$, EntityHandler.ENTITY_KEY, entityKey$); nameNode.setUserObject(nameLocator$); valueNode = new DefaultMutableTreeNode(); valueLocator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, aCa.value); valueLocator$ = Locator.append(valueLocator$, FIELD_NAME, aCa.name); valueLocator$ = Locator.append(valueLocator$, FIELD_VALUE, aCa.value); valueLocator$ = Locator.append(valueLocator$, Locator.LOCATOR_TYPE, FIELD_VALUE); valueLocator$ = Locator.append(valueLocator$, Locator.LOCATOR_ICON, valueIcon$); valueLocator$ = Locator.append(valueLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_FIELD_VALUE); if (entihome$ != null) valueLocator$ = Locator.append(valueLocator$, Entigrator.ENTIHOME, entihome$); valueLocator$ = Locator.append(valueLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_FIELD_VALUE); if (entityKey$ != null) valueLocator$ = Locator.append(valueLocator$, EntityHandler.ENTITY_KEY, entityKey$); valueNode.setUserObject(valueLocator$); // System.out.println("JFieldsFacetOpenItem:getDigest:VALUE locator="+valueLocator$); nameNode.add(valueNode); nl.add(nameNode); } return nl.toArray(new DefaultMutableTreeNode[0]); } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } return null; }
From source file:gdt.jgui.entity.folder.JFolderFacetOpenItem.java
/** * Get children nodes of the facet node for the digest view. * @return the children nodes of the facet node. *//*from w ww. jav a 2 s. com*/ @Override public DefaultMutableTreeNode[] getDigest() { try { // System.out.println("JFolderFacetOpenItem:getDigest:locator="+locator$); Properties locator = Locator.toProperties(locator$); entihome$ = locator.getProperty(Entigrator.ENTIHOME); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); String folderPath$ = entihome$ + "/" + entityKey$; File folder = new File(folderPath$); DefaultMutableTreeNode fileNode; File[] fa = folder.listFiles(); if (fa == null) return null; ArrayList<DefaultMutableTreeNode> fnl = new ArrayList<DefaultMutableTreeNode>(); Properties fileLocator; String icon$; for (File f : fa) { fileLocator = new Properties(); fileLocator.setProperty(Locator.LOCATOR_TITLE, f.getName()); fileLocator.setProperty(Entigrator.ENTIHOME, entihome$); fileLocator.setProperty(EntityHandler.ENTITY_KEY, entityKey$); fileLocator.setProperty(BaseHandler.HANDLER_SCOPE, JConsoleHandler.CONSOLE_SCOPE); fileLocator.setProperty(JFolderPanel.FILE_NAME, f.getName()); // System.out.println("JFolderFacetOpenItem:getDigest:file="+f.getName()); fileLocator.setProperty(JFolderPanel.FILE_PATH, f.getPath()); fileLocator.setProperty(Locator.LOCATOR_TYPE, JFolderPanel.LOCATOR_TYPE_FILE); fileLocator.setProperty(Locator.LOCATOR_CHECKABLE, Locator.LOCATOR_TRUE); fileLocator.setProperty(JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_FILE_NODE); icon$ = Support.readHandlerIcon(null, getClass(), "file.png"); fileLocator.setProperty(Locator.LOCATOR_ICON, icon$); fileLocator.setProperty(BaseHandler.HANDLER_CLASS, getClass().getName()); fileLocator.setProperty(BaseHandler.HANDLER_METHOD, "openFile"); fileNode = new DefaultMutableTreeNode(); fileNode.setUserObject(Locator.toString(fileLocator)); fnl.add(fileNode); } return fnl.toArray(new DefaultMutableTreeNode[0]); } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } return null; }
From source file:gdt.jgui.entity.webset.JWebsetFacetOpenItem.java
/** * Get children nodes of the facet node for the digest view. * @return the children nodes of the facet node. *///ww w . j a va 2 s . c o m @Override public DefaultMutableTreeNode[] getDigest() { try { // System.out.println("JWebsetFacetOpenItem:getDigest:locator="+locator$); Properties locator = Locator.toProperties(locator$); entihome$ = locator.getProperty(Entigrator.ENTIHOME); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); Core[] ca = entity.elementGet("web"); if (ca == null) return null; DefaultMutableTreeNode nameNode; DefaultMutableTreeNode valueNode; String locator$ = getLocator(); String nameLocator$; String valueLocator$; String nameIcon$;//=icon$=Support.readHandlerIcon(JEntitiesPanel.class, "text.png"); String valueIcon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "equal.png"); ArrayList<DefaultMutableTreeNode> nl = new ArrayList<DefaultMutableTreeNode>(); for (Core aCa : ca) { nameNode = new DefaultMutableTreeNode(); nameLocator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, aCa.type); nameLocator$ = Locator.append(nameLocator$, Locator.LOCATOR_TYPE, JWeblinksPanel.WEB_LINK_NAME); nameLocator$ = Locator.append(nameLocator$, JWeblinksPanel.WEB_LINK_NAME, aCa.type); nameLocator$ = Locator.append(nameLocator$, JWeblinksPanel.WEB_LINK_KEY, aCa.name); nameIcon$ = entity.getElementItemAt("web.icon", aCa.name); if (nameIcon$ != null) nameLocator$ = Locator.append(nameLocator$, Locator.LOCATOR_ICON, nameIcon$); nameLocator$ = Locator.append(nameLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_WEB_NAME); if (entihome$ != null) nameLocator$ = Locator.append(nameLocator$, Entigrator.ENTIHOME, entihome$); nameLocator$ = Locator.append(nameLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_WEB_ADDRESS); if (entityKey$ != null) nameLocator$ = Locator.append(nameLocator$, EntityHandler.ENTITY_KEY, entityKey$); nameNode.setUserObject(nameLocator$); valueNode = new DefaultMutableTreeNode(); valueLocator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, aCa.value); valueLocator$ = Locator.append(valueLocator$, JWeblinksPanel.WEB_LINK_NAME, aCa.type); valueLocator$ = Locator.append(valueLocator$, JWeblinksPanel.WEB_LINK_URL, aCa.value); valueLocator$ = Locator.append(valueLocator$, JWeblinksPanel.WEB_LINK_KEY, aCa.name); valueLocator$ = Locator.append(valueLocator$, Locator.LOCATOR_TYPE, LOCATOR_TYPE_WEB_ADDRESS); valueLocator$ = Locator.append(valueLocator$, Locator.LOCATOR_ICON, valueIcon$); valueLocator$ = Locator.append(valueLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_WEB_ADDRESS); if (entihome$ != null) valueLocator$ = Locator.append(valueLocator$, Entigrator.ENTIHOME, entihome$); valueLocator$ = Locator.append(valueLocator$, JEntityDigestDisplay.NODE_TYPE, NODE_TYPE_WEB_ADDRESS); if (entityKey$ != null) valueLocator$ = Locator.append(valueLocator$, EntityHandler.ENTITY_KEY, entityKey$); valueNode.setUserObject(valueLocator$); // System.out.println("JFieldsFacetOpenItem:getDigest:VALUE locator="+valueLocator$); nameNode.add(valueNode); nl.add(nameNode); } return nl.toArray(new DefaultMutableTreeNode[0]); } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } return null; }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected File promptUserForNewFile(String wavePath) { JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP3s and WAVs", "mp3", "wav"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);//from w w w . j a va 2s. co m chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { DefaultMutableTreeNode selectedFile = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); //Strip caps and spaces out of filenames. The item sound parser seems to have trouble with them. String destFileName = chosenFile.getFileName().toString().toLowerCase().replace(" ", "_"); Path destPath = Paths.get(installDir, "/dota/sound/" + getCustomSoundPathString() + destFileName); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); String waveString = selectedFile.getUserObject().toString(); int startIndex = -1; int endIndex = -1; if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); waveString = waveString.replace(waveStringFilePath, "\"" + getCustomSoundPathString() + destFileName + "\""); selectedFile.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:dotaSoundEditor.Controls.ItemPanel.java
@Override protected File promptUserForNewFile(String wavePath) { DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); String waveString = selectedTreeNode.getUserObject().toString(); String allowedExtension = FilenameUtils.getExtension(waveString).replace("\"", ""); JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = allowedExtension.equals("wav") ? new FileNameExtensionFilter("WAVs", "wav") : new FileNameExtensionFilter("MP3s", "mp3"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);//from w ww . ja va 2s . c o m chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); int startIndex = -1; int endIndex = -1; //Get the actual value for the wavestring key-value pair. if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); String waveStringNormalizedFilePath = waveStringFilePath.substring(0, waveStringFilePath.lastIndexOf("\"")); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace(")", ""); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace("\"", ""); Path destPath = Paths.get(installDir, "/dota/sound/" + waveStringNormalizedFilePath); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); if (waveString.contains("//")) { waveString = waveString .replace(waveString.substring(waveString.indexOf("//"), waveString.length()), ""); } waveString = waveString.replace(waveStringFilePath, "\"" + waveStringNormalizedFilePath + "\" //Replaced by: " + chosenFile.getFileName().toString()); selectedTreeNode.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java
/** * @param node//from w w w . ja va 2s. c om * @param containersToBeDeleted * @param colObjsToBeUpdated */ private void recursePrune(final DefaultMutableTreeNode node, final ArrayList<Container> containersToBeDeleted, final ArrayList<CollectionObject> colObjsToBeUpdated) { if (node.getUserObject() instanceof Container) { Container cn = (Container) node.getUserObject(); if (cn.getId() != null) { containersToBeDeleted.add(cn); containerIdHash.remove(cn.getId()); CollectionObject co = cn.getCollectionObject(); if (co != null) { cn.getCollectionObjects().clear(); co.setContainer(null); colObjsToBeUpdated.add(cn.getCollectionObject()); colObjIdHash.remove(co.getId()); } for (int i = 0; i < node.getChildCount(); i++) { recursePrune((DefaultMutableTreeNode) node.getChildAt(i), containersToBeDeleted, colObjsToBeUpdated); } cn.getChildren().clear(); for (CollectionObject coKid : cn.getCollectionObjectKids()) { coKid.setContainerOwner(null); colObjsToBeUpdated.add(coKid); colObjIdHash.remove(coKid.getId()); } cn.getCollectionObjectKids().clear(); } } else { CollectionObject co = (CollectionObject) node.getUserObject(); co.setContainer(null); co.setContainerOwner(null); colObjsToBeUpdated.add(co); colObjIdHash.remove(co.getId()); } node.setUserObject(null); model.removeNodeFromParent(node); }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected void revertButtonActionPerformed(ActionEvent evt, Path vpkToRevert) { //TODO: See if we can abstract away some of this functionality if (currentTree.getSelectionRows().length != 0 && ((TreeNode) currentTree.getSelectionPath().getLastPathComponent()).isLeaf()) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) currentTree.getSelectionPath() .getLastPathComponent(); String selectedWaveString = ((DefaultMutableTreeNode) selectedNode).getUserObject().toString(); String selectedWaveParentString = ((DefaultMutableTreeNode) ((DefaultMutableTreeNode) selectedNode) .getParent()).getUserObject().toString(); selectedNode = (DefaultMutableTreeNode) this.getTreeNodeFromWavePath(selectedWaveString); //First go in and delete the sound in customSounds deleteSoundFileByWaveString(selectedWaveString); //Get the relevant wavestring from the internal scriptfile VPKArchive vpk = new VPKArchive(); try {/* w w w .j av a 2 s.c o m*/ vpk.load(new File(vpkToRevert.toString())); } catch (IOException ex) { ex.printStackTrace(); } String scriptDir = getCurrentScriptString(); scriptDir = scriptDir.replace(Paths.get(installDir, "/dota/").toString(), ""); scriptDir = scriptDir.replace("\\", "/"); //Match internal forward slashes scriptDir = scriptDir.substring(1); //Cut off leading slash byte[] bytes = null; VPKEntry entry = vpk.getEntry(scriptDir); try { ByteBuffer scriptBuffer = entry.getData(); bytes = new byte[scriptBuffer.remaining()]; scriptBuffer.get(bytes); } catch (IOException ex) { ex.printStackTrace(); } String scriptFileString = new String(bytes, Charset.forName("UTF-8")); ArrayList<String> wavePathList = this.getWavePathsAsList(selectedNode.getParent()); int waveStringIndex = wavePathList.indexOf(selectedWaveString); //Cut off every part of the scriptFileString before we get to the entry describing the relevant hero action, so we don't accidentally get the wrong wavepaths StringBuilder scriptFileStringShortened = new StringBuilder(); Scanner scan = new Scanner(scriptFileString); boolean found = false; while (scan.hasNextLine()) { String curLine = scan.nextLine(); if (curLine.equals(selectedWaveParentString)) { found = true; } if (found == true) { scriptFileStringShortened.append(curLine).append(System.lineSeparator()); } } scriptFileString = scriptFileStringShortened.toString(); ArrayList<String> internalWavePathsList = getWavePathListFromString(scriptFileString); String replacementString = internalWavePathsList.get(waveStringIndex); selectedNode.setUserObject(replacementString); ScriptParser parser = new ScriptParser(this.currentTreeModel); parser.writeModelToFile(getCurrentScriptString()); //Modify the UI treeNode in addition to the backing TreeNode ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(replacementString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); } }
From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java
public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equalsIgnoreCase("Rename ...")) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent(); QueryMasterData ndata = (QueryMasterData) node.getUserObject(); Object inputValue = JOptionPane.showInputDialog(this, "Rename this query to: ", "Rename Query Dialog", JOptionPane.PLAIN_MESSAGE, null, null, ndata.name().substring(0, ndata.name().lastIndexOf("[") - 1)); if (inputValue != null) { String newQueryName = (String) inputValue; String requestXml = ndata.writeRenameQueryXML(newQueryName); lastRequestMessage = requestXml; setCursor(new Cursor(Cursor.WAIT_CURSOR)); String response = QueryListNamesClient.sendQueryRequestREST(requestXml); if (response.equalsIgnoreCase("CellDown")) { final JPanel parent = this; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(parent, "Trouble with connection to the remote server, " + "this is often a network error, please try again", "Network Error", JOptionPane.INFORMATION_MESSAGE); }/* w ww.j ava2s .c o m*/ }); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); return; } lastResponseMessage = response; if (response != null) { JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil(); try { JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus(); String status = statusType.getType(); if (status.equalsIgnoreCase("DONE")) { ndata.name(newQueryName + " [" + ndata.userId() + "]"); node.setUserObject(ndata); //DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); jTree1.repaint(); } } catch (Exception ex) { ex.printStackTrace(); } } setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } else if (e.getActionCommand().equalsIgnoreCase("Delete")) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent(); QueryMasterData ndata = (QueryMasterData) node.getUserObject(); Object selectedValue = JOptionPane.showConfirmDialog(this, "Delete Query \"" + ndata.name() + "\"?", "Delete Query Dialog", JOptionPane.YES_NO_OPTION); if (selectedValue.equals(JOptionPane.YES_OPTION)) { System.out.println("delete " + ndata.name()); String requestXml = ndata.writeDeleteQueryXML(); lastRequestMessage = requestXml; //System.out.println(requestXml); setCursor(new Cursor(Cursor.WAIT_CURSOR)); String response = QueryListNamesClient.sendQueryRequestREST(requestXml); if (response.equalsIgnoreCase("CellDown")) { final JPanel parent = this; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(parent, "Trouble with connection to the remote server, " + "this is often a network error, please try again", "Network Error", JOptionPane.INFORMATION_MESSAGE); } }); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); return; } lastResponseMessage = response; if (response != null) { JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil(); try { JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus(); String status = statusType.getType(); if (status.equalsIgnoreCase("DONE")) { treeModel.removeNodeFromParent(node); //jTree1.repaint(); } } catch (Exception ex) { ex.printStackTrace(); } } setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } else if (e.getActionCommand().equalsIgnoreCase("Refresh All")) { String status = loadPreviousQueries(false); if (status.equalsIgnoreCase("")) { reset(200, false); } else if (status.equalsIgnoreCase("CellDown")) { final JPanel parent = this; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(parent, "Trouble with connection to the remote server, " + "this is often a network error, please try again", "Network Error", JOptionPane.INFORMATION_MESSAGE); } }); } } }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private DefaultMutableTreeNode convertInfoValueTreeToInfoComponentTree(DefaultMutableTreeNode infoValueTree) throws ModelInformationException { @SuppressWarnings("rawtypes") final Enumeration nodes = infoValueTree.breadthFirstEnumeration(); nodes.nextElement(); // root while (nodes.hasMoreElements()) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement(); if (node.getUserObject() != null) { @SuppressWarnings("unchecked") final Pair<ParameterInfo, String> userObj = (Pair<ParameterInfo, String>) node.getUserObject(); final JComponent component = convertStringToComponent(userObj.getKey(), userObj.getValue()); final Pair<ParameterInfo, JComponent> newUserObj = new Pair<ParameterInfo, JComponent>( userObj.getKey(), component); node.setUserObject(newUserObj); }//from w ww. ja v a 2s . c o m } return infoValueTree; }