c.setCellFactory((co) -> new NameTableCell()); c.setCellValueFactory((cdf) -> new SimpleObjectProperty<>(cdf .getValue())); t.getColumns().add(c); c.setMinWidth(100); c.setCellFactory((co) -> new LastModifiedCell()); c.setCellValueFactory((cdf) -> cdf.getValue() .lastModifiedProperty()); t.getColumns().add(c); c.setCellFactory((co) -> new SizeCell()); c.setCellValueFactory((cdf) -> { if (cdf.getValue() instanceof DirItem) { return new SimpleObjectProperty<>(null); return ((FileItem) cdf.getValue()).fileSizeProperty(); });
final SportType sportType = cellData.getValue().getSportType(); return new SimpleObjectProperty<>(sportType == null ? null : sportType.getName()); }); tcSportSubtype.setCellValueFactory(cellData -> { final SportSubType sportSubType = cellData.getValue().getSportSubType(); return new SimpleObjectProperty<>(sportSubType == null ? null : sportSubType.getName()); }); tcDistance.setCellValueFactory(new PropertyValueFactory<>("distance")); tcAvgSpeed.setCellValueFactory(cellData -> { final Exercise exercise = cellData.getValue(); return new SimpleObjectProperty<>(exercise == null ? null : new SpeedInfo( exercise.getAvgSpeed(), exercise.getSportType().getSpeedMode())); tcEnergy.setCellValueFactory(new PropertyValueFactory<>("calories")); tcEquipment.setCellValueFactory(cellData -> { final Equipment equipment = cellData.getValue().getEquipment(); return new SimpleObjectProperty<>(equipment == null ? null : equipment.getName()); }); tcEquipment.setCellValueFactory(cellData -> new SimpleObjectProperty<>( // cellData.getValue().getEquipment() == null ? null : cellData.getValue().getEquipment().getName())); tcComment.setCellValueFactory(cellData -> new SimpleObjectProperty<>( // StringUtils.getFirstLineOfText(cellData.getValue().getComment())));
contingencyColumn.setPrefWidth(200); contingencyColumn.setCellFactory(stringColumnFactory); contingencyColumn.setCellValueFactory(callback -> callback.getValue() instanceof ContingencyRow ? new SimpleObjectProperty<>(callback.getValue().getContingency().getId()) : null); TableColumn<ResultRow, String> equipmentColumn = createColumn("Equipment"); equipmentColumn.setPrefWidth(200); equipmentColumn.setCellFactory(stringColumnFactory); equipmentColumn.setCellValueFactory(callback -> callback.getValue() instanceof LimitViolationRow ? new SimpleObjectProperty<>(((LimitViolationRow) callback.getValue()).getViolation().getSubjectId()) : null); TableColumn<ResultRow, String> violationTypeColumn = createColumn("ViolationType"); violationTypeColumn.setPrefWidth(150); violationTypeColumn.setCellFactory(stringColumnFactory); violationTypeColumn.setCellValueFactory(callback -> callback.getValue() instanceof LimitViolationRow ? new SimpleObjectProperty<>(((LimitViolationRow) callback.getValue()).getViolation().getLimitType().name()) : null); TableColumn<ResultRow, String> violationNameColumn = createColumn("ViolationName"); violationNameColumn.setPrefWidth(150); violationNameColumn.setCellFactory(stringColumnFactory); violationNameColumn.setCellValueFactory(callback -> callback.getValue() instanceof LimitViolationRow ? new SimpleObjectProperty<>(((LimitViolationRow) callback.getValue()).getViolation().getLimitName()) : null); TableColumn<ResultRow, Double> limitColumn = createColumn("Limit"); limitColumn.setCellFactory(decimalColumnFactory); limitColumn.setCellValueFactory(callback -> callback.getValue() instanceof LimitViolationRow ? new SimpleObjectProperty<>(((LimitViolationRow) callback.getValue()).getViolation().getLimit()) : null); TableColumn<ResultRow, Double> valueColumn = createColumn("Value");
equipmentColumn.setPrefWidth(200); equipmentColumn.setCellFactory(stringColumnFactory); equipmentColumn.setCellValueFactory(callback -> new SimpleObjectProperty<>(callback.getValue().getSubjectId())); TableColumn<LimitViolation, String> violationTypeColumn = createColumn("ViolationType"); violationTypeColumn.setPrefWidth(150); violationTypeColumn.setCellFactory(stringColumnFactory); violationTypeColumn.setCellValueFactory(callback -> new SimpleObjectProperty<>(callback.getValue().getLimitType().name())); TableColumn<LimitViolation, String> violationNameColumn = createColumn("ViolationName"); violationNameColumn.setPrefWidth(150); violationNameColumn.setCellFactory(stringColumnFactory); violationNameColumn.setCellValueFactory(callback -> new SimpleObjectProperty<>(callback.getValue().getLimitName())); TableColumn<LimitViolation, Double> limitColumn = createColumn("Limit"); limitColumn.setCellFactory(decimalColumnFactory); limitColumn.setCellValueFactory(callback -> new SimpleObjectProperty<>(callback.getValue().getLimit())); TableColumn<LimitViolation, Double> valueColumn = createColumn("Value"); valueColumn.setCellFactory(decimalColumnFactory); valueColumn.setCellValueFactory(callback -> new SimpleObjectProperty<>(callback.getValue().getValue())); TableColumn<LimitViolation, Double> loadColumn = createColumn("Load"); loadColumn.setPrefWidth(150); loadColumn.setCellFactory(decimalColumnFactory); loadColumn.setCellValueFactory(callback -> { LimitViolation violation = callback.getValue(); double load = violation.getValue() / (violation.getLimit() * violation.getLimitReduction()) * 100; return new SimpleObjectProperty<>(load);
factoryColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().parentDisplayText())); tableView.getColumns().add(factoryColumn); fieldColumn.setCellValueFactory(param -> { try { String labelText = uniformDesign.getLabelText(param.getValue().createPreviousAttribute()); previousColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPreviousAttributeDisplayText())); tableView.getColumns().add(previousColumn); newColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getNewAttributeDisplayText())); tableView.getColumns().add(newColumn);
c.setCellValueFactory(f -> new SimpleObjectProperty<>(f.getValue())); c.setCellFactory(cc -> new TableCell<S, S>() { private BooleanProperty modelProperty;
c.setCellFactory((co) -> new NameTableCell()); c.setCellValueFactory((cdf) -> new SimpleObjectProperty<>(cdf .getValue())); this.tableView.getColumns().add(c); c.setMinWidth(100); c.setCellFactory((co) -> new LastModifiedCell()); c.setCellValueFactory((cdf) -> cdf.getValue() .lastModifiedProperty()); this.tableView.getColumns().add(c); c.setCellFactory((co) -> new SizeCell()); c.setCellValueFactory((cdf) -> { if (cdf.getValue() instanceof DirItem) { return new SimpleObjectProperty<>(null); return ((FileItem) cdf.getValue()).fileSizeProperty(); });
doneColumn.setMaxWidth(40); doneColumn.setMinWidth(40); doneColumn.setCellValueFactory(cdf -> cdf.getValue().pDone());
test.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().internal().getDisplayText())); tableView.getColumns().add(test); tableView.getStyleClass().add("hidden-tableview-headers");
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); TableColumn<T, String> column = new TableColumn<>(); column.setCellValueFactory(param -> new DataObservableDisplayText(param.getValue()).get()); table.getColumns().add(column); pane.setCenter(table);
typeCol.setCellValueFactory(new PropertyValueFactory("type")); TableColumn<Var, ScriptValue> valueCol = new TableColumn("Value"); valueCol.setCellValueFactory(c -> new ReadOnlyObjectWrapper(c.getValue().getValue())); valueCol.setCellFactory(c -> new VarValueCell()); table.getColumns().addAll(nameCol, typeCol, valueCol);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); TableColumn<Data, String> test = new TableColumn<>("Data"); test.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().internal().getDisplayText())); tableView.getColumns().add(test); tableView.getStyleClass().add("hidden-tableview-headers");
@Override public Node createContent() { SplitPane splitPane = new SplitPane(); splitPane.setOrientation(orientation); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); column = new TableColumn<>("Data"); column.setCellValueFactory(param -> new DataObservableDisplayText(param.getValue()).get()); tableView.getColumns().add(column); BorderPane borderPaneWrapper = new BorderPane(); borderPaneWrapper.setCenter(tableView); SplitPane.setResizableWithParent(borderPaneWrapper, Boolean.FALSE); splitPane.getItems().add(borderPaneWrapper); Node dataEditorWidget = this.dataEditor.createContent(); SplitPane.setResizableWithParent(dataEditorWidget, Boolean.TRUE); splitPane.getItems().add(dataEditorWidget); splitPane.setDividerPositions(dividerPosition); tableView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { dataEditor.edit(newValue); }); listEditWidget = new BorderPane(); TableControlWidget tableControlWidget= new TableControlWidget<>(tableView, uniformDesign); Node tableControlWidgetContent = tableControlWidget.createContent(); HBox hBox = new HBox(); hBox.getChildren().addAll(listEditWidget, tableControlWidgetContent); HBox.setHgrow(tableControlWidgetContent, Priority.ALWAYS); HBox.setMargin(tableControlWidgetContent, new Insets(0,1,0,0)); borderPaneWrapper.setBottom(hBox); tableView.setTableMenuButtonVisible(false); return splitPane; }
/** * Setup a table column with the provided value extractor * * @param c * the column to configure * @param valueExtractor * function to extract the value * @param labelConverter * the label converter * @return the column instance itself */ public static <S, T> TableColumn<S, T> setupColumn(TableColumn<S, T> c, Function<S, T> valueExtractor, Function<T, @NonNull CharSequence> labelConverter) { c.setCellValueFactory(f -> new SimpleObjectProperty<>(valueExtractor.apply(f.getValue()))); c.setCellFactory(cc -> new TableCell<S, T>() { @Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setText(""); //$NON-NLS-1$ setGraphic(null); } else { setText(labelConverter.apply(item).toString()); } } }); return c; }
doneColumn.setMaxWidth(40); doneColumn.setMinWidth(40); doneColumn.setCellValueFactory(cdf -> cdf.getValue().pDone());
public static <T> List<TableColumn<T, ?>> createColumns(Class<T> entityType, ExceptionHandler exceptionHandler) { List<TableColumn<T, ?>> columns = new ArrayList<>(); for (Field field : entityType.getDeclaredFields()) { ViewColumn columnAnnotation = field.getAnnotation(ViewColumn.class); if (columnAnnotation != null) { TableColumn<T, ?> column = new TableColumn<>(); column.setText(columnAnnotation.value()); column.setEditable(columnAnnotation.editable()); column.setSortable(columnAnnotation.sortable()); column.setResizable(columnAnnotation.resizeable()); column.setCellValueFactory(e -> { try { return new SimpleObjectProperty(DataFXUtils.getPrivileged(field, e.getValue())); } catch (Exception exception) { exceptionHandler.setException(exception); return null; } }); columns.add(column); } } return columns; } }
public static <T> List<TableColumn<T, ?>> createColumns(Class<T> entityType, ExceptionHandler exceptionHandler) { List<TableColumn<T, ?>> columns = new ArrayList<>(); for (Field field : entityType.getDeclaredFields()) { ViewColumn columnAnnotation = field.getAnnotation(ViewColumn.class); if (columnAnnotation != null) { TableColumn<T, ?> column = new TableColumn<>(); column.setText(columnAnnotation.value()); column.setEditable(columnAnnotation.editable()); column.setSortable(columnAnnotation.sortable()); column.setResizable(columnAnnotation.resizeable()); column.setCellValueFactory(e -> { try { return new SimpleObjectProperty(DataFXUtils.getPrivileged(field, e.getValue())); } catch (Exception exception) { exceptionHandler.setException(exception); return null; } }); columns.add(column); } } return columns; } }
/** * Create a row expander column that can be added to the TableView list of columns. * * The expandedNodeCallback is expected to return a Node representing the editor that should appear below the * table row when the toggle button within the expander column is clicked. * * Once this column is assigned to a TableView, it will automatically install a custom row factory for the TableView * so that it can configure a TableRow with the {@link ExpandableTableRowSkin}. It is within the skin that the actual * rendering of the expanded node occurs. * * @see TableRowExpanderColumn * @see TableRowDataFeatures * * @param expandedNodeCallback */ public TableRowExpanderColumn(Callback<TableRowDataFeatures<S>, Node> expandedNodeCallback) { this.expandedNodeCallback = expandedNodeCallback; getStyleClass().add(STYLE_CLASS); setCellValueFactory(param -> getExpandedProperty(param.getValue())); setCellFactory(param -> new ToggleCell()); installRowFactoryOnTableViewAssignment(); }
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; import javafx.scene.control.CheckBox; import javafx.scene.control.TableColumn; import javafx.util.Callback; public class PersonUnemployedValueFactory implements Callback, ObservableValue> { @Override public ObservableValue call(TableColumn.CellDataFeatures param) { Person person = param.getValue(); CheckBox checkBox = new CheckBox(); checkBox.selectedProperty().setValue(person.isUnemployed()); checkBox.selectedProperty().addListener((ov, old_val, new_val) -> { person.setUnemployed(new_val); }); return new SimpleObjectProperty(checkBox); } }
/** * Create a row expander column that can be added to the TableView list of columns. * * The expandedNodeCallback is expected to return a Node representing the editor that should appear below the * table row when the toggle button within the expander column is clicked. * * Once this column is assigned to a TableView, it will automatically install a custom row factory for the TableView * so that it can configure a TableRow with the {@link impl.org.controlsfx.skin.ExpandableTableRowSkin}. It is within the skin that the actual * rendering of the expanded node occurs. * * @see TableRowExpanderColumn * @see TableRowDataFeatures * * @param expandedNodeCallback */ public TableRowExpanderColumn(Callback<TableRowDataFeatures<S>, Node> expandedNodeCallback) { this.expandedNodeCallback = expandedNodeCallback; getStyleClass().add(STYLE_CLASS); setCellValueFactory(param -> getExpandedProperty(param.getValue())); setCellFactory(param -> new ToggleCell()); installRowFactoryOnTableViewAssignment(); }