@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); } }
@SuppressWarnings("unchecked") @Test public void selectAllCells() { TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view"); Platform.runLater(() -> { TreeTableViewSelectionModel<?> selectionModel = treeTableNode.getSelectionModel(); selectionModel.setCellSelectionEnabled(true); selectionModel.setSelectionMode(SelectionMode.MULTIPLE); selectionModel.selectRange(0, getTreeTableColumnAt(treeTableNode, 0), treeTableNode.getExpandedItemCount() - 1, getTreeTableColumnAt(treeTableNode, 1)); treeTable.marathon_select("all"); }); new Wait("Waiting for all cells to be selected") { @Override public boolean until() { return treeTableNode.getSelectionModel().getSelectedCells().size() == treeTableNode.getExpandedItemCount() * treeTableNode.getColumns().size(); } }; }
@SuppressWarnings("unchecked") @Test public void selectMultipleCells() { TreeTableView<?> treeTableView = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { TreeTableViewSelectionModel<?> selectionModel = treeTableView.getSelectionModel(); selectionModel.setCellSelectionEnabled(true); selectionModel.setSelectionMode(SelectionMode.MULTIPLE); Point2D point = getPoint(treeTableView, 1, 0); RFXTreeTableView rfxTreeTableView = new RFXTreeTableView(treeTableView, null, point, lr); rfxTreeTableView.focusGained(null); @SuppressWarnings("rawtypes") TreeTableColumn column = getTreeTableColumnAt(treeTableView, 0); selectionModel.select(1, column); selectionModel.select(3, getTreeTableColumnAt(treeTableView, 1)); rfxTreeTableView.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals( "{\"cells\":[[\"/Sales Department/Ethan Williams\",\"Employee\"],[\"/Sales Department/Michael Brown\",\"Email\"]]}", recording.getParameters()[0]); }
@SuppressWarnings("unchecked") @Test public void selectACell() { TreeTableView<?> treeTableView = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { TreeTableViewSelectionModel<?> selectionModel = treeTableView.getSelectionModel(); selectionModel.setCellSelectionEnabled(true); Point2D point = getPoint(treeTableView, 1, 0); RFXTreeTableView rfxTreeTableView = new RFXTreeTableView(treeTableView, null, point, lr); rfxTreeTableView.focusGained(null); @SuppressWarnings("rawtypes") TreeTableColumn column = getTreeTableColumnAt(treeTableView, 0); selectionModel.select(1, column); rfxTreeTableView.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("{\"cells\":[[\"/Sales Department/Ethan Williams\",\"Employee\"]]}", recording.getParameters()[0]); }
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(); } }
@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; } }
@SuppressWarnings("unchecked") @Test public void selectNoCell() { TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view"); Platform.runLater(() -> { TreeTableViewSelectionModel<?> selectionModel = treeTableNode.getSelectionModel(); selectionModel.setCellSelectionEnabled(true); selectionModel.select(0, getTreeTableColumnAt(treeTableNode, 0)); treeTable.marathon_select(""); }); new Wait("Waiting for no cell selection") { @Override public boolean until() { return treeTableNode.getSelectionModel().getSelectedCells().size() == 0; } }; }
@Test public void selectACell() { TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view"); Platform.runLater(() -> { TreeTableViewSelectionModel<?> selectionModel = treeTableNode.getSelectionModel(); selectionModel.setCellSelectionEnabled(true); treeTable.marathon_select("{\"cells\":[[\"/Sales Department/Ethan Williams\",\"Employee\"]]}"); }); new Wait("Waiting for cell to be selected") { @Override public boolean until() { return treeTableNode.getSelectionModel().getSelectedCells().size() == 1; } }; }
@Test public void selectMultipleCells() { TreeTableView<?> treeTableNode = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view"); Platform.runLater(() -> { TreeTableViewSelectionModel<?> selectionModel = treeTableNode.getSelectionModel(); selectionModel.setSelectionMode(SelectionMode.MULTIPLE); selectionModel.setCellSelectionEnabled(true); treeTable.marathon_select( "{\"cells\":[[\"/Sales Department/Ethan Williams\",\"Employee\"],[\"/Sales Department/Michael Brown\",\"Email\"]]}"); }); new Wait("Waiting for cells to be selected") { @Override public boolean until() { return treeTableNode.getSelectionModel().getSelectedCells().size() == 2; } }; }
@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); }
public static <S, T> Callback<TreeTableColumn<S, T>, TreeTableCell<S, T>> forTreeTableColumn( final Supplier<TypedTextField<T>> constructor, final TreeTableViewSelectionModel<S> selection ) { return (column -> new TypedTextFieldTreeTableCell<S, T>(constructor, selection)); }
public TypedTextFieldTreeTableCell( final Supplier<TypedTextField<T>> constructor, final TreeTableViewSelectionModel<S> selection ) { this.constructor = constructor; this.selection = selection; }
public TreeTableViewSelectionModel<T> getSelectionModel() { return tree.getSelectionModel(); }