Example usage for javax.swing.tree TreeSelectionModel getSelectionRows

List of usage examples for javax.swing.tree TreeSelectionModel getSelectionRows

Introduction

In this page you can find the example usage for javax.swing.tree TreeSelectionModel getSelectionRows.

Prototype

int[] getSelectionRows();

Source Link

Document

Returns all of the currently selected rows.

Usage

From source file:org.openmicroscopy.shoola.agents.measurement.view.ObjectManager.java

/** Initializes the components composing the display. */
private void initComponents() {
    ROINode root = new ROINode("root");
    objectsTable = new ROITable(new ROITableModel(root, COLUMN_NAMES), COLUMN_NAMES, this);
    objectsTable.setRootVisible(false);//w  ww  .j av  a2 s  . c  om
    objectsTable.setColumnSelectionAllowed(true);
    objectsTable.setRowSelectionAllowed(true);
    treeSelectionListener = new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            TreeSelectionModel tsm = objectsTable.getTreeSelectionModel();
            if (tsm.isSelectionEmpty())
                return;
            int[] index = tsm.getSelectionRows();
            if (index.length == 0)
                return;
            if (index.length == 1) {
                ROINode node = (ROINode) objectsTable.getNodeAtRow(objectsTable.getSelectedRow());
                if (node == null)
                    return;
                Object nodeValue = node.getUserObject();
                view.clearInspector();
                if (nodeValue instanceof ROIShape) {
                    view.selectFigure(((ROIShape) nodeValue).getFigure());
                }
                int col = objectsTable.getSelectedColumn();
                int row = objectsTable.getSelectedRow();

                if (row < 0 || col < 0)
                    return;
            } else {
                ROIShape shape;
                for (int i = 0; i < index.length; i++) {
                    shape = objectsTable.getROIShapeAtRow(index[i]);
                    if (shape != null) {
                        view.selectFigure(shape.getFigure());
                        requestFocus();
                    }
                }
            }
        }
    };

    objectsTable.addTreeSelectionListener(treeSelectionListener);

    ColumnFactory columnFactory = new ColumnFactory() {

        public void configureColumnWidths(JXTable table, TableColumnExt columnExt) {
            columnExt.setPreferredWidth(COLUMN_WIDTHS.get(columnExt.getHeaderValue()));
        }
    };
    objectsTable.setHorizontalScrollEnabled(true);
    objectsTable.setColumnControlVisible(true);
    objectsTable.setColumnFactory(columnFactory);
}