List of usage examples for javax.swing.tree AbstractLayoutCache getPathForRow
public abstract TreePath getPathForRow(int row);
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
private void handleKeyPress(KeyEvent theE) { int row = getSelectedRow(); if (row == -1) { return;/* www . j a v a2s .c o m*/ } if (theE.getKeyCode() == KeyEvent.VK_ENTER || theE.getKeyCode() == KeyEvent.VK_F2) { AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); TreePath path = layout.getPathForRow(row); TreeNodeBase baseObj = (TreeNodeBase) path.getLastPathComponent(); if (myTableModel.isCellEditable(baseObj, TreeRowModel.COL_VALUE)) { editCellAt(row, TreeRowModel.COL_VALUE + 1); theE.consume(); } } }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
private void handleNewSelectedIndex(int theNewIndex) { if (mySelectionHandlingDisabled) { return;//ww w.j av a2s .c o m } ourLog.info("New selection index: " + theNewIndex); if (myCurrentlyEditing) { ourLog.info("Not responding to new selection index because we are marked as editing right now"); return; } AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); TreePath path = layout.getPathForRow(theNewIndex); DefaultMutableTreeNode lead = (DefaultMutableTreeNode) path.getLastPathComponent(); if (lead instanceof TreeNodeSegment) { TreeNodeSegment segmentNode = (TreeNodeSegment) lead; myMessages.setHighlitedRangeBasedOnSegment(segmentNode.getSegment()); } else if (lead instanceof TreeNodeGroup) { TreeNodeGroup type = (TreeNodeGroup) lead; try { List<Segment> segments = type.getSegments(); myMessages.setHighlitedRangeBasedOnSegment(segments.toArray(new Segment[segments.size()])); } catch (HL7Exception e) { e.printStackTrace(); } } else if (lead instanceof TreeNodeType) { TreeNodeType type = (TreeNodeType) lead; myMessages.setHighlitedRangeBasedOnField(type.getSegmentAndComponentPath()); } else { myMessages.clearHighlight(); } }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
public void collapseAll() { AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); for (int i = 0; i < layout.getRowCount(); i++) { TreePath path = layout.getPathForRow(i); collapsePath(path);// ww w . jav a 2 s. c om } }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
public void expandAll() { AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); for (int i = 0; i < layout.getRowCount(); i++) { TreePath path = layout.getPathForRow(i); expandPath(path);//from w w w .j a v a 2 s .c om } }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
private Set<String> getOpenPaths() { Set<String> retVal = new HashSet<String>(); TableModel model = getModel(); AbstractLayoutCache layout = ((OutlineModel) model).getLayout(); int messageIndex = -1; for (int i = 0; i < layout.getRowCount(); i++) { TreePath path = layout.getPathForRow(i); Object baseObj = path.getLastPathComponent(); if (baseObj instanceof TreeNodeMessage || baseObj instanceof TreeNodeUnknown) { messageIndex++;//from ww w .j a v a 2s.c om if (layout.getExpandedState(path)) { retVal.add(Integer.toString(messageIndex)); } } else { baseObj = path.getPathComponent(path.getPathCount() - 2); if (baseObj instanceof TreeNodeBase) { retVal.add(Integer.toString(messageIndex) + ((TreeNodeBase) baseObj).getTerserPath()); } } } return retVal; }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
private String getPathAtRow(int theRowIndex) { AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); int messageIndex = -1; for (int i = 0; i < layout.getRowCount(); i++) { TreePath path = layout.getPathForRow(i); Object baseObj = path.getLastPathComponent(); if (baseObj instanceof TreeNodeMessage || baseObj instanceof TreeNodeUnknown) { messageIndex++;// w w w .j a v a2 s.c o m if (i == theRowIndex) { return Integer.toString(messageIndex); } } else { if (i == theRowIndex && baseObj instanceof TreeNodeBase) { return (Integer.toString(messageIndex) + ((TreeNodeBase) baseObj).getTerserPath()); } } } return null; }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
private void expandPaths(Set<String> theOpenPaths, String theSelectedPath) { AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); int messageIndex = -1; for (int i = 0; i < layout.getRowCount(); i++) { TreePath path = layout.getPathForRow(i); Object baseObj = path.getLastPathComponent(); String pathString = null; if (baseObj instanceof TreeNodeMessage || baseObj instanceof TreeNodeUnknown) { messageIndex++;/*from w w w . j ava2 s . co m*/ pathString = Integer.toString(messageIndex); } else if (baseObj instanceof TreeNodeBase) { pathString = (Integer.toString(messageIndex) + ((TreeNodeBase) baseObj).getTerserPath()); } if (pathString != null) { if (theOpenPaths.contains(pathString)) { expandPath(path); } else { collapsePath(path); } if (pathString.equals(theSelectedPath)) { getSelectionModel().setSelectionInterval(i, i); } } } }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
void addChildren() throws InterruptedException, InvocationTargetException { if (myMessages != null && myMessages.getRuntimeProfile() != null) { myRuntimeProfileValidator = new DefaultValidator(); myRuntimeProfileValidator.setValidateChildren(false); }/*from w ww . j ava2 s . c o m*/ final Set<String> openPaths = getOpenPaths(); int selectedRow = getSelectedRow(); final String selectedPath = getPathAtRow(selectedRow); if (myMessages != null) { try { addChildren(myMessages.getMessages(), myTop, ""); } catch (InterruptedException e) { ourLog.info("Interrupted during an update loop, going to schedule another pass"); myUpdaterThread.scheduleUpdate(); } catch (InvocationTargetException e) { ourLog.error("Failed up update message tree", e); } myTop.validate(); EventQueue.invokeLater(new Runnable() { public void run() { myTreeModel.nodeStructureChanged(myTop); } }); } EventQueue.invokeLater(new Runnable() { public void run() { try { mySelectionHandlingDisabled = true; ourLog.debug("Open paths are: {}", openPaths); if (openPaths.isEmpty() && myShouldOpenDefaultPaths) { ourLog.info("Opening default paths"); final AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); for (int row = 0; row < layout.getRowCount(); row++) { TreePath path = layout.getPathForRow(row); Object component = path.getLastPathComponent(); if (component instanceof TreeNodeMessage || component instanceof TreeNodeUnknown || component instanceof TreeNodeGroup) { expandPath(path); } } myShouldOpenDefaultPaths = false; } else { ourLog.info("Opening pre-existing paths: {} and selected path: {}", openPaths, selectedPath); expandPaths(openPaths, selectedPath); } } finally { mySelectionHandlingDisabled = false; } } }); // if (selectedRow != -1) { // getSelectionModel().setSelectionInterval(selectedRow, selectedRow); // handleNewSelectedIndex(selectedRow); // } }
From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java
private void doSynchronizeTreeWithHighlitedPath() { String highlitedPath = myMessages.getHighlitedPath(); if (highlitedPath == null) { return;/*from w w w.j ava 2 s . c o m*/ } final AbstractLayoutCache layout = ((OutlineModel) getModel()).getLayout(); int lastSegmentRow = -1; int currentSegmentRow = -1; int currentSelectedRow = -1; int currentMessageIndex = -1; for (int row = 0; row < layout.getRowCount(); row++) { TreePath path = layout.getPathForRow(row); Object component = path.getLastPathComponent(); if (component instanceof TreeNodeMessage) { currentMessageIndex = ((TreeNodeMessage) component).getMessageIndex(); if (highlitedPath.startsWith(currentMessageIndex + "/")) { expandPath(path); } else { // collapsePath(path); } continue; } if (component instanceof TreeNodeUnknown) { continue; } if (component instanceof TreeNodeSegment) { lastSegmentRow = row; } TreeNodeBase node = (TreeNodeBase) component; String terserPath = (currentMessageIndex) + node.getTerserPath(); if (highlitedPath != null && highlitedPath.startsWith(terserPath) && !highlitedPath.startsWith(terserPath + "(")) { expandPath(path); if (highlitedPath.equals(terserPath)) { currentSelectedRow = row; getSelectionModel().setSelectionInterval(row, row); currentSegmentRow = lastSegmentRow; } } else { // collapsePath(path); } } // Adjust the tree scrollpane's scroll position so that the newly // selected row is visible if (currentSegmentRow != -1 && currentSelectedRow != -1 && !myRespondingToManualRangeChange) { JViewport viewPort = (JViewport) getParent(); final JScrollPane scrollPane = (JScrollPane) viewPort.getParent(); int tableHeaderHeight = getTableHeader().getHeight(); int numRowsVisible = ((scrollPane.getHeight() - tableHeaderHeight) / layout.getRowHeight()) - 1; int segmentDelta = currentSelectedRow - currentSegmentRow; if (segmentDelta > numRowsVisible) { currentSegmentRow = currentSegmentRow + (segmentDelta - numRowsVisible); } final int scrollToRow = currentSegmentRow; SwingUtilities.invokeLater(new Runnable() { public void run() { scrollPane.getVerticalScrollBar().setValue(layout.getRowHeight() * scrollToRow); } }); } }