use of javafx.scene.control.SplitMenuButton in project org.csstudio.display.builder by kasemir.
the class ScriptsDialog method createScriptsTable.
/**
* @return Node for UI elements that edit the scripts
*/
private Region createScriptsTable() {
scripts_icon_col = new TableColumn<>();
scripts_icon_col.setCellValueFactory(cdf -> new SimpleObjectProperty<ImageView>(getScriptImage(cdf.getValue())) {
{
bind(Bindings.createObjectBinding(() -> getScriptImage(cdf.getValue()), cdf.getValue().fileProperty()));
}
});
scripts_icon_col.setCellFactory(col -> new TableCell<ScriptItem, ImageView>() {
/* Instance initializer. */
{
setAlignment(Pos.CENTER_LEFT);
}
@Override
protected void updateItem(final ImageView item, final boolean empty) {
super.updateItem(item, empty);
super.setGraphic(item);
}
});
scripts_icon_col.setEditable(false);
scripts_icon_col.setSortable(false);
scripts_icon_col.setMaxWidth(25);
scripts_icon_col.setMinWidth(25);
// Create table with editable script 'file' column
scripts_name_col = new TableColumn<>(Messages.ScriptsDialog_ColScript);
scripts_name_col.setCellValueFactory(new PropertyValueFactory<ScriptItem, String>("file"));
scripts_name_col.setCellFactory(col -> new TextFieldTableCell<ScriptItem, 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 startEdit() {
super.startEdit();
((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
}
@Override
public void commitEdit(final String newValue) {
((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
super.commitEdit(newValue);
Platform.runLater(() -> btn_pv_add.requestFocus());
}
});
scripts_name_col.setOnEditCommit(event -> {
final int row = event.getTablePosition().getRow();
script_items.get(row).file.set(event.getNewValue());
fixupScripts(row);
});
scripts_table = new TableView<>(script_items);
scripts_table.getColumns().add(scripts_icon_col);
scripts_table.getColumns().add(scripts_name_col);
scripts_table.setEditable(true);
scripts_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
scripts_table.setTooltip(new Tooltip(Messages.ScriptsDialog_ScriptsTT));
scripts_table.setPlaceholder(new Label(Messages.ScriptsDialog_NoScripts));
// Buttons
addMenuButton = new MenuButton(Messages.Add, JFXUtil.getIcon("add.png"), new MenuItem(Messages.AddPythonFile, JFXUtil.getIcon("file-python.png")) {
{
setOnAction(e -> addPythonFile());
}
}, new MenuItem(Messages.AddJavaScriptFile, JFXUtil.getIcon("file-javascript.png")) {
{
setOnAction(e -> addJavaScriptFile());
}
}, new SeparatorMenuItem(), new MenuItem(Messages.AddEmbeddedPython, JFXUtil.getIcon("python.png")) {
{
setOnAction(e -> addEmbeddedJython());
}
}, new MenuItem(Messages.AddEmbeddedJavaScript, JFXUtil.getIcon("javascript.png")) {
{
setOnAction(e -> addEmbeddedJavaScript());
}
});
addMenuButton.setMaxWidth(Double.MAX_VALUE);
addMenuButton.setAlignment(Pos.CENTER_LEFT);
btn_script_remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
btn_script_remove.setMaxWidth(Double.MAX_VALUE);
btn_script_remove.setAlignment(Pos.CENTER_LEFT);
btn_script_remove.setDisable(true);
btn_script_remove.setOnAction(event -> {
final int sel = scripts_table.getSelectionModel().getSelectedIndex();
if (sel >= 0) {
script_items.remove(sel);
fixupScripts(sel);
}
});
btn_edit = new SplitMenuButton(convertToFileMenuItem, new SeparatorMenuItem(), convertToEmbeddedPythonMenuItem, convertToEmbeddedJavaScriptMenuItem);
btn_edit.setText(Messages.Select);
btn_edit.setGraphic(JFXUtil.getIcon("select-file.png"));
btn_edit.setMaxWidth(Double.MAX_VALUE);
btn_edit.setMinWidth(120);
btn_edit.setAlignment(Pos.CENTER_LEFT);
btn_edit.setDisable(true);
btn_edit.setOnAction(e -> editOrSelect());
final VBox buttons = new VBox(10, addMenuButton, btn_script_remove, btn_edit);
final HBox content = new HBox(10, scripts_table, buttons);
HBox.setHgrow(scripts_table, Priority.ALWAYS);
HBox.setHgrow(buttons, Priority.NEVER);
return content;
}
Aggregations