Search in sources :

Example 1 with SyntaxHighlightedMultiLineInputDialog

use of org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog in project org.csstudio.display.builder by kasemir.

the class RulesDialog method createRulesTable.

/**
 * @return Node for UI elements that edit the rules
 */
private Node createRulesTable() {
    // Create table with editable rule 'name' column
    final TableColumn<RuleItem, String> name_col = new TableColumn<>(Messages.RulesDialog_ColName);
    name_col.setCellValueFactory(new PropertyValueFactory<RuleItem, String>("name"));
    name_col.setCellFactory(list -> new TextFieldTableCell<RuleItem, String>(new DefaultStringConverter()) {

        private final ChangeListener<? super Boolean> focusedListener = (ob, o, n) -> {
            if (!n)
                cancelEdit();
        };

        @Override
        public void cancelEdit() {
            ((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
            super.cancelEdit();
        }

        @Override
        public void commitEdit(final String newValue) {
            ((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
            super.commitEdit(newValue);
            Platform.runLater(() -> btn_add_pv.requestFocus());
        }

        @Override
        public void startEdit() {
            super.startEdit();
            ((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
        }
    });
    name_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        rule_items.get(row).name.set(event.getNewValue());
        fixupRules(row);
    });
    rules_table = new TableView<>(rule_items);
    rules_table.getColumns().add(name_col);
    rules_table.setEditable(true);
    rules_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    rules_table.setTooltip(new Tooltip(Messages.RulesDialog_RulesTT));
    rules_table.setPlaceholder(new Label(Messages.RulesDialog_NoRules));
    // Buttons
    btn_add_rule = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
    btn_add_rule.setMaxWidth(Double.MAX_VALUE);
    btn_add_rule.setAlignment(Pos.CENTER_LEFT);
    btn_add_rule.setOnAction(event -> {
        final RuleItem newItem = new RuleItem(attached_widget, selected_rule_item == null ? ((propinfo_ls.size() == 0) ? "" : propinfo_ls.get(0).getPropID()) : selected_rule_item.prop_id.get());
        rule_items.add(newItem);
        rules_table.getSelectionModel().select(newItem);
        final int newRow = rules_table.getSelectionModel().getSelectedIndex();
        ModelThreadPool.getTimer().schedule(() -> {
            Platform.runLater(() -> rules_table.edit(newRow, name_col));
        }, 123, TimeUnit.MILLISECONDS);
    });
    btn_remove_rule = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    btn_remove_rule.setMaxWidth(Double.MAX_VALUE);
    btn_remove_rule.setAlignment(Pos.CENTER_LEFT);
    btn_remove_rule.setDisable(true);
    btn_remove_rule.setOnAction(event -> {
        final int sel = rules_table.getSelectionModel().getSelectedIndex();
        if (sel >= 0) {
            rule_items.remove(sel);
            fixupRules(sel);
        }
    });
    btn_move_rule_up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
    btn_move_rule_up.setMaxWidth(Double.MAX_VALUE);
    btn_move_rule_up.setAlignment(Pos.CENTER_LEFT);
    btn_move_rule_up.setDisable(true);
    btn_move_rule_up.setOnAction(event -> TableHelper.move_item_up(rules_table, rule_items));
    btn_move_rule_down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
    btn_move_rule_down.setMaxWidth(Double.MAX_VALUE);
    btn_move_rule_down.setAlignment(Pos.CENTER_LEFT);
    btn_move_rule_down.setDisable(true);
    btn_move_rule_down.setOnAction(event -> TableHelper.move_item_down(rules_table, rule_items));
    btn_dup_rule = new Button(Messages.Duplicate, JFXUtil.getIcon("file-duplicate.png"));
    btn_dup_rule.setMaxWidth(Double.MAX_VALUE);
    btn_dup_rule.setAlignment(Pos.CENTER_LEFT);
    btn_dup_rule.setDisable(true);
    btn_dup_rule.setOnAction(event -> {
        if (selected_rule_item != null) {
            final RuleItem newItem = RuleItem.forInfo(attached_widget, selected_rule_item.getRuleInfo(), undo);
            if (!newItem.nameProperty().get().endsWith(" (duplicate)"))
                newItem.nameProperty().set(newItem.nameProperty().get() + " (duplicate)");
            rule_items.add(newItem);
            rules_table.getSelectionModel().select(newItem);
            final int newRow = rules_table.getSelectionModel().getSelectedIndex();
            ModelThreadPool.getTimer().schedule(() -> {
                Platform.runLater(() -> rules_table.edit(newRow, name_col));
            }, 123, TimeUnit.MILLISECONDS);
        }
    });
    btn_show_script = new Button(Messages.RulesDialog_ShowScript, JFXUtil.getIcon("file.png"));
    btn_show_script.setMaxWidth(Double.MAX_VALUE);
    btn_show_script.setMinWidth(120);
    btn_dup_rule.setAlignment(Pos.CENTER_LEFT);
    btn_show_script.setDisable(true);
    btn_show_script.setOnAction(event -> {
        final int sel = rules_table.getSelectionModel().getSelectedIndex();
        if (sel >= 0) {
            final String content = rule_items.get(sel).getRuleInfo().getTextPy(attached_widget);
            final SyntaxHighlightedMultiLineInputDialog dialog = new SyntaxHighlightedMultiLineInputDialog(btn_show_script, content, Language.Python, false);
            DialogHelper.positionDialog(dialog, btn_show_script, -200, -300);
            dialog.setTextHeight(600);
            dialog.show();
        }
    });
    final VBox buttons = new VBox(10, btn_add_rule, btn_remove_rule, btn_move_rule_up, btn_move_rule_down, new Pane(), btn_dup_rule, btn_show_script);
    final HBox content = new HBox(10, rules_table, buttons);
    HBox.setHgrow(rules_table, Priority.ALWAYS);
    HBox.setHgrow(buttons, Priority.NEVER);
    return content;
}
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) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) TableColumn(javafx.scene.control.TableColumn) Pane(javafx.scene.layout.Pane) SplitPane(javafx.scene.control.SplitPane) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) Button(javafx.scene.control.Button) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) TextField(javafx.scene.control.TextField) VBox(javafx.scene.layout.VBox)

Example 2 with SyntaxHighlightedMultiLineInputDialog

use of org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog in project org.csstudio.display.builder by kasemir.

the class ScriptsDialog method add.

private void add(final String file, final String text) {
    final ScriptItem newItem = new ScriptItem(file, text, true, new ArrayList<>());
    script_items.add(newItem);
    scripts_table.getSelectionModel().select(newItem);
    final int newRow = scripts_table.getSelectionModel().getSelectedIndex();
    ModelThreadPool.getTimer().schedule(() -> {
        if (ScriptInfo.isEmbedded(file)) {
            Platform.runLater(() -> {
                final Language language = ScriptInfo.isJython(selected_script_item.getScriptInfo().getPath()) ? Language.Python : Language.JavaScript;
                final SyntaxHighlightedMultiLineInputDialog dlg = new SyntaxHighlightedMultiLineInputDialog(scripts_table, selected_script_item.text, language);
                DialogHelper.positionDialog(dlg, btn_edit, -300, -200);
                dlg.showAndWait().ifPresent(result -> selected_script_item.text = result);
            });
        } else
            Platform.runLater(() -> scripts_table.edit(newRow, scripts_name_col));
    }, 123, TimeUnit.MILLISECONDS);
}
Also used : Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog)

Example 3 with SyntaxHighlightedMultiLineInputDialog

use of org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog in project org.csstudio.display.builder by kasemir.

the class ScriptsDialog method editOrSelect.

private void editOrSelect() {
    if (Messages.Select.equals(btn_edit.getText())) {
        try {
            // Use the script file name, except if that's the example name,
            // because it doesn't exist and file dialog will then start
            // in some random directory instead of the display file's dir.
            String initial = selected_script_item.file.get();
            if (Messages.ScriptsDialog_DefaultScriptFile.equals(initial))
                initial = "";
            final String path = FilenameSupport.promptForRelativePath(widget, initial);
            if (path != null) {
                selected_script_item.file.set(path);
                selected_script_item.text = null;
            }
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Cannot prompt for filename", ex);
        }
        FilenameSupport.performMostAwfulTerribleNoGoodHack(scripts_table);
    } else {
        final Language language = ScriptInfo.isJython(selected_script_item.getScriptInfo().getPath()) ? Language.Python : Language.JavaScript;
        final SyntaxHighlightedMultiLineInputDialog dlg = new SyntaxHighlightedMultiLineInputDialog(btn_edit, selected_script_item.text, language);
        DialogHelper.positionDialog(dlg, btn_edit, -300, -200);
        dlg.showAndWait().ifPresent(result -> selected_script_item.text = result);
    }
}
Also used : Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) BackingStoreException(java.util.prefs.BackingStoreException)

Aggregations

SyntaxHighlightedMultiLineInputDialog (org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog)3 Language (org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language)3 BackingStoreException (java.util.prefs.BackingStoreException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Level (java.util.logging.Level)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 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 StringProperty (javafx.beans.property.StringProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 FXCollections (javafx.collections.FXCollections)1 ListChangeListener (javafx.collections.ListChangeListener)1 ObservableList (javafx.collections.ObservableList)1 Insets (javafx.geometry.Insets)1