use of org.csstudio.display.builder.model.properties.ActionInfo 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.ActionInfo 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.ActionInfo in project org.csstudio.display.builder by kasemir.
the class ActionButtonRepresentation method createSWTControl.
@Override
protected Button createSWTControl(final Composite parent) throws Exception {
final List<ActionInfo> actions = model_widget.propActions().getValue().getActions();
final Button button = new Button(parent, SWT.PUSH);
// Use basic button for single action
if (actions.size() == 1) {
final ActionInfo the_action = actions.get(0);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent event) {
handleAction(the_action, event.stateMask);
}
});
} else {
// Add context menu if there are multiple actions
final Menu menu = new Menu(button);
for (final ActionInfo action : actions) {
final MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(action.getDescription());
final ActionInfo the_action = action;
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent event) {
handleAction(the_action, event.stateMask);
}
});
}
button.setMenu(menu);
}
return button;
}
use of org.csstudio.display.builder.model.properties.ActionInfo in project org.csstudio.display.builder by kasemir.
the class ContextMenuSupport method fillContextMenu.
private void fillContextMenu(final IMenuManager manager) {
final Widget context_menu_widget = view.getActiveWidget();
if (context_menu_widget == null) {
logger.log(Level.WARNING, "Missing context_menu_widget");
manager.add(new Action("No widget") {
});
} else {
// Widget info
manager.add(new WidgetInfoAction(context_menu_widget));
// Actions of the widget
for (ActionInfo info : context_menu_widget.propActions().getValue().getActions()) {
if (info.getType() == ActionType.OPEN_DISPLAY) {
// Add variant for all the available Target types: Replace, new Tab, ...
final OpenDisplayActionInfo open_info = (OpenDisplayActionInfo) info;
for (Target target : Target.values()) {
// STANDALONE can be achieved via StandaloneAction on new display
if (target == Target.STANDALONE)
continue;
final String desc = target == Target.REPLACE ? open_info.getDescription() : open_info.getDescription() + " (" + target + ")";
manager.add(new ActionInfoWrapper(context_menu_widget, new OpenDisplayActionInfo(desc, open_info.getFile(), open_info.getMacros(), target)));
}
} else
manager.add(new ActionInfoWrapper(context_menu_widget, info));
}
// Actions of the widget runtime
final WidgetRuntime<Widget> runtime = RuntimeUtil.getRuntime(context_menu_widget);
if (runtime == null)
throw new NullPointerException("Missing runtime for " + context_menu_widget);
for (RuntimeAction info : runtime.getRuntimeActions()) manager.add(new RuntimeActionWrapper(context_menu_widget, info));
}
// Placeholder for ProcessVariable object contributions
manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(new Separator());
if (context_menu_widget != null) {
final Node node = JFXBaseRepresentation.getJFXNode(context_menu_widget);
final Scene scene = node.getScene();
manager.add(new SaveSnapshotAction(shell, scene));
manager.add(new PrintAction(shell, scene));
manager.add(new SendEMailAction(shell, scene));
manager.add(new SendLogbookAction(shell, scene));
manager.add(new FullScreenAction(view.getSite().getPage()));
if (support_standalone)
manager.add(new StandaloneAction(view));
}
// Placeholder for the display editor.
// If editor.rcp plugin is included, it adds "Open in editor"
manager.add(new Separator("display_editor"));
manager.add(new ReloadDisplayAction());
}
use of org.csstudio.display.builder.model.properties.ActionInfo in project org.csstudio.display.builder by kasemir.
the class WidgetRuntime method startScripts.
/**
* Start Scripts
*/
private void startScripts() {
// Start scripts triggered by PVs
final List<ScriptInfo> script_infos = widget.propScripts().getValue();
final List<RuleInfo> rule_infos = widget.propRules().getValue();
if ((script_infos.size() > 0) || (rule_infos.size() > 0)) {
final List<RuntimeScriptHandler> handlers = new ArrayList<>(script_infos.size() + rule_infos.size());
for (final ScriptInfo script_info : script_infos) {
try {
handlers.add(new RuntimeScriptHandler(widget, script_info));
} catch (final Exception ex) {
final StringBuilder buf = new StringBuilder();
buf.append("Script failed to compile\n");
try {
final DisplayModel model = widget.getDisplayModel();
buf.append("Display '").append(model.getDisplayName()).append("', ");
} catch (Exception ignore) {
// Skip display model
}
buf.append(widget).append(", ").append(script_info.getPath());
logger.log(Level.WARNING, buf.toString(), ex);
}
}
for (final RuleInfo rule_info : rule_infos) {
try {
handlers.add(new RuntimeScriptHandler(widget, rule_info));
} catch (final Exception ex) {
final StringBuilder buf = new StringBuilder();
buf.append("Rule failed to compile\n");
try {
final DisplayModel model = widget.getDisplayModel();
buf.append("Display '").append(model.getDisplayName()).append("', ");
} catch (Exception ignore) {
// Skip display model
}
buf.append(widget).append(", ").append(rule_info.getName());
logger.log(Level.WARNING, buf.toString(), ex);
}
}
script_handlers = handlers;
}
// Compile scripts invoked by actions
final List<ActionInfo> actions = widget.propActions().getValue().getActions();
if (actions.size() > 0) {
final Map<ExecuteScriptActionInfo, Script> scripts = new HashMap<>();
for (ActionInfo action_info : actions) {
if (!(action_info instanceof ExecuteScriptActionInfo))
continue;
final ExecuteScriptActionInfo script_action = (ExecuteScriptActionInfo) action_info;
try {
final MacroValueProvider macros = widget.getMacrosOrProperties();
final Script script = RuntimeScriptHandler.compileScript(widget, macros, script_action.getInfo());
scripts.put(script_action, script);
} catch (final Exception ex) {
final StringBuilder buf = new StringBuilder();
buf.append("Script for action failed to compile\n");
try {
final DisplayModel model = widget.getDisplayModel();
buf.append("Display '").append(model.getDisplayName()).append("', ");
} catch (Exception ignore) {
// Skip display model
}
buf.append(widget).append(", ").append(script_action);
logger.log(Level.WARNING, buf.toString(), ex);
}
}
if (scripts.size() > 0)
action_scripts = scripts;
}
// Signal that start() has completed
started.countDown();
}
Aggregations