Search in sources :

Example 1 with ArrayWidget

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

the class DisplayEditor method addWidgets.

/**
 * @param widgets Widgets to be added to existing model
 */
private void addWidgets(final List<Widget> widgets) {
    // Dropped into a sub-group or the main display?
    ChildrenProperty target = group_handler.getActiveParentChildren();
    if (target == null)
        target = model.runtimeChildren();
    Widget container = target.getWidget();
    // Correct all dropped widget locations relative to container
    Point2D offset = GeometryTools.getContainerOffset(container);
    // Also account for scroll pane
    Point2D origin = JFXGeometryTools.getContentOrigin(model_root);
    int dx = (int) (offset.getX() - origin.getX());
    int dy = (int) (offset.getY() - origin.getY());
    // Add dropped widgets
    try {
        final ListIterator<Widget> it = widgets.listIterator();
        if (container instanceof ArrayWidget) {
            if (target.getValue().isEmpty()) {
                // Drop first widget into ArrayWidget
                Widget widget = it.next();
                widget.propX().setValue(widget.propX().getValue() - dx);
                widget.propY().setValue(widget.propY().getValue() - dy);
                widget_naming.setDefaultName(container.getDisplayModel(), widget);
                undo.execute(new AddWidgetAction(selection, target, widget));
            }
            // Hide highlight, since not adding to ArrayWidget container
            if (it.hasNext())
                group_handler.hide();
            // Re-assign target, container, etc. to use ArrayWidget's parent
            target = ChildrenProperty.getParentsChildren(container);
            container = target.getWidget();
            offset = GeometryTools.getContainerOffset(container);
            origin = JFXGeometryTools.getContentOrigin(model_root);
            dx = (int) (offset.getX() - origin.getX());
            dy = (int) (offset.getY() - origin.getY());
        }
        while (it.hasNext()) {
            Widget widget = it.next();
            widget.propX().setValue(widget.propX().getValue() - dx);
            widget.propY().setValue(widget.propY().getValue() - dy);
            widget_naming.setDefaultName(container.getDisplayModel(), widget);
            undo.execute(new AddWidgetAction(selection, target, widget));
        }
        selection.setSelection(widgets);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Cannot add widgets", ex);
    }
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) AddWidgetAction(org.csstudio.display.builder.editor.undo.AddWidgetAction) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) Point2D(javafx.geometry.Point2D) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) Widget(org.csstudio.display.builder.model.Widget)

Aggregations

Point2D (javafx.geometry.Point2D)1 AddWidgetAction (org.csstudio.display.builder.editor.undo.AddWidgetAction)1 ChildrenProperty (org.csstudio.display.builder.model.ChildrenProperty)1 Widget (org.csstudio.display.builder.model.Widget)1 ArrayWidget (org.csstudio.display.builder.model.widgets.ArrayWidget)1