use of org.csstudio.display.builder.model.properties.ActionInfos in project org.csstudio.display.builder by kasemir.
the class ActionButtonRepresentation method makeBaseButton.
// private int calls = 0;
/**
* Create <code>base</code>, either single-action button
* or menu for selecting one out of N actions
*/
private ButtonBase makeBaseButton() {
final ActionInfos actions = model_widget.propActions().getValue();
final ButtonBase result;
if (actions.isExecutedAsOne() || actions.getActions().size() < 2) {
final Button button = new Button();
button.setOnAction(event -> handleActions(actions.getActions()));
result = button;
} else {
final MenuButton button = new MenuButton();
// Experimenting with ways to force update of popup location,
// #226
button.showingProperty().addListener((prop, old, showing) -> {
if (showing) {
// System.out.println("Showing " + model_widget + " menu: " + showing);
// if (++calls > 2)
// {
// System.out.println("Hack!");
// if (button.getPopupSide() == Side.BOTTOM)
// button.setPopupSide(Side.LEFT);
// else
// button.setPopupSide(Side.BOTTOM);
// // button.layout();
// }
}
});
for (final ActionInfo action : actions.getActions()) {
final MenuItem item = new MenuItem(makeActionText(action), new ImageView(new Image(action.getType().getIconStream())));
item.getStyleClass().add("action_button_item");
item.setOnAction(event -> handleAction(action));
button.getItems().add(item);
}
result = button;
}
result.setStyle(background);
result.getStyleClass().add("action_button");
result.setMnemonicParsing(false);
// Model has width/height, but JFX widget has min, pref, max size.
// updateChanges() will set the 'pref' size, so make min use that as well.
result.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE);
// Monitor keys that modify the OpenDisplayActionInfo.Target.
// Use filter to capture event that's otherwise already handled.
result.addEventFilter(MouseEvent.MOUSE_PRESSED, this::checkModifiers);
// Need to attach TT to the specific button, not the common jfx_node Pane
TooltipSupport.attach(result, model_widget.propTooltip());
result.setCursor(Cursor.HAND);
return result;
}
use of org.csstudio.display.builder.model.properties.ActionInfos in project org.csstudio.display.builder by kasemir.
the class JFXActionsDialogDemo method start.
@Override
public void start(final Stage stage) {
final Widget widget = new Widget("demo");
final Macros macros = new Macros();
macros.add("S", "Test");
macros.add("N", "17");
final ActionInfos actions = new ActionInfos(Arrays.asList(new OpenDisplayActionInfo("Related Display", "../opi/some_file.opi", macros, Target.TAB), new WritePVActionInfo("Reset", "Test:CS:Reset", "1"), new ExecuteScriptActionInfo("Script", new ScriptInfo(ScriptInfo.EMBEDDED_PYTHON, "print 'hi'", false, Collections.emptyList()))));
final ActionsDialog dialog = new ActionsDialog(widget, actions);
final Optional<ActionInfos> result = dialog.showAndWait();
if (result.isPresent()) {
if (result.get().isExecutedAsOne())
System.out.println("Execute all commands as one:");
for (ActionInfo info : result.get().getActions()) {
if (info instanceof ExecuteScriptActionInfo) {
final ExecuteScriptActionInfo action = (ExecuteScriptActionInfo) info;
System.out.println("Execute " + action.getDescription() + ", " + action.getInfo() + ": " + action.getInfo().getText());
} else
System.out.println(info);
}
} else
System.out.println("Cancelled");
}
use of org.csstudio.display.builder.model.properties.ActionInfos in project org.csstudio.display.builder by kasemir.
the class AllWidgetsAllProperties method main.
public static void main(String[] args) throws Exception {
final DisplayModel model = new DisplayModel();
for (final WidgetDescriptor widget_type : WidgetFactory.getInstance().getWidgetDescriptions()) {
Widget widget = widget_type.createWidget();
widget.setPropertyValue("name", widget_type.getName() + " 1");
// For some widgets, adjust default values
if (widget_type == ActionButtonWidget.WIDGET_DESCRIPTOR) {
ActionButtonWidget button = (ActionButtonWidget) widget;
final Macros macros = new Macros();
macros.add("S", "Test");
macros.add("N", "2");
button.propActions().setValue(new ActionInfos(Arrays.asList(new OpenDisplayActionInfo("Display", "other.opi", macros, Target.REPLACE))));
}
model.runtimeChildren().addChild(widget);
}
ModelWriter.skip_defaults = false;
try {
final ModelWriter writer = new ModelWriter(new FileOutputStream(EXAMPLE_FILE));
writer.writeModel(model);
writer.close();
} finally {
ModelWriter.skip_defaults = true;
}
}
Aggregations