Example usage for javax.swing.tree AbstractLayoutCache getRowCount

List of usage examples for javax.swing.tree AbstractLayoutCache getRowCount

Introduction

In this page you can find the example usage for javax.swing.tree AbstractLayoutCache getRowCount.

Prototype

public abstract int getRowCount();

Source Link

Document

Number of rows being displayed.

Usage

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);/*  www .j  a v a 2 s  . c  o  m*/
    }
}

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.  ja  v  a2  s  .c  o m
    }
}

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   w ww  . java 2s. co m*/

            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++;//from w  ww.j  a  v a2s . 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++;//w w w  .j a va 2 s .c om
            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   ww  w . j a v  a 2  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;// w w w . j  ava2 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);
            }
        });

    }
}