/** * 8158784: [TEST BUG] Need test for JDK-8157398 */ @Test public void testCollapsedNodeGraphicVisible() throws Exception { Color nodeColor = new Color(Math.random(), Math.random(), Math.random(), 1); TreeTableView treeTable = (TreeTableView) testedControl.getControl(); TreeItem<String> root = new TreeItem<>("Root Node"); TreeItem<String> child = new TreeItem<>("Child", new Rectangle(10, 10, nodeColor)); TreeTableColumn<String, String> column = new TreeTableColumn<>("Column"); column.setCellValueFactory(item -> new SimpleStringProperty("Whatever")); treeTable.getColumns().setAll(column); root.getChildren().add(child); root.setExpanded(true); treeTable.setShowRoot(true); runAndWait(() -> { treeTable.setRoot(root); }); Wrap nodeGraphic = parent.lookup(node -> node == child.getGraphic()).wrap(); Wrap sceneWrap = Root.ROOT.lookup().wrap(); waitForColor(nodeGraphic, 1, 1, nodeColor); Bounds graphicBounds = child.getGraphic().localToScene(child.getGraphic().getBoundsInLocal()); root.setExpanded(false); waitForColor(sceneWrap, (int) (graphicBounds.getMinX() + graphicBounds.getWidth() / 2), (int) (graphicBounds.getMinY() + graphicBounds.getHeight() / 2), Color.WHITE); }
@SuppressWarnings("unchecked") private String getTreeTableItemText(TreeTableView<?> treeTableView, TreeItem<?> lastPathComponent) { @SuppressWarnings("rawtypes") TreeTableColumn treeTableColumn = treeTableView.getTreeColumn(); if (treeTableColumn == null) { treeTableColumn = treeTableView.getColumns().get(0); } ObservableValue<?> cellObservableValue = treeTableColumn.getCellObservableValue(lastPathComponent); String original = cellObservableValue.getValue().toString(); String itemText = original; int suffixIndex = 0; TreeItem<?> parent = lastPathComponent.getParent(); if (parent == null) return itemText; ObservableList<?> children = parent.getChildren(); for (int i = 0; i < children.indexOf(lastPathComponent); i++) { TreeItem<?> child = (TreeItem<?>) children.get(i); cellObservableValue = treeTableColumn.getCellObservableValue(child); String current = cellObservableValue.getValue().toString(); if (current.equals(original)) { itemText = String.format("%s(%d)", original, ++suffixIndex); } } return itemText; }
@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 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]); }
private void setupGroupView() { groupList = new JFXTreeTableView<>(); TreeTableColumn<GroupTreeObject, String> nameColumn = new JFXTreeTableColumn<>("Name"); nameColumn.setPrefWidth(150); nameColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<GroupTreeObject, String> param) -> { Group group = fromItem(param.getValue()); if (group == null) { return new SimpleStringProperty(); } return new SimpleStringProperty(group.getDisplayName()); }); groupList.getColumns().add(nameColumn); TreeItem treeItem = new TreeItem<>(); treeItem.setExpanded(true); groupList.setRoot(treeItem); groupList.setShowRoot(false); groupList.setPrefHeight(Short.MAX_VALUE); }
@Override public TreeTableCell<ReferenceDescription, ReferenceDescription> call(TreeTableColumn<ReferenceDescription, ReferenceDescription> param) { return new TreeTableCell<ReferenceDescription, ReferenceDescription>() { @Override protected void updateItem(ReferenceDescription item, boolean empty) { super.updateItem(item, empty); if (!empty && item != null) { setText(item.getDisplayName().getText()); setGraphic(createGraphicNode(item)); } else { setText(null); setGraphic(null); } } }; }
@Override protected Node getTestContainer() { treeOrTreeTableView = new TreeTableView<Data>(); treeOrTreeTableView.setMinSize(300, 500); treeOrTreeTableView.setMaxSize(300, 500); treeOrTreeTableView.setPrefSize(300, 500); TreeTableColumn<Data, Node> column = new TreeTableColumn<Data, Node>("Items' name"); column.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Data, Node>, ObservableValue<Node>>() { @Override public ObservableValue<Node> call(final TreeTableColumn.CellDataFeatures<Data, Node> p) { SimpleObjectProperty<Node> text = new SimpleObjectProperty<Node>(); text.setValue(new Label(p.getValue().getValue().getData())); return text; } }); column.setPrefWidth(150); ((TreeTableView) treeOrTreeTableView).getColumns().add(column); reset(0); return treeOrTreeTableView; }
void resizeColumn(final int index, final double delta) { final double initialWidth = getColumnWidth(index); new GetAction<Void>() { @Override public void run(Object... os) throws Exception { if (isTableTests) { TableView table = (TableView) testedControl.getControl(); table.resizeColumn((TableColumn) table.getColumns().get(index), delta); } else { TreeTableView treeTable = (TreeTableView) testedControl.getControl(); treeTable.resizeColumn((TreeTableColumn) treeTable.getColumns().get(index), delta); } } }.dispatch(testedControl.getEnvironment()); new Waiter(new Timeout("", 1000)).waitState(new State<Boolean>() { public Boolean reached() { return (Math.abs(getColumnWidth(index) - initialWidth - delta) <= 1e-7) ? Boolean.TRUE : null; } }); }
/** * @param forward true gets the column to the right, false the column to the left of the current column * @return */ private TreeTableColumn<S, ?> getNextColumn(boolean forward) { List<TreeTableColumn<S, ?>> columns = new ArrayList<>(); for (TreeTableColumn<S, ?> column : getTreeTableView().getColumns()) { columns.addAll(getLeaves(column)); } //There is no other column that supports editing. if (columns.size() < 2) { return null; } int nextIndex = columns.indexOf(getTableColumn()); if (forward) { nextIndex++; if (nextIndex > columns.size() - 1) { nextIndex = 0; } } else { nextIndex--; if (nextIndex < 0) { nextIndex = columns.size() - 1; } } return columns.get(nextIndex); }
/** * this is a blocking method so it should not be called from the ui thread, * it will regroup the tree table view * @param treeTableColumns */ public void group(TreeTableColumn<S, ?>... treeTableColumns) { try{ lock.lock(); // init groups map if (groupOrder.size() == 0) { groups = new HashMap<>(); } try { if (originalRoot == null) { originalRoot = getRoot(); } for (TreeTableColumn<S, ?> treeTableColumn : treeTableColumns) { groups = group(treeTableColumn, groups, null, (RecursiveTreeItem<S>) originalRoot); } groupOrder.addAll(treeTableColumns); // update table ui buildGroupedRoot(groups, null, 0); } catch (Exception e) { e.printStackTrace(); } }finally { lock.unlock(); } }
@Override public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) { return new TreeTableCell<FeatureTableRow, Object>() { @Override public void updateItem(Object object, boolean empty) { super.updateItem(object, empty); setStyle("-fx-alignment: CENTER;" + "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;"); if (object == null) { setText(null); } else { NumberFormat formatter = MZmineCore.getConfiguration().getMZFormat(); Double doubleValue = Double.parseDouble(object.toString()); setText(formatter.format(doubleValue)); } } }; }
@Override public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) { return new TreeTableCell<FeatureTableRow, Object>() { @Override public void updateItem(Object object, boolean empty) { super.updateItem(object, empty); setStyle("-fx-alignment: CENTER;" + "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;"); if (object == null) { setText(null); } else { try { NumberFormat formatter = new DecimalFormat("#0.00"); Double doubleValue = Double.parseDouble(object.toString()); setText(formatter.format(doubleValue)); } catch (NumberFormatException e) { setText(object.toString()); } } } }; }
@Override public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) { return new TreeTableCell<FeatureTableRow, Object>() { @Override public void updateItem(Object object, boolean empty) { super.updateItem(object, empty); setStyle("-fx-alignment: CENTER;" + "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;"); if (object == null) { setText(null); } else { Integer integerValue = Integer.parseInt(object.toString()); setText(integerValue.toString()); } } }; }
@Override public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) { return new TreeTableCell<FeatureTableRow, Object>() { @Override public void updateItem(Object object, boolean empty) { super.updateItem(object, empty); setStyle("-fx-alignment: CENTER;" + "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;"); if (object == null) { setText(null); } else { Range rangeValue = (Range) object; NumberFormat formatter = MZmineCore.getConfiguration().getMZFormat(); String value = formatter.format(rangeValue.lowerEndpoint()) + " - " + formatter.format(rangeValue.upperEndpoint()); setText(value); } } }; }
@Override public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) { return new TreeTableCell<FeatureTableRow, Object>() { @Override public void updateItem(Object object, boolean empty) { super.updateItem(object, empty); setStyle("-fx-alignment: CENTER;" + "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;"); if (object == null) { setText(null); } else { Double doubleValue = Double.parseDouble(object.toString()); NumberFormat formatter = MZmineCore.getConfiguration().getIntensityFormat(); setText(formatter.format(doubleValue)); } } }; }
@Override public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) { return new TreeTableCell<FeatureTableRow, Object>() { @Override public void updateItem(Object object, boolean empty) { super.updateItem(object, empty); setStyle("-fx-alignment: CENTER;" + "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;"); if (object == null) { setText(null); } else { NumberFormat formatter = MZmineCore.getConfiguration().getRTFormat(); Float floatValue = Float.parseFloat(object.toString()); setText(formatter.format(floatValue)); } } }; }
@Override public TreeTableCell<FeatureTableRow, Object> call(TreeTableColumn<FeatureTableRow, Object> p) { return new TreeTableCell<FeatureTableRow, Object>() { @Override public void updateItem(Object object, boolean empty) { super.updateItem(object, empty); setStyle("-fx-alignment: CENTER;" + "-fx-border-color: transparent -fx-table-cell-border-color -fx-table-cell-border-color transparent;"); if (object == null) { setText(null); } else { // Default format to two decimals NumberFormat formatter = new DecimalFormat("#0.00"); Double doubleValue = Double.parseDouble(object.toString()); setText(formatter.format(doubleValue)); } } }; }
public PgpKeyTreePane() { loadDynamicComponentFxml(PgpKeyTreePane.class, this); treeTableView.setShowRoot(false); treeTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); nameTreeTableColumn.setCellFactory(new Callback<TreeTableColumn<PgpKeyTreeItem<?>,String>, TreeTableCell<PgpKeyTreeItem<?>,String>>() { @Override public TreeTableCell<PgpKeyTreeItem<?>, String> call(TreeTableColumn<PgpKeyTreeItem<?>, String> param) { return new NameCell(); } }); checkedTreeItems.addListener(new SetChangeListener<PgpKeyTreeItem<?>>() { @Override public void onChanged(SetChangeListener.Change<? extends PgpKeyTreeItem<?>> change) { final PgpKeyTreeItem<?> elementAdded = change.getElementAdded(); if (elementAdded != null) elementAdded.setChecked(true); final PgpKeyTreeItem<?> elementRemoved = change.getElementRemoved(); if (elementRemoved != null) elementRemoved.setChecked(false); } }); }
@Override public TreeTableCell<FileTreeItem<?>, String> call(TreeTableColumn<FileTreeItem<?>, String> param) { return new TreeTableCell<FileTreeItem<?>, String>() { @Override protected void updateItem(String value, boolean empty) { super.updateItem(value, empty); final FileTreeItem<?> treeItem = getTreeTableRow().getItem(); if (value == null || treeItem == null || empty) { setText(null); setGraphic(null); } else { setText(value); setGraphic(treeItem2CollisionIconImageView.get(treeItem)); updateGraphicAsync(this, treeItem); } } }; }
@SuppressWarnings("rawtypes") public TreeTableCell getVisibleCellAt(TreeTableView<?> treeTableView, int row, int column) { Set<Node> lookupAll = getTreeTableCells(treeTableView); TreeTableCell cell = null; for (Node node : lookupAll) { TreeTableCell<?, ?> cell1 = (TreeTableCell<?, ?>) node; TreeTableRow<?> tableRow = cell1.getTreeTableRow(); TreeTableColumn<?, ?> tableColumn = cell1.getTableColumn(); if (tableRow.getIndex() == row && tableColumn == treeTableView.getColumns().get(column)) { cell = cell1; break; } } return cell; }
protected int getTreeTableColumnIndex(TreeTableView<?> treeTableView, String columnName) { ObservableList<?> columns = treeTableView.getColumns(); int ncolumns = columns.size(); for (int i = 0; i < ncolumns; i++) { @SuppressWarnings("rawtypes") String column = ((TreeTableColumn) columns.get(i)).getText(); if (columnName.equals(escapeSpecialCharacters(column))) { return i; } } throw new RuntimeException("Could not find column " + columnName + " in tree table"); }
private void updateObservableListProperties(TreeTableColumn<Employee, String> empColumn) { empColumn.setOnEditCommit(new EventHandler<TreeTableColumn.CellEditEvent<Employee, String>>() { @Override public void handle(CellEditEvent<Employee, String> t) { TreeItem<Employee> treeItem = t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()); treeItem.getValue().setName(t.getNewValue()); } }); }
private <T> void setupCellValueFactory(JFXTreeTableColumn<FXHost, T> column, Function<FXHost, ObservableValue<T>> mapper) { column.setCellValueFactory((TreeTableColumn.CellDataFeatures<FXHost, T> param) -> { if (column.validateValue(param)) { return mapper.apply(param.getValue().getValue()); } else { return column.getComputedValue(param); } }); }
private TreeTableCell<T,Object> getCellFactory(TreeTableColumn<T,Object> tc) { return new TreeTableCell<T,Object>() { @Override protected void updateItem(Object item, boolean empty) { super.updateItem(item, empty); if(empty) { setText(null); setGraphic(null); } else { if(renderer == null) { String text = formatter.toString(item); setText(text); setGraphic(null); setAlignment(alignment); } else { Node n = renderer.apply(item); setText(null); setGraphic(n); } } } }; }
private Callback createCellFactory() { return new Callback<TreeTableColumn<T,?>,TreeTableCell<T,?>>() { @Override public TreeTableCell<T,?> call(TreeTableColumn<T,?> column) { return new TreeTableCell() { @Override protected void updateItem(Object item, boolean empty) { if(item == getItem()) { return; } super.updateItem(item, empty); if(item == null) { super.setText(null); super.setGraphic(null); } else if(item instanceof Node) { super.setText(null); super.setGraphic((Node)item); } else { super.setText(item.toString()); super.setGraphic(null); } } }; } }; }
private static ReadOnlyObjectProperty<? extends Control> getControlProperty(Object obj) { if (obj instanceof TableColumn) { return ((TableColumn) obj).tableViewProperty(); } else if (obj instanceof TreeTableColumn) { return ((TreeTableColumn) obj).treeTableViewProperty(); } else if (obj instanceof DockTab) { return ((DockTab) obj).tabPaneProperty(); } return null; }
protected void addColumnString (String heading, int width, Justification justification, String propertyName) { TreeTableColumn<T, String> column = new TreeTableColumn<> (heading); column.setPrefWidth (width); column .setCellValueFactory (new TreeItemPropertyValueFactory<T, String> (propertyName)); getColumns ().add (column); if (justification == Justification.CENTER) column.setStyle ("-fx-alignment: CENTER;"); }
protected void addColumnNumber (String heading, int width, String propertyName) { TreeTableColumn<T, Number> column = new TreeTableColumn<> (heading); column.setPrefWidth (width); column .setCellValueFactory (new TreeItemPropertyValueFactory<T, Number> (propertyName)); getColumns ().add (column); column.setStyle ("-fx-alignment: CENTER-RIGHT;"); }
EventHandler getOnEditStart(final int columnIndex) { return new GetAction<EventHandler>() { @Override public void run(Object... os) throws Exception { if (isTreeTests) { setResult(((TreeView) (testedControl.getControl())).getOnEditStart()); } else { TreeTableView treeTable = (TreeTableView) (testedControl.getControl()); setResult(((TreeTableColumn) treeTable.getColumns().get(columnIndex)).getOnEditStart()); } } }.dispatch(testedControl.getEnvironment()); }
EventHandler getOnEditCancel(final int columnIndex) { return new GetAction<EventHandler>() { @Override public void run(Object... os) throws Exception { if (isTreeTests) { setResult(((TreeView) (testedControl.getControl())).getOnEditCancel()); } else { TreeTableView treeTable = (TreeTableView) (testedControl.getControl()); setResult(((TreeTableColumn) treeTable.getColumns().get(columnIndex)).getOnEditCancel()); } } }.dispatch(testedControl.getEnvironment()); }
EventHandler getOnEditCommit(final int columnIndex) { return new GetAction<EventHandler>() { @Override public void run(Object... os) throws Exception { if (isTreeTests) { setResult(((TreeView) (testedControl.getControl())).getOnEditCommit()); } else { TreeTableView treeTable = (TreeTableView) (testedControl.getControl()); setResult(((TreeTableColumn) treeTable.getColumns().get(columnIndex)).getOnEditCommit()); } } }.dispatch(testedControl.getEnvironment()); }
void setOnEditStart(EventHandler handler, final int columnIndex) { new GetAction<Void>() { @Override public void run(Object... args) throws Exception { if (isTreeTests) { ((TreeView) (testedControl.getControl())).setOnEditStart((EventHandler) args[0]); } else { TreeTableView treeTable = (TreeTableView) (testedControl.getControl()); ((TreeTableColumn) treeTable.getColumns().get(columnIndex)).setOnEditStart((EventHandler) args[0]); } } }.dispatch(testedControl.getEnvironment(), handler); }
void setOnEditCancel(EventHandler handler, final int columnIndex) { new GetAction<Void>() { @Override public void run(Object... args) throws Exception { if (isTreeTests) { ((TreeView) (testedControl.getControl())).setOnEditCancel((EventHandler) args[0]); } else { TreeTableView treeTable = (TreeTableView) (testedControl.getControl()); ((TreeTableColumn) treeTable.getColumns().get(columnIndex)).setOnEditCancel((EventHandler) args[0]); } } }.dispatch(testedControl.getEnvironment(), handler); }
void setOnEditCommit(EventHandler handler, final int columnIndex) { new GetAction<Void>() { @Override public void run(Object... args) throws Exception { if (isTreeTests) { ((TreeView) (testedControl.getControl())).setOnEditCommit((EventHandler) args[0]); } else { TreeTableView treeTable = (TreeTableView) (testedControl.getControl()); ((TreeTableColumn) treeTable.getColumns().get(columnIndex)).setOnEditCommit((EventHandler) args[0]); } } }.dispatch(testedControl.getEnvironment(), handler); }
static void checkSortType(TableColumnBase col, ColumnState.SortTypeProvider type) { if (isTableTests) { assertTrue(((TableColumn) col).getSortType().equals(type.forTableColumn())); } else { assertTrue(((TreeTableColumn) col).getSortType().equals(type.forTreeTableColumn())); } }
static void setSortType(TableColumnBase col, ColumnState.SortTypeProvider type) { if (isTableTests) { ((TableColumn) col).setSortType(type.forTableColumn()); } else { ((TreeTableColumn) col).setSortType(type.forTreeTableColumn()); } }
protected String getColumnText(final int index) { if (isTableTests) { TableView table = (TableView) testedControl.getControl(); return ((TableColumn) table.getColumns().get(index)).getText(); } else { TreeTableView treeTable = (TreeTableView) testedControl.getControl(); return ((TreeTableColumn) treeTable.getColumns().get(index)).getText(); } }