Search in sources :

Example 41 with TableColumn

use of javafx.scene.control.TableColumn in project bisq-desktop by bisq-network.

the class FailedTradesView method setTradeIdColumnCellFactory.

private void setTradeIdColumnCellFactory() {
    tradeIdColumn.setCellValueFactory((offerListItem) -> new ReadOnlyObjectWrapper<>(offerListItem.getValue()));
    tradeIdColumn.setCellFactory(new Callback<TableColumn<FailedTradesListItem, FailedTradesListItem>, TableCell<FailedTradesListItem, FailedTradesListItem>>() {

        @Override
        public TableCell<FailedTradesListItem, FailedTradesListItem> call(TableColumn<FailedTradesListItem, FailedTradesListItem> column) {
            return new TableCell<FailedTradesListItem, FailedTradesListItem>() {

                private HyperlinkWithIcon field;

                @Override
                public void updateItem(final FailedTradesListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        field = new HyperlinkWithIcon(model.getTradeId(item));
                        field.setOnAction(event -> tradeDetailsWindow.show(item.getTrade()));
                        field.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails")));
                        setGraphic(field);
                    } else {
                        setGraphic(null);
                        if (field != null)
                            field.setOnAction(null);
                    }
                }
            };
        }
    });
}
Also used : TradeDetailsWindow(bisq.desktop.main.overlays.windows.TradeDetailsWindow) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) VBox(javafx.scene.layout.VBox) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) FXML(javafx.fxml.FXML) TableCell(javafx.scene.control.TableCell) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) Res(bisq.core.locale.Res) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) SortedList(javafx.collections.transformation.SortedList) TableCell(javafx.scene.control.TableCell) Tooltip(javafx.scene.control.Tooltip) TableColumn(javafx.scene.control.TableColumn) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon)

Example 42 with TableColumn

use of javafx.scene.control.TableColumn 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 43 with TableColumn

use of javafx.scene.control.TableColumn in project org.csstudio.display.builder by kasemir.

the class WidgetInfoDialog method createProperties.

private Tab createProperties(final Widget widget) {
    // Use text field to allow copying the name (for use in scripts)
    // and value, but not the localized description and category
    // which are just for information
    final TableColumn<WidgetProperty<?>, String> cat = new TableColumn<>(Messages.WidgetInfoDialog_Category);
    cat.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getCategory().getDescription()));
    final TableColumn<WidgetProperty<?>, String> descr = new TableColumn<>(Messages.WidgetInfoDialog_Property);
    descr.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getDescription()));
    final TableColumn<WidgetProperty<?>, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(TextFieldTableCell.forTableColumn());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getName()));
    final TableColumn<WidgetProperty<?>, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(TextFieldTableCell.forTableColumn());
    value.setCellValueFactory(param -> new ReadOnlyStringWrapper(Objects.toString(param.getValue().getValue())));
    final TableView<WidgetProperty<?>> table = new TableView<>(FXCollections.observableArrayList(widget.getProperties()));
    table.getColumns().add(cat);
    table.getColumns().add(descr);
    table.getColumns().add(name);
    table.getColumns().add(value);
    table.setEditable(true);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return new Tab(Messages.WidgetInfoDialog_TabProperties, table);
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) Tab(javafx.scene.control.Tab) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Example 44 with TableColumn

use of javafx.scene.control.TableColumn in project org.csstudio.display.builder by kasemir.

the class WidgetInfoDialog method createPVs.

private Tab createPVs(final Collection<NameStateValue> pvs) {
    // Use text field to allow users to copy the name, value to clipboard
    final TableColumn<NameStateValue, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(TextFieldTableCell.forTableColumn());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().name));
    final TableColumn<NameStateValue, String> state = new TableColumn<>(Messages.WidgetInfoDialog_State);
    state.setCellFactory(TextFieldTableCell.forTableColumn());
    state.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().state));
    final TableColumn<NameStateValue, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(TextFieldTableCell.forTableColumn());
    value.setCellValueFactory(param -> {
        String text;
        final VType vtype = param.getValue().value;
        if (vtype == null)
            text = Messages.WidgetInfoDialog_Disconnected;
        else {
            // so only show the basic type info
            if (vtype instanceof VNumberArray)
                text = vtype.toString();
            else
                text = VTypeUtil.getValueString(vtype, true);
            if (vtype instanceof Alarm) {
                final Alarm alarm = (Alarm) vtype;
                if (alarm.getAlarmSeverity() != AlarmSeverity.NONE)
                    text = text + " [" + alarm.getAlarmSeverity().toString() + ", " + alarm.getAlarmName() + "]";
            }
        }
        return new ReadOnlyStringWrapper(text);
    });
    final ObservableList<NameStateValue> pv_data = FXCollections.observableArrayList(pvs);
    pv_data.sort((a, b) -> a.name.compareTo(b.name));
    final TableView<NameStateValue> table = new TableView<>(pv_data);
    table.getColumns().add(name);
    table.getColumns().add(state);
    table.getColumns().add(value);
    table.setEditable(true);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return new Tab(Messages.WidgetInfoDialog_TabPVs, table);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VType(org.diirt.vtype.VType) Tab(javafx.scene.control.Tab) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) Alarm(org.diirt.vtype.Alarm) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Example 45 with TableColumn

use of javafx.scene.control.TableColumn in project org.csstudio.display.builder by kasemir.

the class PointsTable method create.

/**
 * @return Top-level {@link Node}
 */
public Node create() {
    // Layout:
    // 
    // | table |  [Add]
    // | table |  [Remove]
    // | table |
    // | table |
    // Create table with editable columns for type Double (supported as Number)
    final TableColumn<Point, Number> x_col = new TableColumn<>(Messages.PointsTable_X);
    x_col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {

        @Override
        public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getX());
        }
    });
    x_col.setCellFactory(TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    x_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        points.setX(row, event.getNewValue().doubleValue());
    });
    final TableColumn<Point, Number> y_col = new TableColumn<>(Messages.PointsTable_Y);
    y_col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {

        @Override
        public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getY());
        }
    });
    y_col.setCellFactory(TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    y_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        points.setY(row, event.getNewValue().doubleValue());
    });
    final ObservableList<Point> data = new PointsAdapter(points);
    final TableView<Point> table = new TableView<>(data);
    table.getColumns().add(x_col);
    table.getColumns().add(y_col);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.setPlaceholder(new Label(Messages.PointsTable_Empty));
    table.setEditable(true);
    // Buttons
    final Button add = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
    add.setMaxWidth(Double.MAX_VALUE);
    add.setOnAction(event -> data.add(new Point(0, 0)));
    final Button remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    remove.setMaxWidth(Double.MAX_VALUE);
    remove.setOnAction(event -> {
        final int sel = table.getSelectionModel().getSelectedIndex();
        if (sel >= 0)
            data.remove(sel);
    });
    final Button up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
    up.setMaxWidth(Double.MAX_VALUE);
    up.setOnAction(event -> TableHelper.move_item_up(table, data));
    final Button down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
    down.setMaxWidth(Double.MAX_VALUE);
    down.setOnAction(event -> TableHelper.move_item_down(table, data));
    final VBox buttons = new VBox(10, add, remove, up, down);
    final HBox content = new HBox(10, table, buttons);
    HBox.setHgrow(table, Priority.ALWAYS);
    return content;
}
Also used : HBox(javafx.scene.layout.HBox) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableValue(javafx.beans.value.ObservableValue) Label(javafx.scene.control.Label) Point(org.csstudio.display.builder.model.properties.Point) TableColumn(javafx.scene.control.TableColumn) Point(org.csstudio.display.builder.model.properties.Point) NumberStringConverter(javafx.util.converter.NumberStringConverter) Button(javafx.scene.control.Button) VBox(javafx.scene.layout.VBox) TableView(javafx.scene.control.TableView)

Aggregations

TableColumn (javafx.scene.control.TableColumn)132 TableView (javafx.scene.control.TableView)68 TableCell (javafx.scene.control.TableCell)66 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)46 Button (javafx.scene.control.Button)44 VBox (javafx.scene.layout.VBox)41 Tooltip (javafx.scene.control.Tooltip)40 Callback (javafx.util.Callback)40 ObservableList (javafx.collections.ObservableList)39 Insets (javafx.geometry.Insets)37 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)36 Label (javafx.scene.control.Label)35 ArrayList (java.util.ArrayList)33 List (java.util.List)33 Scene (javafx.scene.Scene)32 Res (bisq.core.locale.Res)31 FxmlView (bisq.desktop.common.view.FxmlView)31 Inject (javax.inject.Inject)31 HyperlinkWithIcon (bisq.desktop.components.HyperlinkWithIcon)30 SortedList (javafx.collections.transformation.SortedList)27