use of org.csstudio.display.builder.representation.javafx.PVTableItem in project org.csstudio.display.builder by kasemir.
the class RulesDialog method createPVsTable.
/**
* @return Node for UI elements that edit the PVs of a rule
*/
private HBox createPVsTable() {
final TableColumn<PVTableItem, Integer> indexColumn = new TableColumn<>("#");
indexColumn.setEditable(false);
indexColumn.setSortable(false);
indexColumn.setCellFactory(new LineNumberTableCellFactory<>(true));
indexColumn.setMaxWidth(26);
indexColumn.setMinWidth(26);
// Create table with editable 'name' column
final TableColumn<PVTableItem, String> name_col = new TableColumn<>(Messages.ScriptsDialog_ColPV);
name_col.setSortable(false);
name_col.setCellValueFactory(new PropertyValueFactory<PVTableItem, String>("name"));
name_col.setCellFactory(col -> new AutoCompletedTableCell(menu, btn_add_pv));
name_col.setOnEditCommit(event -> {
final int row = event.getTablePosition().getRow();
pv_items.get(row).nameProperty().set(event.getNewValue());
fixupPVs(row);
});
// Table column for 'trigger' uses CheckBoxTableCell that directly
// modifies the Observable Property
final TableColumn<PVTableItem, Boolean> trigger_col = new TableColumn<>(Messages.ScriptsDialog_ColTrigger);
trigger_col.setSortable(false);
trigger_col.setCellValueFactory(new PropertyValueFactory<PVTableItem, Boolean>("trigger"));
trigger_col.setCellFactory(CheckBoxTableCell.<PVTableItem>forTableColumn(trigger_col));
trigger_col.setResizable(false);
trigger_col.setMaxWidth(70);
trigger_col.setMinWidth(70);
pvs_table = new TableView<>(pv_items);
pvs_table.getColumns().add(indexColumn);
pvs_table.getColumns().add(name_col);
pvs_table.getColumns().add(trigger_col);
pvs_table.setEditable(true);
pvs_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
pvs_table.setTooltip(new Tooltip(Messages.RulesDialog_PVsTT));
pvs_table.setPlaceholder(new Label(Messages.RulesDialog_NoPVs));
// Buttons
btn_add_pv = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
btn_add_pv.setMaxWidth(Double.MAX_VALUE);
btn_add_pv.setAlignment(Pos.CENTER_LEFT);
btn_add_pv.setOnAction(event -> {
final PVTableItem newItem = new PVTableItem("new-PV", true);
pv_items.add(newItem);
pvs_table.getSelectionModel().select(newItem);
final int newRow = pvs_table.getSelectionModel().getSelectedIndex();
ModelThreadPool.getTimer().schedule(() -> {
Platform.runLater(() -> pvs_table.edit(newRow, name_col));
}, 123, TimeUnit.MILLISECONDS);
});
btn_rm_pv = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
btn_rm_pv.setMaxWidth(Double.MAX_VALUE);
btn_rm_pv.setMinWidth(96);
btn_rm_pv.setAlignment(Pos.CENTER_LEFT);
btn_rm_pv.setDisable(true);
btn_rm_pv.setOnAction(event -> {
final int sel = pvs_table.getSelectionModel().getSelectedIndex();
if (sel >= 0) {
pv_items.remove(sel);
fixupPVs(sel);
}
});
btn_move_pv_up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
btn_move_pv_up.setMaxWidth(Double.MAX_VALUE);
btn_move_pv_up.setAlignment(Pos.CENTER_LEFT);
btn_move_pv_up.setDisable(true);
btn_move_pv_up.setOnAction(event -> TableHelper.move_item_up(pvs_table, pv_items));
btn_move_pv_down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
btn_move_pv_down.setMaxWidth(Double.MAX_VALUE);
btn_move_pv_down.setAlignment(Pos.CENTER_LEFT);
btn_move_pv_down.setDisable(true);
btn_move_pv_down.setOnAction(event -> TableHelper.move_item_down(pvs_table, pv_items));
final VBox buttons = new VBox(10, btn_add_pv, btn_rm_pv, btn_move_pv_up, btn_move_pv_down);
final HBox content = new HBox(10, pvs_table, buttons);
HBox.setHgrow(pvs_table, Priority.ALWAYS);
HBox.setHgrow(buttons, Priority.NEVER);
content.setDisable(true);
return content;
}
use of org.csstudio.display.builder.representation.javafx.PVTableItem in project org.csstudio.display.builder by kasemir.
the class RulesDialog method createContent.
private SplitPane createContent() {
final Node rules = createRulesTable();
final HBox pvs = createPVsTable();
final HBox exprs = createExpressionsTable();
// Display PVs of currently selected rule
rules_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
selected_rule_item = selected;
if (selected == null) {
pvs.setDisable(true);
exprs.setDisable(true);
btn_remove_rule.setDisable(true);
btn_dup_rule.setDisable(true);
btn_move_rule_up.setDisable(true);
btn_move_rule_down.setDisable(true);
btn_show_script.setDisable(true);
propComboBox.setDisable(true);
propComboBox.getSelectionModel().select(null);
valExpBox.setDisable(true);
pv_items.clear();
expression_items.clear();
} else {
pvs.setDisable(false);
exprs.setDisable(false);
final TableViewSelectionModel<RuleItem> model = rules_table.getSelectionModel();
btn_remove_rule.setDisable(false);
btn_dup_rule.setDisable(false);
btn_move_rule_up.setDisable(model.getSelectedIndex() == 0);
btn_move_rule_down.setDisable(model.getSelectedIndex() == rule_items.size() - 1);
btn_show_script.setDisable(false);
propComboBox.setDisable(false);
propComboBox.getSelectionModel().select(getPropLongString(selected));
valExpBox.setDisable(false);
valExpBox.selectedProperty().set(selected.prop_as_expr.get());
pv_items.setAll(selected.pvs);
expression_items.setAll(selected.expressions);
fixupPVs(0);
}
});
// Update PVs of selected rule from PVs table
final ListChangeListener<PVTableItem> pll = change -> {
final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
if (selected != null)
selected.pvs = new ArrayList<>(change.getList());
};
pv_items.addListener(pll);
// Update buttons for currently selected PV
pvs_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
if (selected == null) {
btn_rm_pv.setDisable(true);
btn_move_pv_up.setDisable(true);
btn_move_pv_down.setDisable(true);
} else {
final TableViewSelectionModel<PVTableItem> model = pvs_table.getSelectionModel();
btn_rm_pv.setDisable(false);
btn_move_pv_up.setDisable(model.getSelectedIndex() == 0);
btn_move_pv_down.setDisable(model.getSelectedIndex() == pv_items.size() - 1);
}
});
// Update Expressions of selected rule from Expressions table
final ListChangeListener<ExprItem<?>> ell = change -> {
final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
if (selected != null)
selected.expressions = new ArrayList<>(change.getList());
};
expression_items.addListener(ell);
// Update buttons for currently selected expression
expressions_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
if (selected == null) {
btn_rm_exp.setDisable(true);
btn_move_exp_up.setDisable(true);
btn_move_exp_down.setDisable(true);
} else {
final TableViewSelectionModel<ExprItem<?>> model = expressions_table.getSelectionModel();
btn_rm_exp.setDisable(false);
btn_move_exp_up.setDisable(model.getSelectedIndex() == 0);
btn_move_exp_down.setDisable(model.getSelectedIndex() == expression_items.size() - 1);
}
});
// What is the property id option we are using?
final Label propLabel = new Label("Property ID:");
// Show each property with current value
final ObservableList<String> prop_id_opts = FXCollections.observableArrayList();
for (PropInfo pi : propinfo_ls) {
// Property _value_ can be long, ex. points of a polyline
// Truncate the value that's shown in the combo box
// to prevent combo from using all screen width.
String prop_opt = pi.toString();
if (prop_opt.length() > MAX_PROP_LENGTH)
prop_opt = prop_opt.substring(0, MAX_PROP_LENGTH) + "...";
prop_id_opts.add(prop_opt);
}
propComboBox = new ComboBox<String>(prop_id_opts);
propComboBox.setDisable(true);
propComboBox.getSelectionModel().selectedIndexProperty().addListener((p, o, index) -> {
// Select property info based on index within combo.
final int idx = index.intValue();
if (idx >= 0) {
final PropInfo prop = propinfo_ls.get(idx);
if (selected_rule_item.tryUpdatePropID(undo, prop.getPropID()))
expression_items.setAll(selected_rule_item.expressions);
}
});
propComboBox.setMinHeight(27);
propComboBox.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(propComboBox, Priority.ALWAYS);
// TODO: change this to actually manipulate expression objects in the rule
valExpBox = new CheckBox("Value as Expression");
valExpBox.setDisable(true);
valExpBox.selectedProperty().addListener((ov, old_val, new_val) -> {
if (!selected_rule_item.tryTogglePropAsExpr(undo, new_val))
logger.log(Level.FINE, "Did not update rule property as expression flag to " + new_val);
else
expression_items.setAll(selected_rule_item.expressions);
});
final Region spring = new Region();
HBox.setHgrow(spring, Priority.ALWAYS);
final HBox props = new HBox(10, propLabel, propComboBox, spring, valExpBox);
props.setAlignment(Pos.CENTER);
pvs.setPadding(new Insets(0, 10, 0, 0));
exprs.setPadding(new Insets(0, 0, 0, 10));
HBox.setHgrow(pvs, Priority.ALWAYS);
HBox.setHgrow(exprs, Priority.ALWAYS);
final Preferences pref = Preferences.userNodeForPackage(RulesDialog.class);
final double prefRSPDividerPosition = pref.getDouble("rule.content.divider.position", 0.5);
ruleSplitPane = new SplitPane(pvs, exprs);
ruleSplitPane.setOrientation(Orientation.HORIZONTAL);
ruleSplitPane.setDividerPositions(prefRSPDividerPosition);
ruleSplitPane.setStyle("-fx-background-insets: 0, 0;");
VBox.setVgrow(ruleSplitPane, Priority.ALWAYS);
final VBox subitems = new VBox(10, props, ruleSplitPane);
final VBox rulebox = new VBox(10, rules);
rulebox.setPadding(new Insets(0, 10, 0, 0));
subitems.setPadding(new Insets(0, 0, 0, 10));
VBox.setVgrow(rules, Priority.ALWAYS);
HBox.setHgrow(subitems, Priority.ALWAYS);
final double prefWidth = pref.getDouble("content.width", -1);
final double prefHeight = pref.getDouble("content.height", -1);
final double prefDividerPosition = pref.getDouble("content.divider.position", 0.3);
final SplitPane splitPane = new SplitPane(rulebox, subitems);
splitPane.setOrientation(Orientation.HORIZONTAL);
splitPane.setDividerPositions(prefDividerPosition);
if (prefWidth > 0 && prefHeight > 0)
splitPane.setPrefSize(prefWidth, prefHeight);
// Select the first rule
if (!rules_table.getItems().isEmpty()) {
Platform.runLater(() -> {
rules_table.getSelectionModel().select(0);
rules_table.requestFocus();
});
} else
Platform.runLater(() -> btn_add_rule.requestFocus());
return splitPane;
}
Aggregations