List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java
public DefaultMutableTreeNode addNode(QueryResultData node, DefaultMutableTreeNode parent) { //QueryInstanceData rundata = (QueryInstanceData) parent.getUserObject(); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node); QueryInstanceData tmpData = new QueryInstanceData(); tmpData.name("working ......"); tmpData.tooltip("A tmp node"); tmpData.visualAttribute("LAO"); DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData); treeModel.insertNodeInto(childNode, parent, parent.getChildCount()); if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) { treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount()); }/*from w ww .j ava 2 s . c o m*/ //Make sure the user can see the lovely new node. jTree1.scrollPathToVisible(new TreePath(childNode.getPath())); DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0); QueryData tmpdata = (QueryData) tmpnode.getUserObject(); if (tmpdata.name().equalsIgnoreCase("working ......")) { treeModel.removeNodeFromParent(tmpnode); } return childNode; }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java
/** * /*from ww w. j a va 2 s .com*/ */ private void addColObjAsChild(final DefaultMutableTreeNode parentNodeArg, final CollectionObject colObj) { DefaultMutableTreeNode parentNode = parentNodeArg == null ? getSelectedTreeNode() : parentNodeArg; if (parentNode != null) { if (colObj != null) { Container container = (Container) parentNode.getUserObject(); colObj.setContainerOwner(container); container.getCollectionObjectKids().add(colObj); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(); newNode.setUserObject(colObj); colObjIdHash.add(colObj.getId()); int inx = parentNode.getChildCount(); model.insertNodeInto(newNode, parentNode, inx); model.nodesWereInserted(parentNode, new int[] { inx }); model.nodeChanged(parentNode); model.reload(); tree.restoreTree(); expandToNode(newNode); } } }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
/** * Deletes a ForRow or a FormCell.//from ww w . jav a 2s .c o m */ protected void delControl(final TYPE type) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getSelectionModel().getSelectionPath() .getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent(); Object formObj = selectedNode.getUserObject(); // For when we select delete row Menu when on a Control if (type == TYPE.DelRow && formObj instanceof FormCell) { selectedNode = parentNode; parentNode = (DefaultMutableTreeNode) parentNode.getParent(); formObj = selectedNode.getUserObject(); } if (formObj instanceof FormRow) { FormRow row = (FormRow) formObj; ((FormViewDef) parentNode.getUserObject()).getRows().remove(row); for (FormCellIFace formCell : row.getCells()) { idHash.remove(formCell.getIdent()); } } else if (formObj instanceof FormCell) { FormCell formCell = (FormCell) formObj; ((FormRow) parentNode.getUserObject()).getCells().remove(formCell); idHash.remove(formCell.getIdent()); } renumberRows(formViewDef.getRows()); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.removeNodeFromParent(selectedNode); }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
/** * @param selectedControl/*from w ww . jav a 2 s . c o m*/ * @param selectedCell */ protected void addControl(final ControlIFace selectedControl, @SuppressWarnings("hiding") final FormCell selectedCell) { int position = 0; if (selectedCell != null) { position = selectedRow.getCells().indexOf(selectedCell); } if (selectedControl instanceof RowControl) { addRow(); return; } @SuppressWarnings("hiding") EditorPropPanel panel = new EditorPropPanel(controlHash, subcontrolHash, getAvailableFieldCells(), false, this); //panel.setFormViewDef(formViewDef); FormCell formCell = null; boolean skip = false; if (selectedControl instanceof Control) { Control control = (Control) selectedControl; if (control.getType().equals("label")) //$NON-NLS-1$ { formCell = new FormCellLabel(); formCell.setIdent(Integer.toString(getNextId())); } if (formCell != null) { formCell.setType(FormCellIFace.CellType.valueOf(control.getType())); //System.out.println(formCell.getType() + " "+ formCell.getClass().getSimpleName()); panel.loadView(formCell.getType().toString(), selectedViewDef.getClassName()); panel.setDataIntoUI(formViewDef, formCell, (formViewDef.getRows().size() * 2) - 1, formViewDef.getRowDefItem().getNumItems(), selectedRow.getRowNumber(), (selectedRow.getCells().size() * 2) - 1, formViewDef.getColumnDefItem().getNumItems(), position); } } else { SubControl subControl = (SubControl) selectedControl; FormCellField fcf = null; if (subControl.getType().equals("combobox")) //$NON-NLS-1$ { fcf = new FormCellField(FormCell.CellType.field, Integer.toString(getNextId()), "", 1, 1); //$NON-NLS-1$ fcf.setUiType(FormCellFieldIFace.FieldType.combobox); setDefaultDspUIType(fcf); formCell = fcf; } //System.out.println("* ["+fcf.getUiType().toString() + "] "+ fcf.getClass().getSimpleName()); //SubControl subcontrol = subcontrolHash.get(fcf.getUiType().toString()); //System.out.println("SC: "+subcontrol); panel.loadView(fcf.getUiType().toString(), selectedViewDef.getClassName()); panel.setDataIntoUI(formViewDef, fcf, (formViewDef.getRows().size() * 2) - 1, formViewDef.getRowDefItem().getNumItems(), selectedRow.getRowNumber(), (selectedRow.getCells().size() * 2) - 1, formViewDef.getColumnDefItem().getNumItems(), position); } if (!skip && formCell != null) { CustomDialog propDlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), getResourceString("ViewSetSelectorPanel.CREATE"), true, panel); //$NON-NLS-1$ propDlg.createUI(); //panel.getViewDefMultiView().getCurrentView().getValidator().addEnableItem(propDlg.getOkBtn()); propDlg.pack(); Rectangle r = propDlg.getBounds(); r.width += 60; r.height += 30; propDlg.setBounds(r); propDlg.setVisible(true); if (!propDlg.isCancelled()) { if (selectedControl instanceof Control) { panel.getDataFromUI(formCell); } else { panel.getDataFromUI((FormCellField) formCell); } DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(formCell); newNode.setUserObject(formCell); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) tree.getSelectionModel() .getSelectionPath().getLastPathComponent(); if (!(parentNode.getUserObject() instanceof FormRow)) { parentNode = (DefaultMutableTreeNode) parentNode.getParent(); } TreePath treePath = tree.getSelectionModel().getSelectionPath(); Object[] path = treePath.getPath(); Object[] newPath = new Object[path.length + (selectedCell == null ? 1 : 0)]; for (int i = 0; i < path.length; i++) { newPath[i] = path[i]; } newPath[newPath.length - 1] = newNode; if (selectedRow.getCells().size() == 0) { selectedRow.getCells().add(formCell); ((DefaultTreeModel) tree.getModel()).insertNodeInto(newNode, parentNode, 0); } else if (position == selectedRow.getCells().size() - 1) { //System.out.println("Adding New Cell at position["+(position+1)+"] number of nodes["+nodeParent.getChildCount()+"] rowCells "+selectedRow.getCells().size()); selectedRow.getCells().add(formCell); ((DefaultTreeModel) tree.getModel()).insertNodeInto(newNode, parentNode, position + 1); } else { //System.out.println("Adding New Cell at position["+position+"] number of nodes["+nodeParent.getChildCount()+"] rowCells "+selectedRow.getCells().size()); selectedRow.getCells().insertElementAt(formCell, position + 1); ((DefaultTreeModel) tree.getModel()).insertNodeInto(newNode, parentNode, position + 1); } //System.out.println("******* ADDING ["+formCell.getIdent()+"]"); //$NON-NLS-1$ //$NON-NLS-2$ idHash.put(formCell.getIdent(), true); final TreePath newTreePath = new TreePath(newPath); SwingUtilities.invokeLater(new Runnable() { public void run() { tree.setSelectionPath(newTreePath); } }); previewPanel.rebuild(false); } } }
From source file:edu.harvard.i2b2.previousquery.ui.QueryPreviousRunsPanel.java
private void populateChildNodes(DefaultMutableTreeNode node) { if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) { QueryMasterData data = (QueryMasterData) node.getUserObject(); try {//w w w . jav a 2 s . c o m String xmlRequest = data.writeContentQueryXML(); String xmlResponse = null; if (System.getProperty("webServiceMethod").equals("SOAP")) { xmlResponse = QueryListNamesClient.sendQueryRequestSOAP(xmlRequest); } else { xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest); } if (xmlResponse.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); } }); return; } try { JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), InstanceResponseType.class); for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) { // change later for working with new xml schema // RunQuery runQuery = //queryInstanceType.getResult().get(i).getRunQuery().get // (0); QueryInstanceData runData = new QueryInstanceData(); runData.visualAttribute("FA"); runData.tooltip("The results of the query run"); runData.id(queryInstanceType.getQueryInstanceId()); // runData.patientRefId(new // Integer(queryInstanceType.getRefId()).toString()); // runData.patientCount(new // Long(queryInstanceType.getCount()).toString()); // XMLGregorianCalendar cldr = // queryInstanceType.getStartDate(); /* * runData.name("Results of "+ * "["+addZero(cldr.getMonth( * ))+"-"+addZero(cldr.getDay())+"-" * +addZero(cldr.getYear())+" * "+addZero(cldr.getHour())+":" * +addZero(cldr.getMinute()) * +":"+addZero(cldr.getSecond())+"]"); */ runData.name("Results of " + data.name().substring(0, data.name().indexOf("["))); runData.queryName(data.name()); data.runs.add(runData); addNode(runData, node); } } catch (Exception e) { e.printStackTrace(); } // jTree1.scrollPathToVisible(new TreePath(node.getPath())); } catch (Exception e) { e.printStackTrace(); } } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) { QueryInstanceData data = (QueryInstanceData) node.getUserObject(); try { String xmlRequest = data.writeContentQueryXML(); String xmlResponse = null; if (System.getProperty("webServiceMethod").equals("SOAP")) { xmlResponse = QueryListNamesClient.sendQueryRequestSOAP(xmlRequest); } else { xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest); } if (xmlResponse.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); } }); return; } JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), ResultResponseType.class); for (QueryResultInstanceType queryResultInstanceType : resultResponseType .getQueryResultInstance()) { String status = queryResultInstanceType.getQueryStatusType().getName(); QueryResultData resultData = new QueryResultData(); if (queryResultInstanceType.getQueryResultType().getName().equalsIgnoreCase("PATIENTSET")) { resultData.visualAttribute("FA"); } else { resultData.visualAttribute("LAO"); } // resultData.queryId(data.queryId()); resultData.patientRefId(queryResultInstanceType.getResultInstanceId());// data.patientRefId()); resultData.patientCount(new Integer(queryResultInstanceType.getSetSize()).toString());// data.patientCount()); String resultname = ""; // if ((resultname = queryResultInstanceType // .getQueryResultType().getDescription()) == null) { resultname = queryResultInstanceType.getQueryResultType().getDescription();// getName(); // } if (status.equalsIgnoreCase("FINISHED")) { if (queryResultInstanceType.getQueryResultType().getName().equals("PATIENTSET")) resultname += " - " + resultData.patientCount() + " Patients"; resultData.name(resultname);// + " - " // + resultData.patientCount() + " Patients"); resultData.tooltip(resultData.patientCount() + " Patients"); } else { resultData.name(resultname);// + " - " + status); resultData.tooltip(status); } resultData.xmlContent(xmlResponse); resultData.queryName(data.queryName()); resultData.type(queryResultInstanceType.getQueryResultType().getName()); addNode(resultData, node); } // jTree1.scrollPathToVisible(new TreePath(node.getPath())); } catch (Exception e) { e.printStackTrace(); } } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) { QueryResultData data = (QueryResultData) node.getUserObject(); if (data.patientCount().equalsIgnoreCase("0")) { return; } int maxNumPatientsToDisplay = Integer.valueOf(System.getProperty("PQMaxPatientsNumber")); if (Integer.valueOf(data.patientCount()) > maxNumPatientsToDisplay) { final JPanel parent = this; result = JOptionPane.showConfirmDialog(parent, "The patient count is greater than maximum configured to be displayed.\n" + "Populating the patient list may affect performance. \n" + "Do you want to continue?", "Please Note ...", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.NO_OPTION) { DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0); QueryData tmpdata = (QueryData) tmpnode.getUserObject(); if (tmpdata.name().equalsIgnoreCase("working ......")) { tmpdata.name("Over maximum number of patient nodes"); treeModel.reload(tmpnode); } return; } } try { String xmlRequest = data.writeContentQueryXML(); String xmlResponse = null; if (System.getProperty("webServiceMethod").equals("SOAP")) { xmlResponse = QueryListNamesClient.sendPDORequestSOAP(xmlRequest, showName()); } else { xmlResponse = QueryListNamesClient.sendPdoRequestREST(xmlRequest); } if (xmlResponse.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); } }); return; } // check response status here ...... // System.out.println("Response: "+xmlResponse); PatientSet patientSet = new PDOResponseMessageFactory().getPatientSetFromResponseXML(xmlResponse); List<PatientType> patients = patientSet.getPatient(); System.out.println("Patient set size: " + patients.size()); for (int i = 0; i < patients.size(); i++) { PatientType patient = patients.get(i); PatientData pData = new PatientData(); pData.patientID(patient.getPatientId().getValue()); pData.setParamData(patient.getParam()); pData.visualAttribute("LAO"); pData.tooltip("Patient"); pData.patientSetID(data.patientRefId()); if (showName()) { pData.name(pData.patientID() + " [" + pData.lastName().substring(0, 1).toUpperCase() + pData.lastName().substring(1, pData.lastName().length()).toLowerCase() + ", " + pData.firstName().substring(0, 1).toUpperCase() + pData.firstName().substring(1, pData.firstName().length()).toLowerCase() + "]");//["+pData.age()+" // y/o // "+pData.gender()+" // "+pData.race()+"]"); } else { pData.name(pData.patientID() + " [" + pData.age() + " y/o " + pData.gender() + " " + pData.race() + "]"); } pData.queryName(data.queryName()); addNode(pData, node); } } catch (Exception e) { e.printStackTrace(); } } // implement for other type of nodes later!!! }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java
/** * //w w w . j a va 2 s.com */ private void createUI() { CellConstraints cc = new CellConstraints(); edaColObjPanel = new EditDeleteAddVertPanel(getEditColObjAL(), getDelColObjAL(), getAddColObjAL()); edaContnrPanel = new EditDeleteAddVertPanel(getEditContainerAL(), getDelContainerAL(), getAddContainerAL()); set(rootContainer, rootColObj); scrollPane = UIHelper.createScrollPane(tree, true); treeRenderer = new ContainerTreeRenderer(null, !isViewMode, isViewMode); treeRenderer.setEditable(true); treeRenderer.setLeafIcon( IconManager.getIcon(CollectionObject.class.getSimpleName(), IconManager.IconSize.Std32)); treeRenderer.setVerticalTextPosition(SwingConstants.CENTER); tree.setCellRenderer(treeRenderer); tree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { mousePressedOnTree(e); } }); } }); colObjAssocIcon = new JLabel( IconManager.getIcon(CollectionObject.class.getSimpleName(), IconManager.IconSize.Std20)); containerAssocIcon = new JLabel( IconManager.getIcon(Container.class.getSimpleName(), IconManager.IconSize.Std20)); colObjIcon = new JLabel( IconManager.getIcon(CollectionObject.class.getSimpleName(), IconManager.IconSize.Std20)); containerIcon = new JLabel( IconManager.getIcon(Container.class.getSimpleName(), IconManager.IconSize.Std20)); searchCOBtn = UIHelper.createIconBtn("Search", IconManager.IconSize.Std20, "", true, null); searchCNBtn = UIHelper.createIconBtn("Search", IconManager.IconSize.Std20, "", true, null); colObjIcon.setEnabled(false); containerIcon.setEnabled(false); containerPanel = new ViewBasedDisplayPanel(null, "ContainerBrief", Container.class.getName(), true, MultiView.NO_OPTIONS); // Right Vertical Control Panel PanelBuilder rpb = null; if (!isViewMode) { rpb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,p,2px,p,10px,p, 20px,p,2px,p,10px,p,f:p:g")); PanelBuilder cnCOLblPB = new PanelBuilder(new FormLayout("p,1px,p", "p")); cnCOLblPB.add(containerAssocIcon, cc.xy(1, 1)); cnCOLblPB.add(colObjAssocIcon, cc.xy(3, 1)); containerAssocIcon.setEnabled(false); colObjAssocIcon.setEnabled(false); int y = 1; rpb.add(containerIcon, cc.xy(1, y)); y += 2; rpb.add(edaContnrPanel, cc.xy(1, y)); y += 2; rpb.add(searchCNBtn, cc.xy(1, y)); y += 2; rpb.addSeparator("", cc.xy(1, y)); y += 2; rpb.add(colObjIcon, cc.xy(1, y)); y += 2; rpb.add(edaColObjPanel, cc.xy(1, y)); y += 2; rpb.add(searchCOBtn, cc.xy(1, y)); y += 2; } // Main Layout PanelBuilder pb = new PanelBuilder(new FormLayout("l:p,8px,f:p:g", "f:p:g,10px,p,2px,p"), this); if (rpb != null) { pb.add(rpb.getPanel(), cc.xy(1, 1)); } pb.add(scrollPane, cc.xy(3, 1)); //pb.addSeparator("Container", cc.xyw(1,3,3)); //pb.add(containerPanel, cc.xyw(1,5,3)); //pb.setDefaultDialogBorder(); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { updateBtnUI(); currContainer = null; currColObj = null; DefaultMutableTreeNode node = getSelectedTreeNode(); if (node != null) { if (node.getUserObject() instanceof Container) { currContainer = (Container) node.getUserObject(); if (containerPanel != null) { containerPanel.getMultiView().setData(currContainer); } } else if (node.getUserObject() instanceof CollectionObject) { currColObj = (CollectionObject) node.getUserObject(); } } } }); GhostGlassPane glassPane = (GhostGlassPane) UIRegistry.get(UIRegistry.GLASSPANE); glassPane.add((GhostActionable) tree); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setShowsRootHandles(true); searchCOBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addColObjToContainer(true, false); } }); searchCNBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addContainer(true); } }); FormViewObj fvo = containerPanel.getMultiView().getCurrentViewAsFormViewObj(); if (fvo != null) { Component comp = fvo.getCompById("nm"); if (comp instanceof ValTextField) { final ValTextField nameTF = fvo.getCompById("nm"); nameTF.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { nameFieldChanged(nameTF.getText()); if (changeListener != null) changeListener.stateChanged(null); } }); final ValComboBox typeCBX = fvo.getCompById("typ"); typeCBX.getComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PickListItemIFace pli = (PickListItemIFace) typeCBX.getComboBox().getSelectedItem(); typeChanged(pli == null ? -1 : Integer.parseInt(pli.getValue())); if (changeListener != null) changeListener.stateChanged(null); } }); } } }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
/** * Adds a new row in the right position (above). *//* www . j ava2s . c o m*/ protected void addRow() { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); FormRow newRow = new FormRow(); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newRow); newNode.setUserObject(newRow); DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getSelectionModel().getSelectionPath() .getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent(); if (parentNode == null) { parentNode = (DefaultMutableTreeNode) model.getRoot(); selectedNode = null; } int position; if (selectedRow == null || parentNode.getUserObject() instanceof String) { formViewDef.getRows().add(newRow); position = formViewDef.getRows().size() - 1; } else { position = formViewDef.getRows().indexOf(selectedRow); formViewDef.getRows().insertElementAt(newRow, (byte) position); } model.insertNodeInto(newNode, parentNode, position); renumberRows(formViewDef.getRows()); updateTreeNodes((DefaultMutableTreeNode) model.getRoot(), model, false); Object[] newPath = new Object[2]; newPath[0] = parentNode; newPath[1] = newNode; final TreePath newTreePath = new TreePath(newPath); SwingUtilities.invokeLater(new Runnable() { public void run() { tree.setSelectionPath(newTreePath); } }); previewPanel.rebuild(false); }
From source file:edu.harvard.i2b2.previousquery.ui.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); setCursor(new Cursor(Cursor.WAIT_CURSOR)); String response = null; if (System.getProperty("webServiceMethod").equals("SOAP")) { // TO DO // response = // QueryListNamesClient.sendQueryRequestSOAP(requestXml); } else { response = QueryListNamesClient.sendQueryRequestREST(requestXml); }//from w w w .j a va 2 s.c o m 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; } 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(); // System.out.println(requestXml); setCursor(new Cursor(Cursor.WAIT_CURSOR)); String response = null; if (System.getProperty("webServiceMethod").equals("SOAP")) { // TO DO // response = // QueryListNamesClient.sendQueryRequestSOAP(requestXml); } else { 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; } 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:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
private void saveParameterOrGene(final DefaultMutableTreeNode node, final Element chromosomeElement) { final Document document = chromosomeElement.getOwnerDocument(); final ParameterOrGene userObj = (ParameterOrGene) node.getUserObject(); final ParameterInfo info = userObj.getInfo(); if (userObj.isGene()) { final GeneInfo geneInfo = userObj.getGeneInfo(); final Element geneElement = document.createElement(GENE); chromosomeElement.appendChild(geneElement); geneElement.setAttribute(WizardSettingsManager.NAME, info.getName()); geneElement.setAttribute(WizardSettingsManager.TYPE, geneInfo.getValueType()); if (GeneInfo.INTERVAL.equals(geneInfo.getValueType())) { geneElement.setAttribute(IS_INTEGER, String.valueOf(geneInfo.isIntegerVals())); geneElement.setAttribute(MIN_VALUE, String.valueOf(geneInfo.getMinValue())); geneElement.setAttribute(MAX_VALUE, String.valueOf(geneInfo.getMaxValue())); } else if (GeneInfo.LIST.equals(geneInfo.getValueType())) { for (final Object value : geneInfo.getValueRange()) { final Element element = document.createElement(LIST_VALUE); geneElement.appendChild(element); element.appendChild(document.createTextNode(String.valueOf(value))); }/*from w ww . j av a2s. com*/ } } else { final Element paramElement = document.createElement(PARAMETER); chromosomeElement.appendChild(paramElement); paramElement.setAttribute(WizardSettingsManager.NAME, info.getName()); paramElement.appendChild(document.createTextNode(String.valueOf(info.getValue()))); } }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java
/** * /*from w ww . java2 s .co m*/ */ private void updateBtnUI() { containerAssocIcon.setEnabled(false); colObjAssocIcon.setEnabled(false); colObjIcon.setEnabled(false); containerIcon.setEnabled(false); if (tree != null) { boolean isNodeSelected = tree.getSelectionCount() > 0; if (isNodeSelected) { TreePath path = tree.getSelectionModel().getSelectionPath(); if (path != null && path.getPathCount() > 0) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path .getPathComponent(path.getPathCount() - 1); if (node != null) { Object dataObj = node.getUserObject(); if (dataObj != null) { boolean isContainer = dataObj instanceof Container; if (isContainer) { int[] selInxs = tree.getSelectionRows(); Container cntr = (Container) dataObj; edaContnrPanel.getEditBtn().setEnabled(selInxs[0] > 0); if (!isViewMode) { edaContnrPanel.getAddBtn().setEnabled(true); edaContnrPanel.getDelBtn().setEnabled(selInxs[0] > 0); } else { edaContnrPanel.getEditBtn().setEnabled(selInxs[0] > -1); } if (!isViewMode) { colObjAssocIcon.setEnabled(true); containerAssocIcon.setEnabled(true); } else { containerAssocIcon.setEnabled(cntr.getCollectionObject() != null); colObjAssocIcon.setEnabled(cntr.getCollectionObject() != null); } colObjIcon.setEnabled(!isViewMode); containerIcon.setEnabled(true); if (!isViewMode) { edaColObjPanel.getAddBtn().setEnabled(true); edaColObjPanel.getDelBtn().setEnabled(false); } edaColObjPanel.getEditBtn().setEnabled(false); searchCOBtn.setEnabled(true); searchCNBtn.setEnabled(true); } else { edaContnrPanel.setEnabled(false); containerIcon.setEnabled(false); colObjIcon.setEnabled(true); edaColObjPanel.getEditBtn().setEnabled(true); if (!isViewMode) { edaColObjPanel.getDelBtn().setEnabled(true); edaColObjPanel.getAddBtn().setEnabled(false); searchCOBtn.setEnabled(false); searchCNBtn.setEnabled(false); } containerAssocIcon.setEnabled(false); colObjAssocIcon.setEnabled(false); } } } } } else { edaColObjPanel.setEnabled(false); edaContnrPanel.setEnabled(false); colObjIcon.setEnabled(false); containerIcon.setEnabled(false); searchCOBtn.setEnabled(false); searchCNBtn.setEnabled(false); containerAssocIcon.setEnabled(false); colObjAssocIcon.setEnabled(false); } } }