List of usage examples for javax.swing.tree TreePath getPathCount
public int getPathCount()
From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateImportDialog.java
private void initComponents() { setBackground(UIConstants.BACKGROUND_COLOR); getContentPane().setBackground(getBackground()); topPanel = new JPanel(); topPanel.setBackground(getBackground()); linkPanel = new JPanel(); linkPanel.setBackground(topPanel.getBackground()); linkLeftPanel = new JPanel(); linkLeftPanel.setBackground(linkPanel.getBackground()); linkLeftSelectAllLabel = new JLabel("<html><u>All</u></html>"); linkLeftSelectAllLabel.setForeground(Color.BLUE); linkLeftSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkLeftSelectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { importTreeTable.getModel().setValueAt(true, row, IMPORT_SELECTED_COLUMN); }//from w w w . j a v a 2 s . c o m } }); linkLeftDeselectAllLabel = new JLabel("<html><u>None</u></html>"); linkLeftDeselectAllLabel.setForeground(Color.BLUE); linkLeftDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkLeftDeselectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { importTreeTable.getModel().setValueAt(false, row, IMPORT_SELECTED_COLUMN); } } }); linkRightPanel = new JPanel(); linkRightPanel.setBackground(linkPanel.getBackground()); linkRightOverwriteAllLabel = new JLabel("<html><u>All</u></html>"); linkRightOverwriteAllLabel.setForeground(Color.BLUE); linkRightOverwriteAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkRightOverwriteAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { TreePath path = importTreeTable.getPathForRow(row); if (path != null) { ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent(); if (node instanceof ImportLibraryTreeTableNode) { ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node; if (libraryNode.getConflicts().getMatchingLibrary() != null) { importTreeTable.getModel().setValueAt(true, row, IMPORT_OVERWRITE_COLUMN); } } else if (node instanceof ImportCodeTemplateTreeTableNode) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node; if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null) { importTreeTable.getModel().setValueAt(true, row, IMPORT_OVERWRITE_COLUMN); } } } } } }); linkRightOverwriteNoneLabel = new JLabel("<html><u>None</u></html>"); linkRightOverwriteNoneLabel.setForeground(Color.BLUE); linkRightOverwriteNoneLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); linkRightOverwriteNoneLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { for (int row = 0; row < importTreeTable.getRowCount(); row++) { TreePath path = importTreeTable.getPathForRow(row); if (path != null) { ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent(); if (node instanceof ImportLibraryTreeTableNode) { ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node; if (libraryNode.getConflicts().getMatchingLibrary() != null) { importTreeTable.getModel().setValueAt(false, row, IMPORT_OVERWRITE_COLUMN); } } else if (node instanceof ImportCodeTemplateTreeTableNode) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node; if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null) { importTreeTable.getModel().setValueAt(false, row, IMPORT_OVERWRITE_COLUMN); } } } } } }); final TableCellEditor templateCellEditor = new NameCellEditor(); importTreeTable = new JXTreeTable() { @Override public boolean isCellEditable(int row, int column) { return (column == IMPORT_OVERWRITE_COLUMN || column == IMPORT_SELECTED_COLUMN || column == IMPORT_NAME_COLUMN); } @Override public TableCellEditor getCellEditor(int row, int column) { if (isHierarchical(column)) { return templateCellEditor; } else { return super.getCellEditor(row, column); } } }; importTreeTable.setLargeModel(true); DefaultTreeTableModel model = new ImportTreeTableModel(); model.setColumnIdentifiers(Arrays.asList(new String[] { "", "Name", "Overwrite", "Conflicts", "Id" })); DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(); model.setRoot(rootNode); importTreeTable.setTreeTableModel(model); Set<String> addedCodeTemplateIds = new HashSet<String>(); if (unassignedCodeTemplates) { ImportTreeTableNode libraryNode = new ImportUnassignedLibraryTreeTableNode("Select a library", ""); CodeTemplateLibrary library = importLibraries.get(0); for (CodeTemplate codeTemplate : library.getCodeTemplates()) { if (!addedCodeTemplateIds.contains(codeTemplate.getId())) { libraryNode .add(new ImportCodeTemplateTreeTableNode(codeTemplate.getName(), codeTemplate.getId())); addedCodeTemplateIds.add(codeTemplate.getId()); importCodeTemplateMap.put(codeTemplate.getId(), codeTemplate); } } rootNode.add(libraryNode); } else { Set<String> addedLibraryIds = new HashSet<String>(); for (CodeTemplateLibrary library : importLibraries) { if (!addedLibraryIds.contains(library.getId())) { ImportTreeTableNode libraryNode = new ImportLibraryTreeTableNode(library.getName(), library.getId()); importLibraryMap.put(library.getId(), library); for (CodeTemplate codeTemplate : library.getCodeTemplates()) { if (!addedCodeTemplateIds.contains(codeTemplate.getId())) { libraryNode.add(new ImportCodeTemplateTreeTableNode(codeTemplate.getName(), codeTemplate.getId())); addedCodeTemplateIds.add(codeTemplate.getId()); importCodeTemplateMap.put(codeTemplate.getId(), codeTemplate); } } rootNode.add(libraryNode); addedLibraryIds.add(library.getId()); } } } importTreeTable.setOpenIcon(null); importTreeTable.setClosedIcon(null); importTreeTable.setLeafIcon(null); importTreeTable.setRootVisible(false); importTreeTable.setDoubleBuffered(true); importTreeTable.setDragEnabled(false); importTreeTable.setRowSelectionAllowed(true); importTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); importTreeTable.setRowHeight(UIConstants.ROW_HEIGHT); importTreeTable.setFocusable(true); importTreeTable.setOpaque(true); importTreeTable.getTableHeader().setReorderingAllowed(false); importTreeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); importTreeTable.setEditable(true); importTreeTable.setSortable(false); importTreeTable.setAutoCreateColumnsFromModel(false); importTreeTable.setShowGrid(true, true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { importTreeTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } importTreeTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { checkSelection(evt); } @Override public void mouseReleased(MouseEvent evt) { checkSelection(evt); } private void checkSelection(MouseEvent evt) { int row = importTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row < 0) { importTreeTable.clearSelection(); } } }); importTreeTable.addTreeWillExpandListener(new TreeWillExpandListener() { @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { } @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { throw new ExpandVetoException(event); } }); importTreeTable.setTreeCellRenderer(new NameCellRenderer()); importTreeTable.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent evt) { if (evt.getColumn() != IMPORT_CONFLICTS_COLUMN) { for (int row = evt.getFirstRow(); row <= evt.getLastRow() && row < importTreeTable.getRowCount(); row++) { TreePath path = importTreeTable.getPathForRow(row); if (path != null) { ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent(); if (path.getPathCount() == 2) { if (node instanceof ImportUnassignedLibraryTreeTableNode) { String libraryName = (String) node.getValueAt(IMPORT_NAME_COLUMN); String libraryId = null; for (CodeTemplateLibrary library : PlatformUI.MIRTH_FRAME.codeTemplatePanel .getCachedCodeTemplateLibraries().values()) { if (library.getName().equals(libraryName)) { libraryId = library.getId(); break; } } node.setValueAt(libraryId, IMPORT_ID_COLUMN); } else if (node instanceof ImportLibraryTreeTableNode) { ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node; libraryNode.setConflicts(getLibraryConflicts(node)); } for (Enumeration<? extends TreeTableNode> codeTemplateNodes = node .children(); codeTemplateNodes.hasMoreElements();) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) codeTemplateNodes .nextElement(); codeTemplateNode.setConflicts(getCodeTemplateConflicts(codeTemplateNode)); } importTreeTable.updateUI(); } else if (path.getPathCount() == 3) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node; codeTemplateNode.setConflicts(getCodeTemplateConflicts(node)); } } } } updateImportButton(); updateErrorsAndWarnings(); } }); importTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { updateImportButton(); updateErrorsAndWarnings(); } } }); importTreeTable.expandAll(); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN).setMinWidth(20); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN).setMaxWidth(20); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN) .setCellRenderer(new ImportSelectedCellRenderer()); importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN) .setCellEditor(new ImportSelectedCellEditor()); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN).setMinWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN).setMaxWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN) .setCellRenderer(new OverwriteCellRenderer()); importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN) .setCellEditor(new OverwriteCellEditor()); importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setMinWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setMaxWidth(60); importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setCellRenderer(new IconCellRenderer()); importTreeTable.getColumnModel().removeColumn(importTreeTable.getColumnModel().getColumn(IMPORT_ID_COLUMN)); importTreeTableScrollPane = new JScrollPane(importTreeTable); importTreeTableScrollPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(0x6E6E6E))); warningsPanel = new JPanel(); warningsPanel.setBackground(getBackground()); warningsPanel.setVisible(false); warningsLabel = new JLabel(UIConstants.ICON_WARNING); warningsTextArea = new JTextArea(); warningsTextArea.setLineWrap(true); warningsTextArea.setWrapStyleWord(true); errorsPanel = new JPanel(); errorsPanel.setBackground(getBackground()); errorsPanel.setVisible(false); errorsLabel = new JLabel(UIConstants.ICON_ERROR); errorsTextArea = new JTextArea(); errorsTextArea.setLineWrap(true); errorsTextArea.setWrapStyleWord(true); separator = new JSeparator(); buttonPanel = new JPanel(); buttonPanel.setBackground(getBackground()); importButton = new JButton("Import"); importButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { boolean warnings = false; for (Enumeration<? extends TreeTableNode> libraryNodes = ((TreeTableNode) importTreeTable .getTreeTableModel().getRoot()).children(); libraryNodes.hasMoreElements();) { for (Enumeration<? extends TreeTableNode> codeTemplateNodes = libraryNodes.nextElement() .children(); codeTemplateNodes.hasMoreElements();) { ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) codeTemplateNodes .nextElement(); if ((boolean) codeTemplateNode.getValueAt(IMPORT_SELECTED_COLUMN)) { CodeTemplateConflicts conflicts = codeTemplateNode.getConflicts(); if (conflicts.getMatchingCodeTemplate() != null) { warnings = true; break; } } } if (warnings) { break; } } if (!warnings || PlatformUI.MIRTH_FRAME.alertOption(CodeTemplateImportDialog.this, "Some selected rows have warnings. Are you sure you wish to continue?")) { save(); dispose(); } } catch (Exception e) { PlatformUI.MIRTH_FRAME.alertThrowable(CodeTemplateImportDialog.this, e, "Unable to import: " + e.getMessage()); } } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (confirmClose()) { dispose(); } } }); updateImportButton(); }
From source file:org.kepler.gui.popups.LibraryPopupListener.java
/** Determine if this object is contained within a KAR * by checking all of the parent objects to see if they * are a KAREntityLibrary. do not check the object itself *///from ww w. ja v a 2s. c o m private boolean _isPathInsideKAR(TreePath selPath) { for (int i = (selPath.getPathCount() - 2); i >= 0; i--) { if (selPath.getPathComponent(i) instanceof KAREntityLibrary) { return true; } } return false; }
From source file:org.kepler.gui.popups.OutlinePopupListener.java
/** * Description of the Method/* w ww . j av a 2 s .co m*/ * *@param e * Description of the Parameter */ private void maybeShowPopup(MouseEvent e) { if (isDebugging) log.debug("maybeShowPopup(" + e.toString() + ")"); if (e.isPopupTrigger() || _trigger) { _trigger = false; TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY()); if (isDebugging) log.debug(selPath.toString()); if ((selPath != null)) { // determine if this object is contained within a KAR // by checking all of the parent objects to see // if they are a KAREntityLibrary // do not check the object itself boolean inKAR = false; Object ob = null; for (int i = (selPath.getPathCount() - 2); i >= 0; i--) { ob = selPath.getPathComponent(i); if (ob instanceof KAREntityLibrary) { inKAR = true; break; } } ob = selPath.getLastPathComponent(); if (isDebugging) log.debug(ob.getClass().getName()); if (!inKAR) { handlePopupOutsideKar(selPath, e); } } } }
From source file:org.kepler.gui.ResultTreeRebuilder.java
/** * Description of the Method/* w w w . j av a 2s . c o m*/ * *@exception IllegalActionException * Description of the Exception */ private void buildResultTree(EntityLibrary newRoot) throws IllegalActionException { if (isDebugging) log.debug("buildResultTree()"); // iterate over each treepath in results for (int i = 0; i < results.size(); i++) { try { TreePath currentPath = results.getTreePath(i); if (isDebugging) log.debug(currentPath); EntityLibrary treeCurrent = newRoot; for (int j = 1; j < currentPath.getPathCount(); j++) { NamedObj pathCurrent = (NamedObj) currentPath.getPathComponent(j); if (pathCurrent instanceof EntityLibrary) { List<EntityLibrary> children = treeCurrent.entityList(EntityLibrary.class); boolean alreadyThere = false; for (EntityLibrary child : children) { if (isDebugging) log.debug(child.getName()); if (child.getName().equals(pathCurrent.getName())) { // this EntityLibrary is already there treeCurrent = child; alreadyThere = true; break; } } if (!alreadyThere) { // create it EntityLibrary newEntity = copyEntityLibrary((EntityLibrary) pathCurrent); setContainer(treeCurrent, newEntity); treeCurrent = newEntity; } } else { List<NamedObj> children = treeCurrent.entityList(NamedObj.class); boolean alreadyThere = false; for (NamedObj child : children) { if (child.getName().equals(pathCurrent.getName())) { // this NamedObj is already there alreadyThere = true; break; } } if (!alreadyThere) { // create it NamedObj newEntity = cloneEntity((NamedObj) pathCurrent); setContainer(treeCurrent, newEntity); // Leaf node, all done break; } } } } catch (IllegalActionException iae) { throw new IllegalActionException("cannot build search result tree: " + iae); } catch (NameDuplicationException nde) { log.error("EXCEPTION CAUGHT: " + nde.getMessage()); } catch (Exception e) { log.error("EXCEPTION CAUGHT: " + e.getMessage()); } } // end for loop }
From source file:org.trianacode.gui.hci.ApplicationFrame.java
public void treeNodesInserted(TreeModelEvent event) { TreePath path = event.getTreePath(); if (path.getPathCount() >= 2) { toolboxTree.scrollPathToVisible(event.getTreePath()); toolboxTree.getModel().removeTreeModelListener(this); }/*from w w w.j av a2 s . c o m*/ }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
/** * @return ArrayList<String> with selected items in the tree *///from w w w . jav a 2s. co m private ArrayList<String> getSelectedLocalFiles() { ArrayList<String> files = new ArrayList<String>(); TreePath path = jTreeResults.getSelectionPath(); // Tree Root is not permited if (path == null || path.getPathCount() < 2) { return null; } jTreeResults.expandPath(path); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); // recieves all childs ArrayList<DefaultMutableTreeNode> childs = getLocalLeafs(node, path); Iterator<DefaultMutableTreeNode> it = childs.iterator(); // converts TreeNodes to filePaths while (it.hasNext()) { Object obj = it.next().getUserObject(); if (SearchResult.class.isInstance(obj)) { files.add(obj.toString()); } } } return files; }
From source file:ui.panel.UILicenseAdd.java
private JPanel createPnlFeature() { JPanel panel = p.createPanel(Layouts.gridbag); GridBagConstraints g = new GridBagConstraints(); lblSelectFeature = l.createLabel("Select Features", SwingConstants.LEFT); g.gridx = 0;//from w w w.j a va2 s.co m g.gridy = 0; g.gridwidth = 2; g.insets = new Insets(5, 5, 5, 5); panel.add(lblSelectFeature, g); lblServiceApi = l.createLabel("Service APIs Used", SwingConstants.LEFT); g.gridx = 4; g.gridy = 0; g.gridwidth = 2; g.insets = new Insets(5, 5, 5, 5); panel.add(lblServiceApi, g); getFeaturesData(); DefaultMutableTreeNode root = new MyDataNode("Features", "Features"); for (String key : Data.featureList.keySet()) { try { DefaultMutableTreeNode element = new MyDataNode(key, Data.fieldNames.get(key)); JSONArray features = Data.featureList.get(key); ArrayList<DefaultMutableTreeNode> arrayFeatureCheckBox = new ArrayList<DefaultMutableTreeNode>(); for (int i = 0; i < features.length(); i++) { JSONObject feature = features.getJSONObject(i); DefaultMutableTreeNode featureElement = new MyDataNode((String) feature.get("name"), Data.fieldNames.get(feature.get("name"))); element.add(featureElement); arrayFeatureCheckBox.add(featureElement); } root.add(element); } catch (JSONException e) { e.printStackTrace(); } } tree = new JTree(root); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath path = tree.getSelectionModel().getSelectionPath(); model.removeAllElements(); String item = tree.getSelectionModel().getSelectionPath().getLastPathComponent().toString(); MyDataNode node = (MyDataNode) tree.getSelectionModel().getSelectionPath().getLastPathComponent(); String selected = node.getValue(); servicesList = new HashMap<String, String>(); try { if (selected.equalsIgnoreCase("Features")) { for (String key : Data.featureList.keySet()) { JSONArray featureArray = Data.featureList.get(key); for (int i = 0; i < featureArray.length(); i++) { JSONArray servicesArray = featureArray.getJSONObject(i).getJSONArray("services"); for (int x = 0; x < servicesArray.length(); x++) { servicesList.put(Integer.toString(servicesArray.getJSONObject(x).getInt("id")), servicesArray.getJSONObject(x).getString("name")); } } } } else if (path.getPathCount() == 2) { for (String key : Data.featureList.keySet()) { if (key.equals(selected)) { JSONArray featureArray = Data.featureList.get(key); for (int i = 0; i < featureArray.length(); i++) { JSONArray servicesArray = featureArray.getJSONObject(i) .getJSONArray("services"); for (int x = 0; x < servicesArray.length(); x++) { servicesList.put( Integer.toString(servicesArray.getJSONObject(x).getInt("id")), servicesArray.getJSONObject(x).getString("name")); } } } else { continue; } } } else { MyDataNode nodePath = (MyDataNode) path.getPathComponent(1); for (String key : Data.featureList.keySet()) { if (key.equals(nodePath.getValue())) { JSONArray featureArray = Data.featureList.get(key); for (int i = 0; i < featureArray.length(); i++) { System.out.println( featureArray.getJSONObject(i).getString("name") + ":" + selected); if (featureArray.getJSONObject(i).getString("name").equals(selected)) { JSONArray servicesArray = featureArray.getJSONObject(i) .getJSONArray("services"); System.out.println(servicesArray); for (int x = 0; x < servicesArray.length(); x++) { servicesList.put( Integer.toString(servicesArray.getJSONObject(x).getInt("id")), servicesArray.getJSONObject(x).getString("name")); } } else { continue; } } } else { continue; } } } } catch (JSONException ex) { ex.printStackTrace(); } for (String serviceKey : servicesList.keySet()) { model.addElement(servicesList.get(serviceKey)); } listServiceUsed.setModel(model); } }); checkTreeManager = new CheckTreeManager(tree); spTreeCheckBox = new JScrollPane(tree); spTreeCheckBox.setPreferredSize(new Dimension(300, 300)); g.gridx = 0; g.gridy = 1; g.gridwidth = 3; g.anchor = g.LINE_START; g.insets = new Insets(5, 5, 5, 5); panel.add(spTreeCheckBox, g); model = new DefaultListModel<>(); model.addElement(""); listServiceUsed = new JList<String>(model); spList = new JScrollPane(listServiceUsed); spList.setPreferredSize(new Dimension(300, 300)); g.gridx = 4; g.gridy = 1; g.gridwidth = 3; g.anchor = g.LINE_START; panel.add(spList, g); return panel; }
From source file:ui.panel.UILicenseAdd.java
public JPanel createButtonPanel() { JPanel panel = p.createPanel(Layouts.flow); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); btnSubmit = b.createButton("Submit"); btnCancel = b.createButton("Cancel"); btnSubmit.addActionListener(new ActionListener() { @Override/* w w w .ja va 2 s .c o m*/ public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { TreePath[] path = checkTreeManager.getSelectionModel().getSelectionPaths(); ArrayList<String> featureL = new ArrayList<String>(); String[] features = new String[] {}; for (TreePath tp : path) { if (tp.getLastPathComponent().toString().equals("Features")) { Object rootNode = tree.getModel().getRoot(); int parentCount = tree.getModel().getChildCount(rootNode); for (int i = 0; i < parentCount; i++) { Object parentNode = tree.getModel().getChild(rootNode, i); int childrenCount = tree.getModel().getChildCount(parentNode); for (int x = 0; x < childrenCount; x++) { MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x); featureL.add(node.getValue()); } } } else if (tp.getPathCount() == 2) { Object rootNode = tree.getModel().getRoot(); int parentCount = tree.getModel().getChildCount(rootNode); for (int i = 0; i < parentCount; i++) { Object parentNode = tree.getModel().getChild(rootNode, i); if (parentNode.toString().equals(tp.getLastPathComponent().toString())) { int childrenCount = tree.getModel().getChildCount(parentNode); for (int x = 0; x < childrenCount; x++) { MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x); featureL.add(node.getValue()); } } } } else if (tp.getPathCount() == 3) { MyDataNode node = (MyDataNode) tp.getLastPathComponent(); featureL.add(node.getValue()); } } features = featureL.toArray(features); String duration = spnValidity.getValue().toString(); if (cbPerpetual.isSelected()) { duration = "-1"; } String storage = spnCloud.getValue().toString(); String maxVCA = spnConcurrentVCA.getValue().toString(); String response = apiCall.addNodeLicense(Data.targetURL, Data.sessionKey, Data.bucketID, features, duration, storage, maxVCA); try { JSONObject responseObject = new JSONObject(response); if (responseObject.get("result").equals("ok")) { Data.mainFrame.uiLicenseDetail.getLicenseData(); Data.mainFrame.showPanel("license"); } } catch (JSONException e1) { e1.printStackTrace(); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Retrieving License..."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.showPanel("license"); } }); panel.add(btnSubmit); panel.add(btnCancel); return panel; }