use of org.csstudio.display.builder.model.widgets.ActionButtonWidget 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;
}
}
use of org.csstudio.display.builder.model.widgets.ActionButtonWidget in project org.csstudio.display.builder by kasemir.
the class SelectedWidgetUITracker method createInlineEditor.
/**
* Create an inline editor
*
* <p>Depending on the widget's properties, it will edit
* the PV name or the text.
*
* @param widget Widget on which to create an inline editor
*/
private void createInlineEditor(final Widget widget) {
// Check for an inline-editable property
Optional<WidgetProperty<String>> check;
// Add Widget#getInlineEditableProperty()
if (widget instanceof ActionButtonWidget)
check = Optional.of(((ActionButtonWidget) widget).propText());
else if (widget instanceof GroupWidget)
check = Optional.of(((GroupWidget) widget).propName());
else
check = widget.checkProperty(CommonWidgetProperties.propPVName);
if (!check.isPresent())
check = widget.checkProperty(CommonWidgetProperties.propText);
if (!check.isPresent())
return;
// Create text field, aligned with widget, but assert minimum size
final MacroizedWidgetProperty<String> property = (MacroizedWidgetProperty<String>) check.get();
inline_editor = new TextField(property.getSpecification());
// 'Managed' text field would assume some default size,
// but we set the exact size in here
inline_editor.setManaged(false);
// Not really shown since TextField will have focus
inline_editor.setPromptText(property.getDescription());
inline_editor.setTooltip(new Tooltip(property.getDescription()));
inline_editor.relocate(tracker.getX(), tracker.getY());
inline_editor.resize(Math.max(100, tracker.getWidth()), Math.max(20, tracker.getHeight()));
getChildren().add(inline_editor);
// add autocomplete menu if editing property PVName
if (property.getName().equals(CommonWidgetProperties.propPVName.getName()))
autocomplete_menu.attachField(inline_editor);
// On enter, update the property. On Escape, just close
inline_editor.setOnKeyPressed(event -> {
switch(event.getCode()) {
case ENTER:
undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText()));
// Fall through, close editor
case ESCAPE:
event.consume();
closeInlineEditor();
default:
}
});
// Close when focus lost
inline_editor.focusedProperty().addListener((prop, old, focused) -> {
if (!focused)
closeInlineEditor();
});
inline_editor.selectAll();
inline_editor.requestFocus();
}
Aggregations