Search in sources :

Example 6 with TabItemProperty

use of org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty 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 7 with TabItemProperty

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

the class TabsRepresentation method removeTabs.

private void removeTabs(final List<TabItemProperty> removed) {
    for (TabItemProperty item : removed) {
        item.children().removePropertyListener(tab_children_listener);
        item.name().removePropertyListener(tab_title_listener);
        for (Tab tab : jfx_node.getTabs()) if (tab.getUserData() == item) {
            jfx_node.getTabs().remove(tab);
            break;
        }
    }
}
Also used : TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) Tab(javafx.scene.control.Tab)

Example 8 with TabItemProperty

use of org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty 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 9 with TabItemProperty

use of org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty 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

TabItemProperty (org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty)9 TabsWidget (org.csstudio.display.builder.model.widgets.TabsWidget)6 Widget (org.csstudio.display.builder.model.Widget)5 ChildrenProperty (org.csstudio.display.builder.model.ChildrenProperty)4 Tab (javafx.scene.control.Tab)2 TreeItem (javafx.scene.control.TreeItem)2 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 Label (javafx.scene.control.Label)1 TabPane (javafx.scene.control.TabPane)1 MouseEvent (javafx.scene.input.MouseEvent)1 Pane (javafx.scene.layout.Pane)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