use of org.csstudio.display.builder.model.widgets.GroupWidget in project org.csstudio.display.builder by kasemir.
the class ExampleModels method createModel.
/**
* @return {@link DisplayModel}
*/
public static DisplayModel createModel() {
final DisplayModel model = new DisplayModel();
model.setPropertyValue(CommonWidgetProperties.propWidth, 1400);
model.setPropertyValue(CommonWidgetProperties.propHeight, 20 * 50);
for (int i = 0; i < 200; ++i) {
final int x = 0 + (i / 20) * 132;
final int y = 0 + (i % 20) * 50;
final GroupWidget group = new GroupWidget();
group.setPropertyValue(CommonWidgetProperties.propName, "Group " + i);
group.setPropertyValue(CommonWidgetProperties.propX, x);
group.setPropertyValue(CommonWidgetProperties.propY, y);
group.setPropertyValue(CommonWidgetProperties.propWidth, 125);
group.setPropertyValue(CommonWidgetProperties.propHeight, 53);
final LabelWidget label = new LabelWidget();
label.setPropertyValue(CommonWidgetProperties.propName, "Label " + i);
label.setPropertyValue(CommonWidgetProperties.propX, 0);
label.setPropertyValue(CommonWidgetProperties.propY, 4);
label.setPropertyValue(CommonWidgetProperties.propWidth, 15);
label.setPropertyValue(CommonWidgetProperties.propHeight, 15);
label.setPropertyValue(CommonWidgetProperties.propText, Integer.toString(i));
group.runtimeChildren().addChild(label);
// For SWT implementation, rect. is not 'transparent',
// so needs to be behind text
final RectangleWidget rect = new RectangleWidget();
rect.setPropertyValue(CommonWidgetProperties.propName, "Rect " + i);
rect.setPropertyValue(CommonWidgetProperties.propX, 10);
rect.setPropertyValue(CommonWidgetProperties.propY, 0);
rect.setPropertyValue(CommonWidgetProperties.propWidth, 80);
rect.setPropertyValue(CommonWidgetProperties.propHeight, 19);
rect.setPropertyValue(CommonWidgetProperties.propScripts, Arrays.asList(new ScriptInfo("../org.csstudio.display.builder.runtime.test/examples/fudge_width.py", true, new ScriptPV("noise"))));
group.runtimeChildren().addChild(rect);
final TextUpdateWidget text = new TextUpdateWidget();
text.setPropertyValue(CommonWidgetProperties.propName, "Text " + i);
text.setPropertyValue(CommonWidgetProperties.propX, 30);
text.setPropertyValue(CommonWidgetProperties.propY, 4);
text.setPropertyValue(CommonWidgetProperties.propWidth, 45);
text.setPropertyValue(CommonWidgetProperties.propHeight, 15);
text.setPropertyValue(CommonWidgetProperties.propPVName, "ramp");
group.runtimeChildren().addChild(text);
model.runtimeChildren().addChild(group);
}
return model;
}
use of org.csstudio.display.builder.model.widgets.GroupWidget in project org.csstudio.display.builder by kasemir.
the class EmbeddedDisplayRepresentationUtil method reduceDisplayModelToGroup.
/**
* Reduce display model to content of one named group
* @param display_file Name of the display file
* @param model Model loaded from that file
* @param group_name Name of group to use
*/
private static void reduceDisplayModelToGroup(final Widget model_widget, final DisplayModel model, final DisplayAndGroup display_and_group) {
final String group_name = display_and_group.getGroupName();
final List<Widget> children = model.runtimeChildren().getValue();
// Find all groups with desired name.
// Could just loop to get the first matching group,
// but finding all and logging them helps to debug displays.
final List<Widget> groups = children.parallelStream().filter(child -> child instanceof GroupWidget && child.getName().equals(group_name)).collect(Collectors.toList());
// Expect exactly one
if (groups.size() != 1)
logger.log(Level.WARNING, "Expected one group named '" + group_name + "' in '" + display_and_group.getDisplayFile() + "', found " + groups);
// If no group found, use the complete display
if (groups.size() <= 0)
return;
// Replace display with just the content of that group
final GroupWidget group = (GroupWidget) groups.get(0);
model.runtimeChildren().setValue(group.runtimeChildren().getValue());
// Group model correction - use group background color, not the display background color
model.propBackgroundColor().setValue(group.propBackgroundColor().getValue());
// If the group is transparent, see if the embedding widget can also be
if (group.propTransparent().getValue())
model_widget.checkProperty(CommonWidgetProperties.propTransparent).ifPresent(trans -> trans.setValue(true));
// Not removing children from 'group', since group will be GC'ed anyway.
shrinkModelToWidgets(model);
}
use of org.csstudio.display.builder.model.widgets.GroupWidget in project org.csstudio.display.builder by kasemir.
the class MacroHierarchyUnitTest method testTimeOfExpansion.
/**
* Test when macros get expanded
* @throws Exception on error
*/
@Test
public void testTimeOfExpansion() throws Exception {
// model -> group -> subgroup -> label
final DisplayModel model = new DisplayModel();
final GroupWidget group = new GroupWidget();
model.runtimeChildren().addChild(group);
final GroupWidget subgroup = new GroupWidget();
group.runtimeChildren().addChild(subgroup);
final LabelWidget label = new LabelWidget();
subgroup.runtimeChildren().addChild(label);
// Sanity check: Straight forward macro value replacement.
// Display value replaced by group,
// then replaced by subgroup,
// so label sees "subgroup"
model.propMacros().getValue().add("P", "display");
group.propMacros().getValue().add("P", "group");
subgroup.propMacros().getValue().add("P", "subgroup");
Macros macros = label.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("P"), equalTo("subgroup"));
// When are macros expanded?
// In BOY, they were mostly expanded when set,
// except the following example would fail if all widgets
// were within one display.
model.propMacros().getValue().add("P", "display");
// If macros are expanded early on,
// this sets SAVE=display,
// then redefines P
group.propMacros().getValue().add("SAVE", "$(P)");
group.propMacros().getValue().add("P", "group");
// .. and this would restore P='display', since that's what's im $(SAVE):
subgroup.propMacros().getValue().add("P", "$(SAVE)");
// With lazy macro expansion,
// the label widget would have P=$(SAVE), SAVE=$(P),
// so $(P) results in a "recursive macro" error.
// When macros are expanded as the runtime starts..
DisplayMacroExpander.expandDisplayMacros(model);
// ..you get $(P)="display"
macros = label.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("P"), equalTo("display"));
assertThat(MacroHandler.replace(macros, "$(P)"), equalTo("display"));
}
use of org.csstudio.display.builder.model.widgets.GroupWidget in project org.csstudio.display.builder by kasemir.
the class DisplayEditorPart method createContextMenu.
private Menu createContextMenu(final Control parent) {
final MenuManager mm = new MenuManager();
final Action execute = new ExecuteDisplayAction(this);
final MenuManager morph = new MorphWidgetMenuSupport(editor).getMenuManager();
final ImageDescriptor icon = AbstractUIPlugin.imageDescriptorFromPlugin(ModelPlugin.ID, "icons/display.png");
final Action perspective = new OpenPerspectiveAction(icon, Messages.OpenEditorPerspective, EditorPerspective.ID);
final Action reload = new ReloadDisplayAction(this);
mm.setRemoveAllWhenShown(true);
mm.addMenuListener(manager -> {
manager.add(execute);
final List<Widget> selection = editor.getWidgetSelectionHandler().getSelection();
if (!selection.isEmpty()) {
if (selection.size() >= 1)
manager.add(new CreateGroupAction(editor, selection));
if (selection.size() == 1 && selection.get(0) instanceof GroupWidget)
manager.add(new RemoveGroupAction(editor, (GroupWidget) selection.get(0)));
if (selection.size() == 1 && selection.get(0) instanceof EmbeddedDisplayWidget)
manager.add(new EditEmbeddedDisplayAction((EmbeddedDisplayWidget) selection.get(0)));
manager.add(morph);
}
manager.add(reload);
final DisplayModel model = editor.getModel();
if (model != null && !model.isClassModel()) {
manager.add(new ReloadClassesAction(this));
if (selection.isEmpty())
manager.add(new SetDisplaySize(editor));
}
manager.add(perspective);
});
return mm.createContextMenu(parent);
}
use of org.csstudio.display.builder.model.widgets.GroupWidget 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