Search in sources :

Example 1 with TabsWidget

use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.

the class WidgetTree method removeWidget.

/**
 * Remove widget from existing model & tree
 *  @param removed_widget
 */
private void removeWidget(final Widget removed_widget) {
    if (removed_widget instanceof TabsWidget) {
        final ArrayWidgetProperty<TabItemProperty> tabs = ((TabsWidget) removed_widget).propTabs();
        tabs.removePropertyListener(tabs_property_listener);
        removeTabs(tabs.getValue());
    }
    removed_widget.propName().removePropertyListener(name_listener);
    final ChildrenProperty children = ChildrenProperty.getChildren(removed_widget);
    if (children != null) {
        children.removePropertyListener(children_listener);
        for (Widget child : children.getValue()) removeWidget(child);
    }
    final TreeItem<WidgetOrTab> item = widget2tree.remove(removed_widget);
    item.getParent().getChildren().remove(item);
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 2 with TabsWidget

use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.

the class WidgetTree method addWidget.

/**
 * Add widget to existing model & tree
 *  @param added_widget Widget to add
 *  @param index Index of widget within parent. -1 to add at end
 */
private void addWidget(final Widget added_widget, final int index) {
    // Have widget and its parent in model
    final Widget widget_parent = added_widget.getParent().get();
    // Determine parent tree item
    TreeItem<WidgetOrTab> item_parent = null;
    if (widget_parent instanceof TabsWidget) {
        for (TabItemProperty tab : ((TabsWidget) widget_parent).propTabs().getValue()) if (tab.children().getValue().contains(added_widget)) {
            item_parent = tab_name2tree.get(tab.name());
            break;
        }
    } else
        item_parent = widget2tree.get(widget_parent);
    Objects.requireNonNull(item_parent, "Cannot obtain parent item for " + added_widget);
    // Create Tree item
    final TreeItem<WidgetOrTab> item = new TreeItem<>(WidgetOrTab.of(added_widget));
    widget2tree.put(added_widget, item);
    item.setExpanded(true);
    if (index >= 0)
        // Add at same index into Tree
        item_parent.getChildren().add(index, item);
    else
        // Append to end
        item_parent.getChildren().add(item);
    added_widget.propName().addPropertyListener(name_listener);
    if (added_widget instanceof TabsWidget) {
        final ArrayWidgetProperty<TabItemProperty> tabs = ((TabsWidget) added_widget).propTabs();
        addTabs(tabs.getValue());
        tabs.addPropertyListener(tabs_property_listener);
    } else {
        final ChildrenProperty children = ChildrenProperty.getChildren(added_widget);
        if (children != null) {
            children.addPropertyListener(children_listener);
            for (Widget child : children.getValue()) addWidget(child, -1);
        }
    }
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) TreeItem(javafx.scene.control.TreeItem) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 3 with TabsWidget

use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.

the class WidgetTree method removeWidgetListeners.

/**
 * Recursively remove model widget listeners
 *  @param container Widgets to unlink
 */
private void removeWidgetListeners(final Widget widget) {
    if (widget instanceof TabsWidget) {
        final ArrayWidgetProperty<TabItemProperty> tabs = ((TabsWidget) widget).propTabs();
        tabs.removePropertyListener(tabs_property_listener);
        for (TabItemProperty tab : tabs.getValue()) {
            tab.children().removePropertyListener(children_listener);
            tab.name().removePropertyListener(tab_name_listener);
        }
    }
    widget.propName().removePropertyListener(name_listener);
    final ChildrenProperty children = ChildrenProperty.getChildren(widget);
    if (children != null) {
        children.removePropertyListener(children_listener);
        for (Widget child : children.getValue()) removeWidgetListeners(child);
    }
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 4 with TabsWidget

use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.

the class JFXBaseRepresentation method createComponents.

/**
 * {@inheritDoc}
 */
@Override
public Parent createComponents(final Parent parent) throws Exception {
    jfx_node = createJFXNode();
    if (jfx_node != null) {
        // Order JFX children same as model widgets within their container
        int index = -1;
        final Optional<Widget> container = model_widget.getParent();
        if (container.isPresent()) {
            if (container.get() instanceof TabsWidget) {
                // Locate model_widget inside one of the Tab's children
                final List<TabItemProperty> tabs = ((TabsWidget) container.get()).propTabs().getValue();
                for (TabItemProperty tab : tabs) {
                    final int i = tab.children().getValue().indexOf(model_widget);
                    if (i >= 0) {
                        index = i;
                        break;
                    }
                }
            } else
                index = container.get().getProperty(ChildrenProperty.DESCRIPTOR).getValue().indexOf(model_widget);
        }
        if (index < 0)
            JFXRepresentation.getChildren(parent).add(jfx_node);
        else
            JFXRepresentation.getChildren(parent).add(index, jfx_node);
        if (toolkit.isEditMode()) {
            // Any visible item can be 'clicked' to allow editor to 'select' it
            final EventHandler<MouseEvent> detect_click = event -> {
                if (event.isPrimaryButtonDown()) {
                    event.consume();
                    toolkit.fireClick(model_widget, event.isControlDown());
                }
            };
            if (isFilteringEditModeClicks())
                jfx_node.addEventFilter(MouseEvent.MOUSE_PRESSED, detect_click);
            else
                jfx_node.addEventHandler(MouseEvent.MOUSE_PRESSED, detect_click);
        } else
            jfx_node.setOnContextMenuRequested((event) -> {
                event.consume();
                toolkit.fireContextMenu(model_widget);
            });
    }
    registerListeners();
    updateChanges();
    return getChildParent(parent);
}
Also used : EventHandler(javafx.event.EventHandler) DisplayModel(org.csstudio.display.builder.model.DisplayModel) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Node(javafx.scene.Node) MouseEvent(javafx.scene.input.MouseEvent) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Objects(java.util.Objects) JFXRepresentation(org.csstudio.display.builder.representation.javafx.JFXRepresentation) Parent(javafx.scene.Parent) List(java.util.List) ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) Optional(java.util.Optional) DirtyFlag(org.csstudio.display.builder.model.DirtyFlag) WidgetRepresentation(org.csstudio.display.builder.representation.WidgetRepresentation) Widget(org.csstudio.display.builder.model.Widget) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) MouseEvent(javafx.scene.input.MouseEvent) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 5 with TabsWidget

use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.

the class ChildrenProperty method getParentsChildren.

/**
 * Get the 'children' list of a widget's parent.
 *
 *  <p>This is either the children list of a plain parent,
 *  or the children list inside a TabWidget's tab.
 *
 *  @param widget Widget where parent (plain or TabWidget) is checked for
 *  @return {@link ChildrenProperty} that contains the widget
 *  @throws NoSuchElementException if widget has no parent
 *  @throws IllegalArgumentException If no tab of parent {@link TabWidget} contains the widget,
 *  @throws IllegalStateException If parent has no children
 */
public static ChildrenProperty getParentsChildren(final Widget widget) {
    final Widget parent = widget.getParent().get();
    if (parent instanceof TabsWidget) {
        final List<TabItemProperty> tabs = ((TabsWidget) parent).propTabs().getValue();
        for (TabItemProperty tab : tabs) {
            final ChildrenProperty children = tab.children();
            if (children.getValue().contains(widget))
                return children;
        }
        throw new IllegalArgumentException("Cannot locate " + widget + " in " + parent);
    }
    final Optional<WidgetProperty<List<Widget>>> children = parent.checkProperty(DESCRIPTOR);
    if (children.isPresent())
        return (ChildrenProperty) children.get();
    throw new IllegalStateException("Parent of " + widget + " has no 'children': " + parent);
}
Also used : TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget)

Aggregations

TabsWidget (org.csstudio.display.builder.model.widgets.TabsWidget)5 TabItemProperty (org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty)5 ChildrenProperty (org.csstudio.display.builder.model.ChildrenProperty)4 Widget (org.csstudio.display.builder.model.Widget)4 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 EventHandler (javafx.event.EventHandler)1 Node (javafx.scene.Node)1 Parent (javafx.scene.Parent)1 TreeItem (javafx.scene.control.TreeItem)1 MouseEvent (javafx.scene.input.MouseEvent)1 DirtyFlag (org.csstudio.display.builder.model.DirtyFlag)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)1 CommonWidgetProperties (org.csstudio.display.builder.model.properties.CommonWidgetProperties)1 WidgetRepresentation (org.csstudio.display.builder.representation.WidgetRepresentation)1 JFXRepresentation (org.csstudio.display.builder.representation.javafx.JFXRepresentation)1