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);
}
}
};
}
});
}
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;
}
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);
}
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);
}
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;
}
Aggregations