List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:edu.harvard.i2b2.query.ui.GroupPanel.java
public void treeExpanded(TreeExpansionEvent event) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent(); QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject(); jTree1.scrollPathToVisible(new TreePath(node)); // System.out.println("Node expanded: "+data.dimcode()); if (data.visualAttribute().equals("L")) { // return; }//from w w w . java 2 s . co m if (data.visualAttribute().equals("FA")) { data.visualAttribute("FAO"); } else if (data.visualAttribute().equals("CA")) { data.visualAttribute("CAO"); } // check to see if child is a placeholder ('working...') // if so, make Web Service call to update children of node if (node.getChildCount() == 1) { final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0); if (((QueryConceptTreeNodeData) node1.getUserObject()).name().equalsIgnoreCase("working ......")) { final DefaultMutableTreeNode anode = node; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { populateChildNodes(anode); } }); } } else { for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0); QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject(); if (adata.visualAttribute().equals("FAO")) { // adata.visualAttribute("FA"); } else if (adata.visualAttribute().equals("CAO")) { // adata.visualAttribute("CA"); } } } }
From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java
public void treeExpanded(TreeExpansionEvent event) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent(); QueryData data = (QueryData) node.getUserObject(); if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) { QueryResultData rdata = (QueryResultData) node.getUserObject(); if (rdata.patientCount().equalsIgnoreCase("0")) { return; /*/*from w w w .java 2 s .c om*/ * final JPanel parent = this; * java.awt.EventQueue.invokeLater(new Runnable() { public void * run() { JOptionPane.showMessageDialog(parent, "There's no * patient in this set.", "Message", * JOptionPane.INFORMATION_MESSAGE); } }); */ } } jTree1.scrollPathToVisible(new TreePath(node)); System.out.println("Node expanded: " + data.name()); if (data.visualAttribute().equals("FA")) { data.visualAttribute("FAO"); } else if (data.visualAttribute().equals("CA")) { data.visualAttribute("CAO"); } // check to see if child is a placeholder ('working...') // if so, make Web Service call to update children of node if (node.getChildCount() == 1) { final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0); if (((QueryData) node1.getUserObject()).visualAttribute().equals("LAO") && ((QueryData) node1.getUserObject()).name().equals("working ......")) { final DefaultMutableTreeNode anode = node; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { populateChildNodes(anode); } }); } } else { for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0); QueryData adata = (QueryData) anode.getUserObject(); if (adata.visualAttribute().equals("FAO")) { adata.visualAttribute("FA"); } else if (adata.visualAttribute().equals("CAO")) { adata.visualAttribute("CA"); } } } }
From source file:GUI.MainWindow.java
private void doDelete() { DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot(); TreePath[] paths = VulnTree.getSelectionPaths(); if (paths == null) { return;/* w w w . j a v a 2s . c om*/ } for (int i = 0; i < paths.length; i++) { TreePath path = paths[i]; DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (i == 0) { // This is the first delete operation DefaultMutableTreeNode previous = (DefaultMutableTreeNode) node.getPreviousSibling(); // Consider saving deleted vulns into a scratchpad file TODO //System.out.println("previous:" + previous); // If it is null here we have no nodes above it, we get the next sibling below if (previous == null) { previous = (DefaultMutableTreeNode) node.getNextSibling(); } // If it is still null here there are no nodes in the tree. Point to the root. Avoids NullPointerException if (previous == null) { previous = root; } TreePath p = new TreePath(previous.getPath()); VulnTree.setSelectionPath(p); } if (node.getParent() != null) { dtm.removeNodeFromParent(node); } } if (root.getChildCount() == 0) { clearGUI(); } }
From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java
private void libraryComboBoxActionPerformed() { if (!libraryComboBoxAdjusting.get()) { setSaveEnabled(true);//from w ww.ja va 2 s. co m TreePath selectedPath = templateTreeTable.getTreeSelectionModel().getSelectionPath(); if (selectedPath != null) { TreeTableNode selectedNode = (TreeTableNode) selectedPath.getLastPathComponent(); if (selectedNode instanceof CodeTemplateTreeTableNode) { CodeTemplateTreeTableNode codeTemplateNode = (CodeTemplateTreeTableNode) selectedNode; CodeTemplateTreeTableModel model = (CodeTemplateTreeTableModel) templateTreeTable .getTreeTableModel(); CodeTemplateLibraryTreeTableNode currentParent = (CodeTemplateLibraryTreeTableNode) codeTemplateNode .getParent(); String libraryName = (String) templateLibraryComboBox.getSelectedItem(); CodeTemplateLibraryTreeTableNode libraryNode = null; for (Enumeration<? extends MutableTreeTableNode> libraries = ((MutableTreeTableNode) model .getRoot()).children(); libraries.hasMoreElements();) { CodeTemplateLibraryTreeTableNode library = (CodeTemplateLibraryTreeTableNode) libraries .nextElement(); if (library.getLibrary().getName().equals(libraryName)) { libraryNode = library; break; } } CodeTemplateLibraryTreeTableNode fullLibraryNode = null; for (Enumeration<? extends MutableTreeTableNode> libraries = ((MutableTreeTableNode) fullModel .getRoot()).children(); libraries.hasMoreElements();) { CodeTemplateLibraryTreeTableNode library = (CodeTemplateLibraryTreeTableNode) libraries .nextElement(); if (library.getLibrary().getName().equals(libraryName)) { fullLibraryNode = library; break; } } if (!currentParent.getLibraryId().equals(fullLibraryNode.getLibraryId())) { updateCurrentNode(); updateCurrentNode.set(false); model.removeNodeFromParent(codeTemplateNode); if (libraryNode != null) { model.insertNodeInto(codeTemplateNode, libraryNode); selectTemplatePath(new TreePath(model.getPathToRoot(codeTemplateNode))); } else { selectTemplatePath(new TreePath(model.getPathToRoot(model.getRoot()))); } if (model.getRoot() != fullModel.getRoot()) { AbstractSortableTreeTableNode fullCodeTemplateNode = findFullNode(codeTemplateNode); fullModel.removeNodeFromParent(fullCodeTemplateNode); fullModel.insertNodeInto(fullCodeTemplateNode, fullLibraryNode); } updateCurrentNode.set(true); } } } } }
From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java
public void treeExpanded(TreeExpansionEvent event) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent(); QueryData data = (QueryData) node.getUserObject(); /*if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase( "QueryResultData")) {/*www . j a v a 2s. c om*/ QueryResultData rdata = (QueryResultData) node.getUserObject(); if (rdata.patientCount().equalsIgnoreCase("0")) { return; /* * final JPanel parent = this; * java.awt.EventQueue.invokeLater(new Runnable() { public void * run() { JOptionPane.showMessageDialog(parent, "There's no * patient in this set.", "Message", * JOptionPane.INFORMATION_MESSAGE); } }); */ //} //}*/ jTree1.scrollPathToVisible(new TreePath(node)); System.out.println("Node expanded: " + data.name()); if (data.visualAttribute().equals("FA")) { data.visualAttribute("FAO"); } else if (data.visualAttribute().equals("CA")) { data.visualAttribute("CAO"); } // check to see if child is a placeholder ('working...') // if so, make Web Service call to update children of node if (node.getChildCount() == 1) { final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0); if (((QueryData) node1.getUserObject()).visualAttribute().equals("LAO") && ((QueryData) node1.getUserObject()).name().equals("working ......")) { final DefaultMutableTreeNode anode = node; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { populateChildNodes(anode); } }); } } else { for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0); QueryData adata = (QueryData) anode.getUserObject(); if (adata.visualAttribute().equals("FAO")) { adata.visualAttribute("FA"); } else if (adata.visualAttribute().equals("CAO")) { adata.visualAttribute("CA"); } } } }
From source file:com.mirth.connect.client.ui.ChannelPanel.java
private void initComponents() { splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); splitPane.setOneTouchExpandable(true); topPanel = new JPanel(); List<String> columns = new ArrayList<String>(); for (ChannelColumnPlugin plugin : LoadedExtensions.getInstance().getChannelColumnPlugins().values()) { if (plugin.isDisplayFirst()) { columns.add(plugin.getColumnHeader()); }//from w ww.ja v a 2 s. co m } columns.addAll(Arrays.asList(DEFAULT_COLUMNS)); for (ChannelColumnPlugin plugin : LoadedExtensions.getInstance().getChannelColumnPlugins().values()) { if (!plugin.isDisplayFirst()) { columns.add(plugin.getColumnHeader()); } } channelTable = new MirthTreeTable("channelPanel", new LinkedHashSet<String>(columns)); channelTable.setColumnFactory(new ChannelTableColumnFactory()); ChannelTreeTableModel model = new ChannelTreeTableModel(); model.setColumnIdentifiers(columns); model.setNodeFactory(new DefaultChannelTableNodeFactory()); channelTable.setTreeTableModel(model); channelTable.setDoubleBuffered(true); channelTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); channelTable.getTreeSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); channelTable.setHorizontalScrollEnabled(true); channelTable.packTable(UIConstants.COL_MARGIN); channelTable.setRowHeight(UIConstants.ROW_HEIGHT); channelTable.setOpaque(true); channelTable.setRowSelectionAllowed(true); channelTable.setSortable(true); channelTable.putClientProperty("JTree.lineStyle", "Horizontal"); channelTable.setAutoCreateColumnsFromModel(false); channelTable.setShowGrid(true, true); channelTable.restoreColumnPreferences(); channelTable.setMirthColumnControlEnabled(true); channelTable.setDragEnabled(true); channelTable.setDropMode(DropMode.ON); channelTable.setTransferHandler(new ChannelTableTransferHandler() { @Override public boolean canImport(TransferSupport support) { // Don't allow files to be imported when the save task is enabled if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && isSaveEnabled()) { return false; } return super.canImport(support); } @Override public void importFile(final File file, final boolean showAlerts) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { String fileString = StringUtils.trim(parent.readFileToString(file)); try { // If the table is in channel view, don't allow groups to be imported ChannelGroup group = ObjectXMLSerializer.getInstance().deserialize(fileString, ChannelGroup.class); if (group != null && !((ChannelTreeTableModel) channelTable.getTreeTableModel()) .isGroupModeEnabled()) { return; } } catch (Exception e) { } if (showAlerts && !parent.promptObjectMigration(fileString, "channel or group")) { return; } try { importChannel( ObjectXMLSerializer.getInstance().deserialize(fileString, Channel.class), showAlerts); } catch (Exception e) { try { importGroup(ObjectXMLSerializer.getInstance().deserialize(fileString, ChannelGroup.class), showAlerts, !showAlerts); } catch (Exception e2) { if (showAlerts) { parent.alertThrowable(parent, e, "Invalid channel or group file:\n" + e.getMessage()); } } } } }); } catch (Exception e) { e.printStackTrace(); } } @Override public boolean canMoveChannels(List<Channel> channels, int row) { if (row >= 0) { TreePath path = channelTable.getPathForRow(row); if (path != null) { AbstractChannelTableNode node = (AbstractChannelTableNode) path.getLastPathComponent(); if (node.isGroupNode()) { Set<String> currentChannelIds = new HashSet<String>(); for (Enumeration<? extends MutableTreeTableNode> channelNodes = node .children(); channelNodes.hasMoreElements();) { currentChannelIds.add(((AbstractChannelTableNode) channelNodes.nextElement()) .getChannelStatus().getChannel().getId()); } for (Iterator<Channel> it = channels.iterator(); it.hasNext();) { if (currentChannelIds.contains(it.next().getId())) { it.remove(); } } return !channels.isEmpty(); } } } return false; } @Override public boolean moveChannels(List<Channel> channels, int row) { if (row >= 0) { TreePath path = channelTable.getPathForRow(row); if (path != null) { AbstractChannelTableNode node = (AbstractChannelTableNode) path.getLastPathComponent(); if (node.isGroupNode()) { Set<String> currentChannelIds = new HashSet<String>(); for (Enumeration<? extends MutableTreeTableNode> channelNodes = node .children(); channelNodes.hasMoreElements();) { currentChannelIds.add(((AbstractChannelTableNode) channelNodes.nextElement()) .getChannelStatus().getChannel().getId()); } for (Iterator<Channel> it = channels.iterator(); it.hasNext();) { if (currentChannelIds.contains(it.next().getId())) { it.remove(); } } if (!channels.isEmpty()) { ListSelectionListener[] listeners = ((DefaultListSelectionModel) channelTable .getSelectionModel()).getListSelectionListeners(); for (ListSelectionListener listener : listeners) { channelTable.getSelectionModel().removeListSelectionListener(listener); } try { ChannelTreeTableModel model = (ChannelTreeTableModel) channelTable .getTreeTableModel(); Set<String> channelIds = new HashSet<String>(); for (Channel channel : channels) { model.addChannelToGroup(node, channel.getId()); channelIds.add(channel.getId()); } List<TreePath> selectionPaths = new ArrayList<TreePath>(); for (Enumeration<? extends MutableTreeTableNode> channelNodes = node .children(); channelNodes.hasMoreElements();) { AbstractChannelTableNode channelNode = (AbstractChannelTableNode) channelNodes .nextElement(); if (channelIds .contains(channelNode.getChannelStatus().getChannel().getId())) { selectionPaths.add(new TreePath( new Object[] { model.getRoot(), node, channelNode })); } } parent.setSaveEnabled(true); channelTable.expandPath(new TreePath( new Object[] { channelTable.getTreeTableModel().getRoot(), node })); channelTable.getTreeSelectionModel().setSelectionPaths( selectionPaths.toArray(new TreePath[selectionPaths.size()])); return true; } finally { for (ListSelectionListener listener : listeners) { channelTable.getSelectionModel().addListSelectionListener(listener); } } } } } } return false; } }); channelTable.setTreeCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); TreePath path = channelTable.getPathForRow(row); if (path != null && ((AbstractChannelTableNode) path.getLastPathComponent()).isGroupNode()) { setIcon(UIConstants.ICON_GROUP); } return label; } }); channelTable.setLeafIcon(UIConstants.ICON_CHANNEL); channelTable.setOpenIcon(UIConstants.ICON_GROUP); channelTable.setClosedIcon(UIConstants.ICON_GROUP); channelTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { channelListSelected(evt); } }); // listen for trigger button and double click to edit channel. channelTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { checkSelectionAndPopupMenu(evt); } @Override public void mouseReleased(MouseEvent evt) { checkSelectionAndPopupMenu(evt); } @Override public void mouseClicked(MouseEvent evt) { int row = channelTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row == -1) { return; } if (evt.getClickCount() >= 2 && channelTable.getSelectedRowCount() == 1 && channelTable.getSelectedRow() == row) { AbstractChannelTableNode node = (AbstractChannelTableNode) channelTable.getPathForRow(row) .getLastPathComponent(); if (node.isGroupNode()) { doEditGroupDetails(); } else { doEditChannel(); } } } }); // Key Listener trigger for DEL channelTable.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_DELETE) { if (channelTable.getSelectedModelRows().length == 0) { return; } boolean allGroups = true; boolean allChannels = true; for (int row : channelTable.getSelectedModelRows()) { AbstractChannelTableNode node = (AbstractChannelTableNode) channelTable.getPathForRow(row) .getLastPathComponent(); if (node.isGroupNode()) { allChannels = false; } else { allGroups = false; } } if (allChannels) { doDeleteChannel(); } else if (allGroups) { doDeleteGroup(); } } } @Override public void keyReleased(KeyEvent evt) { } @Override public void keyTyped(KeyEvent evt) { } }); // MIRTH-2301 // Since we are using addHighlighter here instead of using setHighlighters, we need to remove the old ones first. channelTable.setHighlighters(); // Set highlighter. if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); channelTable.addHighlighter(highlighter); } HighlightPredicate revisionDeltaHighlighterPredicate = new HighlightPredicate() { @Override public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { if (adapter.column == channelTable.convertColumnIndexToView( channelTable.getColumnExt(DEPLOYED_REVISION_DELTA_COLUMN_NAME).getModelIndex())) { if (channelTable.getValueAt(adapter.row, adapter.column) != null && ((Integer) channelTable.getValueAt(adapter.row, adapter.column)).intValue() > 0) { return true; } if (channelStatuses != null) { String channelId = (String) channelTable.getModel() .getValueAt(channelTable.convertRowIndexToModel(adapter.row), ID_COLUMN_NUMBER); ChannelStatus status = channelStatuses.get(channelId); if (status != null && status.isCodeTemplatesChanged()) { return true; } } } return false; } }; channelTable.addHighlighter(new ColorHighlighter(revisionDeltaHighlighterPredicate, new Color(255, 204, 0), Color.BLACK, new Color(255, 204, 0), Color.BLACK)); HighlightPredicate lastDeployedHighlighterPredicate = new HighlightPredicate() { @Override public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { if (adapter.column == channelTable.convertColumnIndexToView( channelTable.getColumnExt(LAST_DEPLOYED_COLUMN_NAME).getModelIndex())) { Calendar checkAfter = Calendar.getInstance(); checkAfter.add(Calendar.MINUTE, -2); if (channelTable.getValueAt(adapter.row, adapter.column) != null && ((Calendar) channelTable.getValueAt(adapter.row, adapter.column)) .after(checkAfter)) { return true; } } return false; } }; channelTable.addHighlighter(new ColorHighlighter(lastDeployedHighlighterPredicate, new Color(240, 230, 140), Color.BLACK, new Color(240, 230, 140), Color.BLACK)); channelScrollPane = new JScrollPane(channelTable); channelScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); filterPanel = new JPanel(); filterPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(164, 164, 164))); tagsFilterButton = new IconButton(); tagsFilterButton .setIcon(new ImageIcon(getClass().getResource("/com/mirth/connect/client/ui/images/wrench.png"))); tagsFilterButton.setToolTipText("Show Channel Filter"); tagsFilterButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { tagsFilterButtonActionPerformed(); } }); tagsLabel = new JLabel(); ButtonGroup tableModeButtonGroup = new ButtonGroup(); tableModeGroupsButton = new IconToggleButton(UIConstants.ICON_GROUP); tableModeGroupsButton.setToolTipText("Groups"); tableModeGroupsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (!switchTableMode(true)) { tableModeChannelsButton.setSelected(true); } } }); tableModeButtonGroup.add(tableModeGroupsButton); tableModeChannelsButton = new IconToggleButton(UIConstants.ICON_CHANNEL); tableModeChannelsButton.setToolTipText("Channels"); tableModeChannelsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (!switchTableMode(false)) { tableModeGroupsButton.setSelected(true); } } }); tableModeButtonGroup.add(tableModeChannelsButton); tabPane = new JTabbedPane(); splitPane.setTopComponent(topPanel); splitPane.setBottomComponent(tabPane); }
From source file:com.mirth.connect.client.ui.ChannelPanel.java
private TableState getCurrentTableState() { List<String> selectedIds = new ArrayList<String>(); List<String> expandedGroupIds = null; int[] selectedRows = channelTable.getSelectedModelRows(); for (int i = 0; i < selectedRows.length; i++) { AbstractChannelTableNode node = (AbstractChannelTableNode) channelTable.getPathForRow(selectedRows[i]) .getLastPathComponent(); if (node.isGroupNode()) { selectedIds.add(node.getGroupStatus().getGroup().getId()); } else {/*from w w w .j a v a2 s.c om*/ selectedIds.add(node.getChannelStatus().getChannel().getId()); } } ChannelTreeTableModel model = (ChannelTreeTableModel) channelTable.getTreeTableModel(); if (model.isGroupModeEnabled()) { MutableTreeTableNode root = (MutableTreeTableNode) model.getRoot(); if (root != null && root.getChildCount() > 0) { expandedGroupIds = new ArrayList<String>(); for (Enumeration<? extends MutableTreeTableNode> groupNodes = root.children(); groupNodes .hasMoreElements();) { AbstractChannelTableNode groupNode = (AbstractChannelTableNode) groupNodes.nextElement(); if (channelTable.isExpanded(new TreePath(new Object[] { root, groupNode })) || groupNode.getChildCount() == 0) { expandedGroupIds.add(groupNode.getGroupStatus().getGroup().getId()); } } } } return new TableState(selectedIds, expandedGroupIds); }
From source file:com.mirth.connect.client.ui.ChannelPanel.java
private void restoreTableState(TableState tableState) { ChannelTreeTableModel model = (ChannelTreeTableModel) channelTable.getTreeTableModel(); MutableTreeTableNode root = (MutableTreeTableNode) model.getRoot(); if (model.isGroupModeEnabled()) { if (tableState.getExpandedGroupIds() != null && root != null) { channelTable.collapseAll();/*w w w . j a v a2 s . c o m*/ for (Enumeration<? extends MutableTreeTableNode> groupNodes = root.children(); groupNodes .hasMoreElements();) { AbstractChannelTableNode groupNode = (AbstractChannelTableNode) groupNodes.nextElement(); if (tableState.getExpandedGroupIds().contains(groupNode.getGroupStatus().getGroup().getId())) { channelTable.expandPath(new TreePath(new Object[] { root, groupNode })); } } } else { channelTable.expandAll(); } } final List<TreePath> selectionPaths = new ArrayList<TreePath>(); for (Enumeration<? extends MutableTreeTableNode> children = root.children(); children.hasMoreElements();) { AbstractChannelTableNode child = (AbstractChannelTableNode) children.nextElement(); if (child.isGroupNode() && tableState.getSelectedIds().contains(child.getGroupStatus().getGroup().getId()) || !child.isGroupNode() && tableState.getSelectedIds() .contains(child.getChannelStatus().getChannel().getId())) { TreePath path = new TreePath(new Object[] { root, child }); channelTable.getTreeSelectionModel().addSelectionPath(path); selectionPaths.add(path); } if (model.isGroupModeEnabled()) { for (Enumeration<? extends MutableTreeTableNode> channelNodes = child.children(); channelNodes .hasMoreElements();) { AbstractChannelTableNode channelNode = (AbstractChannelTableNode) channelNodes.nextElement(); if (tableState.getSelectedIds().contains(channelNode.getChannelStatus().getChannel().getId())) { TreePath path = new TreePath(new Object[] { root, child, channelNode }); channelTable.getTreeSelectionModel().addSelectionPath(path); selectionPaths.add(path); } } } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { for (TreePath path : selectionPaths) { channelTable.getTreeSelectionModel().addSelectionPath(path); } } }); }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private void modifySubmodelParameterInfo(final SubmodelInfo sInfo) { ClassElement aClassElement = (ClassElement) submodelTypeBox.getSelectedItem(); final Class<?> newActualType = aClassElement.clazz; if (!newActualType.equals(sInfo.getActualType())) { sInfo.setActualType(newActualType, aClassElement.instance); addSubParametersToTree(sInfo, editedTree, editedNode); editedTree//w w w . j a va 2s.c o m .expandPath(new TreePath(((DefaultTreeModel) editedTree.getModel()).getPathToRoot(editedNode))); } // else do nothing }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Find a matching individual in the tree. * /*from www . j a v a2 s. c om*/ * @param wrapper * The individual to be matched * @param forward * True to search forward, false to search backward */ private void findMatchingIndividual(Wrapper wrapper, boolean forward) { final DefaultTreeModel treeModel = (DefaultTreeModel) ontModelTree.getModel(); final DefaultMutableTreeNode finalMatchAt; DefaultMutableTreeNode latestMatchAt = null; DefaultMutableTreeNode firstMatchAt = null; boolean foundClickedNode = false; boolean wrappedAroundBackward = false; if (wrapper != null && wrapper instanceof WrapperInstance) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeModel.getRoot(); @SuppressWarnings("unchecked") final Enumeration<DefaultMutableTreeNode> nodeEnumeration = node.preorderEnumeration(); while (nodeEnumeration.hasMoreElements()) { final DefaultMutableTreeNode nextNode = nodeEnumeration.nextElement(); if (nextNode.getUserObject() instanceof Wrapper) { final Wrapper nodeWrapper = (Wrapper) nextNode.getUserObject(); if (wrapper.getUuid().equals(nodeWrapper.getUuid())) { foundClickedNode = true; if (forward) { // If there is one past this location then // use it, otherwise wrap back to top latestMatchAt = null; } else { if (firstMatchAt != null || latestMatchAt != null) { // Searching backward and have found a previous one break; } wrappedAroundBackward = true; } } else if (!wrapper.getUuid().equals(nodeWrapper.getUuid()) && wrapper.getClass().equals(wrapper.getClass()) && wrapper.getLocalName().equals(nodeWrapper.getLocalName()) && wrapper.getUri().equals(nodeWrapper.getUri())) { if (firstMatchAt == null && !foundClickedNode) { // First one found, keep it in case we wrap around firstMatchAt = nextNode; LOGGER.debug("Found first matching node: search UUID: " + wrapper.getUuid() + " found UUID: " + nodeWrapper.getUuid()); } else { // Keep track of latest one found latestMatchAt = nextNode; LOGGER.debug("Found a following matching node: search UUID: " + wrapper.getUuid() + " found UUID: " + nodeWrapper.getUuid()); // If going forward then this is the next match if (forward && foundClickedNode) { break; } } } } } if ((!forward || foundClickedNode) && latestMatchAt != null) { finalMatchAt = latestMatchAt; if (forward) { setStatus("Next " + wrapper.getLocalName() + " found"); } else { if (wrappedAroundBackward) { setStatus("Wrapped to bottom of tree and found a " + wrapper.getLocalName()); } else { setStatus("Previous " + wrapper.getLocalName() + " found"); } } } else if (firstMatchAt != null) { finalMatchAt = firstMatchAt; if (forward) { setStatus("Wrapped to top of tree and found a " + wrapper.getLocalName()); } else { setStatus("Previous " + wrapper.getLocalName() + " found"); } } else { finalMatchAt = null; setStatus(wrapper.getLocalName() + " could not be found elsewhere in the tree"); } if (finalMatchAt != null) { ontModelTree.setExpandsSelectedPaths(true); // Scroll to the selected node SwingUtilities.invokeLater(new Runnable() { public void run() { ontModelTree.setSelectionPath(new TreePath(treeModel.getPathToRoot(finalMatchAt))); ontModelTree.scrollPathToVisible(new TreePath(treeModel.getPathToRoot(finalMatchAt))); final Rectangle visible = ontModelTree.getVisibleRect(); visible.x = 0; ontModelTree.scrollRectToVisible(visible); } }); } } }