use of eu.fthevenet.util.javafx.controls.DecimalFormatTableCellFactory in project selenium_java by sergueik.
the class WorksheetController method initTableViewPane.
private void initTableViewPane() {
for (ChartViewPort<Double> currentViewPort : viewPorts) {
currentViewPort.getSeriesTable().getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
CheckBox showAllCheckBox = new CheckBox();
TableColumn<TimeSeriesInfo<Double>, Boolean> visibleColumn = new TableColumn<>();
visibleColumn.setGraphic(showAllCheckBox);
visibleColumn.setSortable(false);
visibleColumn.setResizable(false);
visibleColumn.setPrefWidth(32);
InvalidationListener isVisibleListener = (observable) -> {
boolean andAll = true;
boolean orAll = false;
for (TimeSeriesInfo<?> t : currentViewPort.getDataStore().getSeries()) {
andAll &= t.isSelected();
orAll |= t.isSelected();
}
showAllCheckBox.setIndeterminate(Boolean.logicalXor(andAll, orAll));
showAllCheckBox.setSelected(andAll);
};
ChangeListener<Boolean> refreshListener = (observable, oldValue, newValue) -> {
if (worksheet.getChartLayout() == ChartLayout.OVERLAID) {
invalidateAll(false, false, false);
} else {
invalidate(currentViewPort, false, false);
}
};
currentViewPort.getDataStore().getSeries().forEach(doubleTimeSeriesInfo -> {
bindingManager.attachListener(doubleTimeSeriesInfo.selectedProperty(), refreshListener);
bindingManager.attachListener(doubleTimeSeriesInfo.selectedProperty(), isVisibleListener);
// Explicitly call the listener to initialize the proper status of the checkbox
isVisibleListener.invalidated(null);
});
visibleColumn.setCellValueFactory(p -> p.getValue().selectedProperty());
visibleColumn.setCellFactory(CheckBoxTableCell.forTableColumn(visibleColumn));
showAllCheckBox.setOnAction(event -> {
ChangeListener<Boolean> r = (observable, oldValue, newValue) -> {
if (worksheet.getChartLayout() == ChartLayout.OVERLAID) {
invalidateAll(false, false, false);
} else {
invalidate(currentViewPort, false, false);
}
};
boolean b = ((CheckBox) event.getSource()).isSelected();
currentViewPort.getDataStore().getSeries().forEach(s -> bindingManager.detachAllChangeListeners(s.selectedProperty()));
currentViewPort.getDataStore().getSeries().forEach(t -> t.setSelected(b));
r.changed(null, null, null);
currentViewPort.getDataStore().getSeries().forEach(s -> bindingManager.attachListener(s.selectedProperty(), r));
});
DecimalFormatTableCellFactory<TimeSeriesInfo<Double>, String> alignRightCellFactory = new DecimalFormatTableCellFactory<>();
alignRightCellFactory.setAlignment(TextAlignment.RIGHT);
TableColumn<TimeSeriesInfo<Double>, Color> colorColumn = new TableColumn<>();
colorColumn.setSortable(false);
colorColumn.setResizable(false);
colorColumn.setPrefWidth(32);
TableColumn<TimeSeriesInfo<Double>, Boolean> nameColumn = new TableColumn<>("Name");
nameColumn.setSortable(false);
nameColumn.setPrefWidth(160);
nameColumn.setCellValueFactory(new PropertyValueFactory<>("displayName"));
TableColumn<TimeSeriesInfo<Double>, String> minColumn = new TableColumn<>("Min.");
minColumn.setSortable(false);
minColumn.setPrefWidth(75);
minColumn.setCellFactory(alignRightCellFactory);
TableColumn<TimeSeriesInfo<Double>, String> maxColumn = new TableColumn<>("Max.");
maxColumn.setSortable(false);
maxColumn.setPrefWidth(75);
maxColumn.setCellFactory(alignRightCellFactory);
TableColumn<TimeSeriesInfo<Double>, String> avgColumn = new TableColumn<>("Avg.");
avgColumn.setSortable(false);
avgColumn.setPrefWidth(75);
avgColumn.setCellFactory(alignRightCellFactory);
TableColumn<TimeSeriesInfo<Double>, String> currentColumn = new TableColumn<>("Current");
currentColumn.setSortable(false);
currentColumn.setPrefWidth(75);
currentColumn.setCellFactory(alignRightCellFactory);
currentColumn.getStyleClass().add("column-bold-text");
TableColumn<TimeSeriesInfo<Double>, String> pathColumn = new TableColumn<>("Path");
pathColumn.setSortable(false);
pathColumn.setPrefWidth(400);
currentColumn.setVisible(crossHair.isVerticalMarkerVisible());
bindingManager.attachListener(crossHair.verticalMarkerVisibleProperty(), (ChangeListener<Boolean>) (observable, oldValue, newValue) -> currentColumn.setVisible(newValue));
pathColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getBinding().getTreeHierarchy()));
colorColumn.setCellFactory(param -> new ColorTableCell<>(colorColumn));
colorColumn.setCellValueFactory(p -> p.getValue().displayColorProperty());
avgColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> p.getValue().getProcessor() == null ? "NaN" : currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().getAverageValue()), p.getValue().processorProperty()));
minColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> p.getValue().getProcessor() == null ? "NaN" : currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().getMinValue()), p.getValue().processorProperty()));
maxColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> p.getValue().getProcessor() == null ? "NaN" : currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().getMaxValue()), p.getValue().processorProperty()));
currentColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> {
if (p.getValue().getProcessor() == null) {
return "NaN";
}
return currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().tryGetNearestValue(crossHair.getCurrentXValue()).orElse(Double.NaN));
}, crossHair.currentXValueProperty()));
currentViewPort.getSeriesTable().setRowFactory(this::seriesTableRowFactory);
currentViewPort.getSeriesTable().setOnKeyReleased(event -> {
if (event.getCode().equals(KeyCode.DELETE)) {
removeSelectedBinding((TableView<TimeSeriesInfo<Double>>) event.getSource());
}
});
currentViewPort.getSeriesTable().setItems(currentViewPort.getDataStore().getSeries());
currentViewPort.getSeriesTable().getColumns().addAll(visibleColumn, colorColumn, nameColumn, minColumn, maxColumn, avgColumn, currentColumn, pathColumn);
TitledPane newPane = new TitledPane(currentViewPort.getDataStore().getName(), currentViewPort.getSeriesTable());
newPane.setOnDragOver(this::handleDragOverWorksheetView);
newPane.setOnDragDropped(this::handleDragDroppedOnWorksheetView);
newPane.setUserData(currentViewPort);
GridPane titleRegion = new GridPane();
titleRegion.setHgap(5);
titleRegion.getColumnConstraints().add(new ColumnConstraints(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, Priority.ALWAYS, HPos.LEFT, true));
titleRegion.getColumnConstraints().add(new ColumnConstraints(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, Priority.NEVER, HPos.RIGHT, false));
bindingManager.bind(titleRegion.minWidthProperty(), newPane.widthProperty().subtract(30));
bindingManager.bind(titleRegion.maxWidthProperty(), newPane.widthProperty().subtract(30));
Label label = new Label();
bindingManager.bind(label.textProperty(), currentViewPort.getDataStore().nameProperty());
bindingManager.bind(label.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty().not());
HBox editFieldsGroup = new HBox();
DoubleBinding db = Bindings.createDoubleBinding(() -> editFieldsGroup.isVisible() ? USE_COMPUTED_SIZE : 0.0, editFieldsGroup.visibleProperty());
bindingManager.bind(editFieldsGroup.prefHeightProperty(), db);
bindingManager.bind(editFieldsGroup.maxHeightProperty(), db);
bindingManager.bind(editFieldsGroup.minHeightProperty(), db);
bindingManager.bind(editFieldsGroup.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty());
editFieldsGroup.setSpacing(5);
TextField chartNameField = new TextField();
chartNameField.textProperty().bindBidirectional(currentViewPort.getDataStore().nameProperty());
TextField unitNameField = new TextField();
unitNameField.textProperty().bindBidirectional(currentViewPort.getDataStore().unitProperty());
ChoiceBox<UnitPrefixes> unitPrefixChoiceBox = new ChoiceBox<>();
unitPrefixChoiceBox.getItems().setAll(UnitPrefixes.values());
unitPrefixChoiceBox.getSelectionModel().select(currentViewPort.getDataStore().getUnitPrefixes());
bindingManager.bind(currentViewPort.getDataStore().unitPrefixesProperty(), unitPrefixChoiceBox.getSelectionModel().selectedItemProperty());
HBox.setHgrow(chartNameField, Priority.ALWAYS);
titleRegion.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
chartNameField.selectAll();
chartNameField.requestFocus();
currentViewPort.getDataStore().setShowProperties(true);
}
});
editFieldsGroup.getChildren().addAll(chartNameField, unitNameField, unitPrefixChoiceBox);
// *** Toolbar ***
HBox toolbar = new HBox();
toolbar.getStyleClass().add("title-pane-tool-bar");
toolbar.setAlignment(Pos.CENTER);
Button closeButton = (Button) newToolBarButton(Button::new, "Close", "Remove this chart from the worksheet.", new String[] { "exit" }, new String[] { "cross-icon", "small-icon" });
closeButton.setOnAction(event -> {
if (Dialogs.confirmDialog(root, "Are you sure you want to remove chart \"" + currentViewPort.getDataStore().getName() + "\"?", "", ButtonType.YES, ButtonType.NO) == ButtonType.YES) {
worksheet.getCharts().remove(currentViewPort.getDataStore());
}
});
bindingManager.bind(closeButton.disableProperty(), Bindings.createBooleanBinding(() -> worksheet.getCharts().size() > 1, worksheet.getCharts()).not());
ToggleButton editButton = (ToggleButton) newToolBarButton(ToggleButton::new, "Settings", "Edit the chart's settings", new String[] { "dialog-button" }, new String[] { "settings-icon", "small-icon" });
editButton.selectedProperty().bindBidirectional(currentViewPort.getDataStore().showPropertiesProperty());
editButton.setOnAction(event -> newPane.setExpanded(true));
editButtonsGroup.getToggles().add(editButton);
Button moveUpButton = (Button) newToolBarButton(Button::new, "Up", "Move the chart up the list.", new String[] { "dialog-button" }, new String[] { "upArrow-icon", "small-icon" });
bindingManager.bind(moveUpButton.disableProperty(), Bindings.createBooleanBinding(() -> seriesTableContainer.getPanes().indexOf(newPane) == 0, seriesTableContainer.getPanes()));
bindingManager.bind(moveUpButton.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty());
moveUpButton.setOnAction(event -> {
int idx = worksheet.getCharts().indexOf(currentViewPort.getDataStore());
this.preventReload = true;
try {
worksheet.getCharts().remove(currentViewPort.getDataStore());
} finally {
this.preventReload = false;
}
worksheet.getCharts().add(idx - 1, currentViewPort.getDataStore());
});
Button moveDownButton = (Button) newToolBarButton(Button::new, "Down", "Move the chart down the list.", new String[] { "dialog-button" }, new String[] { "downArrow-icon", "small-icon" });
bindingManager.bind(moveDownButton.disableProperty(), Bindings.createBooleanBinding(() -> seriesTableContainer.getPanes().indexOf(newPane) >= seriesTableContainer.getPanes().size() - 1, seriesTableContainer.getPanes()));
bindingManager.bind(moveDownButton.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty());
moveDownButton.setOnAction(event -> {
int idx = worksheet.getCharts().indexOf(currentViewPort.getDataStore());
this.preventReload = true;
try {
worksheet.getCharts().remove(currentViewPort.getDataStore());
} finally {
this.preventReload = false;
}
worksheet.getCharts().add(idx + 1, currentViewPort.getDataStore());
});
toolbar.getChildren().addAll(moveUpButton, moveDownButton, editButton, closeButton);
titleRegion.getChildren().addAll(label, editFieldsGroup, toolbar);
HBox hBox = new HBox();
hBox.setAlignment(Pos.CENTER);
GridPane.setConstraints(label, 0, 0, 1, 1, HPos.LEFT, VPos.CENTER);
GridPane.setConstraints(toolbar, 1, 0, 1, 1, HPos.RIGHT, VPos.CENTER);
newPane.setGraphic(titleRegion);
newPane.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
newPane.setAnimated(false);
seriesTableContainer.getPanes().add(newPane);
}
Platform.runLater(() -> seriesTableContainer.getPanes().get(getWorksheet().getSelectedChart()).setExpanded(true));
bindingManager.attachListener(seriesTableContainer.expandedPaneProperty(), (ObservableValue<? extends TitledPane> observable, TitledPane oldPane, TitledPane newPane) -> {
Boolean expandRequiered = true;
for (TitledPane pane : seriesTableContainer.getPanes()) {
if (pane.isExpanded()) {
expandRequiered = false;
}
}
getAttachedViewport(newPane).ifPresent(nv -> {
getWorksheet().setSelectedChart(viewPorts.indexOf(nv));
if (editButtonsGroup.getSelectedToggle() != null) {
nv.getDataStore().setShowProperties(true);
}
});
if ((expandRequiered) && (oldPane != null)) {
getWorksheet().setSelectedChart(seriesTableContainer.getPanes().indexOf(oldPane));
Platform.runLater(() -> {
seriesTableContainer.setExpandedPane(oldPane);
});
}
});
}
Aggregations