Search in sources :

Example 1 with GroupWidget

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;
}
Also used : RectangleWidget(org.csstudio.display.builder.model.widgets.RectangleWidget) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) TextUpdateWidget(org.csstudio.display.builder.model.widgets.TextUpdateWidget)

Example 2 with GroupWidget

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);
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) TimeoutException(java.util.concurrent.TimeoutException) VisibleWidget(org.csstudio.display.builder.model.widgets.VisibleWidget) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) Version(org.osgi.framework.Version) Collectors(java.util.stream.Collectors) ModelLoader(org.csstudio.display.builder.model.persist.ModelLoader) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Level(java.util.logging.Level) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Future(java.util.concurrent.Future) WidgetColorService(org.csstudio.display.builder.model.persist.WidgetColorService) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Widget(org.csstudio.display.builder.model.Widget) NavigationTabsWidget(org.csstudio.display.builder.model.widgets.NavigationTabsWidget) NamedWidgetColors(org.csstudio.display.builder.model.persist.NamedWidgetColors) VisibleWidget(org.csstudio.display.builder.model.widgets.VisibleWidget) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Widget(org.csstudio.display.builder.model.Widget) NavigationTabsWidget(org.csstudio.display.builder.model.widgets.NavigationTabsWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget)

Example 3 with GroupWidget

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"));
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Test(org.junit.Test)

Example 4 with GroupWidget

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);
}
Also used : OpenPerspectiveAction(org.csstudio.ui.util.perspective.OpenPerspectiveAction) IAction(org.eclipse.jface.action.IAction) RedoAction(org.csstudio.display.builder.editor.rcp.actions.RedoAction) CutDeleteAction(org.csstudio.display.builder.editor.rcp.actions.CutDeleteAction) PasteAction(org.csstudio.display.builder.editor.rcp.actions.PasteAction) OpenPerspectiveAction(org.csstudio.ui.util.perspective.OpenPerspectiveAction) ReloadDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ReloadDisplayAction) RemoveGroupAction(org.csstudio.display.builder.editor.rcp.actions.RemoveGroupAction) ExecuteDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ExecuteDisplayAction) CreateGroupAction(org.csstudio.display.builder.editor.rcp.actions.CreateGroupAction) SelectAllAction(org.csstudio.display.builder.editor.rcp.actions.SelectAllAction) CopyAction(org.csstudio.display.builder.editor.rcp.actions.CopyAction) Action(org.eclipse.jface.action.Action) ReloadClassesAction(org.csstudio.display.builder.editor.rcp.actions.ReloadClassesAction) UndoAction(org.csstudio.display.builder.editor.rcp.actions.UndoAction) CreateGroupAction(org.csstudio.display.builder.editor.rcp.actions.CreateGroupAction) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) Widget(org.csstudio.display.builder.model.Widget) ReloadClassesAction(org.csstudio.display.builder.editor.rcp.actions.ReloadClassesAction) ReloadDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ReloadDisplayAction) ExecuteDisplayAction(org.csstudio.display.builder.editor.rcp.actions.ExecuteDisplayAction) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) MenuManager(org.eclipse.jface.action.MenuManager) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) RemoveGroupAction(org.csstudio.display.builder.editor.rcp.actions.RemoveGroupAction) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget)

Example 5 with GroupWidget

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();
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) SetMacroizedWidgetPropertyAction(org.csstudio.display.builder.editor.undo.SetMacroizedWidgetPropertyAction) Tooltip(javafx.scene.control.Tooltip) TextField(javafx.scene.control.TextField) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget)

Aggregations

GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)11 DisplayModel (org.csstudio.display.builder.model.DisplayModel)6 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)6 Widget (org.csstudio.display.builder.model.Widget)5 Test (org.junit.Test)5 CustomWidget (org.csstudio.display.builder.model.CustomWidget)2 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)2 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Level (java.util.logging.Level)1 Collectors (java.util.stream.Collectors)1