Search in sources :

Example 1 with AutoCompletedTableCell

use of org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell 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 AutoCompletedTableCell

use of org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell in project org.csstudio.display.builder by kasemir.

the class ScriptsDialog method createPVsTable.

/**
 * @return Node for UI elements that edit the PVs of a script
 */
private Region 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
    pvs_name_col = new TableColumn<>(Messages.ScriptsDialog_ColPV);
    pvs_name_col.setSortable(false);
    pvs_name_col.setCellValueFactory(new PropertyValueFactory<PVTableItem, String>("name"));
    pvs_name_col.setCellFactory((col) -> new AutoCompletedTableCell(menu, btn_pv_add));
    pvs_name_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        pv_items.get(row).nameProperty().set(event.getNewValue());
        fixupPVs(row);
    });
    pvs_trigger_col = new TableColumn<>(Messages.ScriptsDialog_ColTrigger);
    pvs_trigger_col.setSortable(false);
    pvs_trigger_col.setCellValueFactory(new PropertyValueFactory<PVTableItem, Boolean>("trigger"));
    pvs_trigger_col.setCellFactory(CheckBoxTableCell.<PVTableItem>forTableColumn(pvs_trigger_col));
    pvs_trigger_col.setResizable(false);
    pvs_trigger_col.setMaxWidth(70);
    pvs_trigger_col.setMinWidth(70);
    // Table column for 'trigger' uses CheckBoxTableCell that directly modifies the Observable Property
    pvs_table = new TableView<>(pv_items);
    pvs_table.getColumns().add(indexColumn);
    pvs_table.getColumns().add(pvs_name_col);
    pvs_table.getColumns().add(pvs_trigger_col);
    pvs_table.setEditable(true);
    pvs_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    pvs_table.setTooltip(new Tooltip(Messages.ScriptsDialog_PVsTT));
    pvs_table.setPlaceholder(new Label(Messages.ScriptsDialog_NoPVs));
    // Buttons
    btn_pv_add = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
    btn_pv_add.setMaxWidth(Double.MAX_VALUE);
    btn_pv_add.setAlignment(Pos.CENTER_LEFT);
    btn_pv_add.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, pvs_name_col));
        }, 123, TimeUnit.MILLISECONDS);
    });
    btn_pv_remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    btn_pv_remove.setMaxWidth(Double.MAX_VALUE);
    btn_pv_remove.setMinWidth(96);
    btn_pv_remove.setAlignment(Pos.CENTER_LEFT);
    btn_pv_remove.setDisable(true);
    btn_pv_remove.setOnAction(event -> {
        final int sel = pvs_table.getSelectionModel().getSelectedIndex();
        if (sel >= 0) {
            pv_items.remove(sel);
            fixupPVs(sel);
        }
    });
    btn_pv_up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
    btn_pv_up.setMaxWidth(Double.MAX_VALUE);
    btn_pv_up.setAlignment(Pos.CENTER_LEFT);
    btn_pv_up.setDisable(true);
    btn_pv_up.setOnAction(event -> TableHelper.move_item_up(pvs_table, pv_items));
    btn_py_down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
    btn_py_down.setMaxWidth(Double.MAX_VALUE);
    btn_py_down.setAlignment(Pos.CENTER_LEFT);
    btn_py_down.setDisable(true);
    btn_py_down.setOnAction(event -> TableHelper.move_item_down(pvs_table, pv_items));
    btn_check_connections = new CheckBox(Messages.ScriptsDialog_CheckConnections);
    btn_check_connections.setSelected(true);
    btn_check_connections.setOnAction(event -> {
        selected_script_item.check_connections = btn_check_connections.isSelected();
    });
    final VBox buttons = new VBox(10, btn_pv_add, btn_pv_remove, btn_pv_up, btn_py_down);
    final HBox pvs_buttons = new HBox(10, pvs_table, buttons);
    HBox.setHgrow(pvs_table, Priority.ALWAYS);
    HBox.setHgrow(buttons, Priority.NEVER);
    final VBox content = new VBox(10, pvs_buttons, btn_check_connections);
    VBox.setVgrow(pvs_buttons, Priority.ALWAYS);
    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) TableColumn(javafx.scene.control.TableColumn) Button(javafx.scene.control.Button) MenuButton(javafx.scene.control.MenuButton) SplitMenuButton(javafx.scene.control.SplitMenuButton) CheckBox(javafx.scene.control.CheckBox) 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 AutoCompletedTableCell (org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell)2 CheckBox (javafx.scene.control.CheckBox)1 MenuButton (javafx.scene.control.MenuButton)1 SplitMenuButton (javafx.scene.control.SplitMenuButton)1 ExprInfoString (org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString)1 PVTableItem (org.csstudio.display.builder.representation.javafx.PVTableItem)1