Search in sources :

Example 1 with GroupingContainerModel

use of org.csstudio.opibuilder.widgets.model.GroupingContainerModel in project yamcs-studio by yamcs.

the class TabEditPart method addTab.

/**
 *Add a TabItem to the index;
 * @param index
 * @param tabItem
 */
public synchronized void addTab(int index, TabItem tabItem) {
    if (index < 0 || index > getTabItemCount())
        throw new IllegalArgumentException();
    if (index >= TabModel.MAX_TABS_AMOUNT)
        return;
    GroupingContainerModel groupingContainerModel = tabItem.getGroupingContainerModel();
    getWidgetModel().addChild(index, groupingContainerModel);
    getTabFigure().addTab((String) tabItem.getPropertyValue(TabProperty.TITLE), index);
    tabItemList.add(index, tabItem);
    initTabLabel(index, tabItem);
    rightShiftTabProperties(index);
    // apply tab properties from TabItem to TabModel
    for (TabProperty tabProperty : TabProperty.values()) {
        String propID = TabModel.makeTabPropID(tabProperty.propIDPre, index);
        getWidgetModel().setPropertyValue(propID, tabItem.getPropertyValue(tabProperty));
    }
    // update property sheet
    getWidgetModel().setPropertyValue(TabModel.PROP_TAB_COUNT, getWidgetModel().getChildren().size(), false);
    for (TabProperty tabProperty : TabProperty.values()) {
        String propID = TabModel.makeTabPropID(tabProperty.propIDPre, getWidgetModel().getChildren().size() - 1);
        getWidgetModel().setPropertyVisible(propID, true);
    }
    // update active tab index to the new added tab
    updateTabAreaSize();
    setActiveTabIndex(index);
}
Also used : GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) TabProperty(org.csstudio.opibuilder.widgets.model.TabModel.TabProperty)

Example 2 with GroupingContainerModel

use of org.csstudio.opibuilder.widgets.model.GroupingContainerModel in project yamcs-studio by yamcs.

the class TabItem method getCopy.

/**
 * @return A copy of this tab.
 * @throws Exception
 */
public TabItem getCopy() throws Exception {
    String xmlString = XMLUtil.widgetToXMLString(groupingContainerModel, false);
    GroupingContainerModel newGroupingContainerModel = (GroupingContainerModel) XMLUtil.XMLStringToWidget(xmlString);
    Map<TabProperty, Object> newPropertyMap = new HashMap<TabProperty, Object>();
    for (Entry<TabProperty, Object> entry : propertyMap.entrySet()) {
        newPropertyMap.put(entry.getKey(), entry.getValue());
    }
    return new TabItem(newGroupingContainerModel, newPropertyMap);
}
Also used : GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) TabProperty(org.csstudio.opibuilder.widgets.model.TabModel.TabProperty) HashMap(java.util.HashMap)

Example 3 with GroupingContainerModel

use of org.csstudio.opibuilder.widgets.model.GroupingContainerModel in project yamcs-studio by yamcs.

the class LockUnlockChildrenAction method run.

@Override
public void run(IAction action) {
    final GroupingContainerModel containerModel = getSelectedContainer();
    Command cmd = createLockUnlockCommand(containerModel);
    execute(cmd);
}
Also used : GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) Command(org.eclipse.gef.commands.Command) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)

Example 4 with GroupingContainerModel

use of org.csstudio.opibuilder.widgets.model.GroupingContainerModel in project yamcs-studio by yamcs.

the class CreateGroupAction method run.

@Override
public void run(IAction action) {
    var originalSelectedWidgets = getSelectedWidgetModels();
    var compoundCommand = new CompoundCommand("Create Group");
    List<AbstractWidgetModel> selectedWidgets = new ArrayList<>();
    selectedWidgets.addAll(originalSelectedWidgets);
    // remove the selected widgets which are children of another selected widget.
    for (var widget : originalSelectedWidgets) {
        if (widget instanceof DisplayModel) {
            selectedWidgets.remove(widget);
            continue;
        }
        if (widget instanceof AbstractContainerModel) {
            for (var child : originalSelectedWidgets) {
                if (((AbstractContainerModel) widget).getChildren().contains(child)) {
                    selectedWidgets.remove(child);
                }
            }
        }
    }
    var minDepth = Integer.MAX_VALUE;
    int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
    var minDepthWidget = selectedWidgets.get(0);
    for (var widget : selectedWidgets) {
        var leftX = widget.getLocation().x;
        var upY = widget.getLocation().y;
        var rightX = widget.getLocation().x + widget.getSize().width;
        var bottomY = widget.getLocation().y + widget.getSize().height;
        var depth = widget.getNestedDepth();
        if (leftX < minX) {
            minX = leftX;
        }
        if (upY < minY) {
            minY = upY;
        }
        if (rightX > maxX) {
            maxX = rightX;
        }
        if (bottomY > maxY) {
            maxY = bottomY;
        }
        if (minDepth > depth) {
            minDepth = depth;
            minDepthWidget = widget;
        }
    }
    // Orphan order should be reversed so that undo operation has the correct order.
    var widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
    for (var i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
    }
    var groupingContainerModel = new GroupingContainerModel();
    SchemaService.getInstance().applySchema(groupingContainerModel);
    // the parent should be the widget with minimum nested depth
    var parent = minDepthWidget.getParent();
    var borderWidth = 0;
    if (groupingContainerModel.getBorderStyle() == BorderStyle.GROUP_BOX) {
        borderWidth = 30;
    }
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN, true);
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_SHOW_SCROLLBAR, false);
    compoundCommand.add(new WidgetCreateCommand(groupingContainerModel, parent, new Rectangle(minX, minY, maxX - minX + borderWidth, maxY - minY + borderWidth), false));
    for (var widget : selectedWidgets) {
        compoundCommand.add(new AddWidgetCommand(groupingContainerModel, widget, new Rectangle(widget.getLocation().translate(-minX, -minY), widget.getSize())));
    }
    execute(compoundCommand);
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand)

Example 5 with GroupingContainerModel

use of org.csstudio.opibuilder.widgets.model.GroupingContainerModel in project yamcs-studio by yamcs.

the class SelectAllInGroupAction method run.

@Override
public void run(IAction action) {
    GroupingContainerModel containerModel = getContainerModel();
    containerModel.selectWidgets(containerModel.getChildren(), false);
}
Also used : GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel)

Aggregations

GroupingContainerModel (org.csstudio.opibuilder.widgets.model.GroupingContainerModel)8 TabProperty (org.csstudio.opibuilder.widgets.model.TabModel.TabProperty)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Level (java.util.logging.Level)1 OPIBuilderPlugin (org.csstudio.opibuilder.OPIBuilderPlugin)1 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)1 OrphanChildCommand (org.csstudio.opibuilder.commands.OrphanChildCommand)1 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 PROP_BORDER_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH)1 PROP_HEIGHT (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT)1 PROP_VISIBLE (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_VISIBLE)1 PROP_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1