Java Code Examples for javafx.scene.control.TreeTableView#getSelectionModel()

The following examples show how to use javafx.scene.control.TreeTableView#getSelectionModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void selectTreeTableCells(TreeTableView<?> treeTableView, String value) {
    @SuppressWarnings("rawtypes")
    TreeTableViewSelectionModel selectionModel = treeTableView.getSelectionModel();
    JSONObject cells = new JSONObject(value);
    JSONArray object = (JSONArray) cells.get("cells");
    for (int i = 0; i < object.length(); i++) {
        JSONArray jsonArray = object.getJSONArray(i);
        int rowIndex = getTreeTableNodeIndex(treeTableView, jsonArray.getString(0));
        int columnIndex = getTreeTableColumnIndex(treeTableView, jsonArray.getString(1));
        @SuppressWarnings("rawtypes")
        TreeTableColumn column = treeTableView.getColumns().get(columnIndex);
        if (getVisibleCellAt(treeTableView, rowIndex, columnIndex) == null) {
            treeTableView.scrollToColumn(column);
            treeTableView.scrollTo(rowIndex);
        }
        selectionModel.select(rowIndex, column);
    }
}
 
Example 2
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public String getTreeTableSelection(TreeTableView<?> treeTableView) {
    TreeTableViewSelectionModel<?> selectionModel = treeTableView.getSelectionModel();
    ObservableList<Integer> selectedIndices = selectionModel.getSelectedIndices();
    ObservableList<?> selectedCells = selectionModel.getSelectedCells();
    int rowCount = treeTableView.getExpandedItemCount();
    int columnCount = treeTableView.getColumns().size();
    if (selectedIndices.size() == 0 || selectedCells.size() == 0) {
        return "";
    } else if (!selectionModel.isCellSelectionEnabled() && selectedIndices.size() == treeTableView.getExpandedItemCount()
            || selectionModel.isCellSelectionEnabled() && selectedCells.size() == rowCount * columnCount) {
        return "all";
    } else if (!selectionModel.isCellSelectionEnabled()) {
        return getTreeTableRowSelectionText(treeTableView, selectionModel.getSelectedItems());
    } else {
        int[] rows = new int[selectedCells.size()];
        int[] columns = new int[selectedCells.size()];
        JSONObject cells = new JSONObject();
        JSONArray value = new JSONArray();
        for (int i = 0; i < selectedCells.size(); i++) {
            TreeTablePosition<?, ?> cell = (TreeTablePosition<?, ?>) selectedCells.get(i);
            rows[i] = cell.getRow();
            columns[i] = cell.getColumn();
            List<String> cellValue = new ArrayList<>();
            cellValue.add(getTreeTableNodePath(treeTableView, selectionModel.getModelItem(cell.getRow())));
            cellValue.add(getTreeTableColumnName(treeTableView, cell.getColumn()));
            value.put(cellValue);
        }
        cells.put("cells", value);
        return cells.toString();
    }
}
 
Example 3
Source File: JavaFXTreeTableViewElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean marathon_select(String value) {
    TreeTableView<?> treeTableView = (TreeTableView<?>) getComponent();
    TreeTableViewSelectionModel<?> selectionModel = treeTableView.getSelectionModel();
    if (value.equals("")) {
        selectionModel.clearSelection();
        return true;
    } else if (value.equals("all")) {
        selectionModel.clearSelection();
        if (!selectionModel.isCellSelectionEnabled()) {
            int rowCount = treeTableView.getExpandedItemCount();
            for (int i = 0; i < rowCount; i++) {
                selectionModel.select(i);
            }
            return true;
        } else {
            selectionModel.clearSelection();
            selectionModel.selectRange(0, getTreeTableColumnAt(treeTableView, 0), treeTableView.getExpandedItemCount() - 1,
                    getTreeTableColumnAt(treeTableView, treeTableView.getColumns().size() - 1));
            return true;
        }
    } else if (!selectionModel.isCellSelectionEnabled()) {
        selectionModel.clearSelection();
        int[] selectedRows = getTreeTableSelectedRows(treeTableView, value);
        for (int selectedRow : selectedRows) {
            if (getVisibleCellAt(treeTableView, selectedRow, 0) == null) {
                treeTableView.scrollTo(selectedRow);
            }
            selectionModel.select(selectedRow);
        }
        return true;
    } else {
        selectionModel.clearSelection();
        selectTreeTableCells(treeTableView, value);
        return true;
    }
}
 
Example 4
Source File: TreeTableCellSampleApp.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("TreeTable View Cell Sample");
    primaryStage.setScene(new Scene(new TreeTableSample()));
    primaryStage.sizeToScene();
    primaryStage.show();
    TreeTableView<?> treeTableView = (TreeTableView<?>) primaryStage.getScene().getRoot().lookup(".tree-table-view");
    TreeTableViewSelectionModel<?> selectionModel = treeTableView.getSelectionModel();
    selectionModel.setCellSelectionEnabled(true);
    selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
}