Search in sources :

Example 1 with PVTableItem

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;
}
Also used : HBox(javafx.scene.layout.HBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) TableColumn(javafx.scene.control.TableColumn) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) Button(javafx.scene.control.Button) VBox(javafx.scene.layout.VBox)

Example 2 with PVTableItem

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;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) LineNumberTableCellFactory(org.csstudio.javafx.LineNumberTableCellFactory) VBox(javafx.scene.layout.VBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) TableHelper(org.csstudio.javafx.TableHelper) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TableView(javafx.scene.control.TableView) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) Pane(javafx.scene.layout.Pane) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) SplitPane(javafx.scene.control.SplitPane) TextField(javafx.scene.control.TextField) Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Collectors(java.util.stream.Collectors) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Region(javafx.scene.layout.Region) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) ObservableList(javafx.collections.ObservableList) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) StringProperty(javafx.beans.property.StringProperty) ExpressionInfo(org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) ExprInfoValue(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoValue) Plugin.logger(org.csstudio.display.builder.editor.Plugin.logger) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) FXCollections(javafx.collections.FXCollections) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) Messages(org.csstudio.display.builder.representation.javafx.Messages) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ScriptsDialog(org.csstudio.display.builder.representation.javafx.ScriptsDialog) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) ChangeListener(javafx.beans.value.ChangeListener) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) Node(javafx.scene.Node) Label(javafx.scene.control.Label) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) SplitPane(javafx.scene.control.SplitPane) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) Preferences(java.util.prefs.Preferences) CheckBox(javafx.scene.control.CheckBox) Region(javafx.scene.layout.Region) VBox(javafx.scene.layout.VBox)

Aggregations

Button (javafx.scene.control.Button)2 Label (javafx.scene.control.Label)2 TableColumn (javafx.scene.control.TableColumn)2 Tooltip (javafx.scene.control.Tooltip)2 HBox (javafx.scene.layout.HBox)2 VBox (javafx.scene.layout.VBox)2 ExprInfoString (org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString)2 PVTableItem (org.csstudio.display.builder.representation.javafx.PVTableItem)2 AutoCompletedTableCell (org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Level (java.util.logging.Level)1 BackingStoreException (java.util.prefs.BackingStoreException)1 Preferences (java.util.prefs.Preferences)1 Collectors (java.util.stream.Collectors)1 Platform (javafx.application.Platform)1 BooleanProperty (javafx.beans.property.BooleanProperty)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1