Search in sources :

Example 11 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class PerformAutoSizeAction method run.

@Override
public void run(IAction action) {
    if (getContainerEditpart().getChildren().size() <= 0) {
        return;
    }
    CompoundCommand compoundCommand = new CompoundCommand("Perform AutoSize");
    AbstractContainerEditpart containerEditpart = getContainerEditpart();
    AbstractContainerModel containerModel = containerEditpart.getWidgetModel();
    // temporary unlock children so children will not be resized.
    if (containerEditpart instanceof GroupingContainerEditPart) {
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, false));
    }
    IFigure figure = getContainerFigure();
    Rectangle childrenRange = GeometryUtil.getChildrenRange(containerEditpart);
    Point tranlateSize = new Point(childrenRange.x, childrenRange.y);
    compoundCommand.add(new SetBoundsCommand(containerModel, new Rectangle(containerModel.getLocation().translate(tranlateSize), new Dimension(childrenRange.width + figure.getInsets().left + figure.getInsets().right, childrenRange.height + figure.getInsets().top + figure.getInsets().bottom))));
    for (Object editpart : containerEditpart.getChildren()) {
        AbstractWidgetModel widget = ((AbstractBaseEditPart) editpart).getWidgetModel();
        compoundCommand.add(new SetBoundsCommand(widget, new Rectangle(widget.getLocation().translate(tranlateSize.getNegated()), widget.getSize())));
    }
    // recover lock
    if (containerEditpart instanceof GroupingContainerEditPart) {
        Object oldvalue = containerEditpart.getWidgetModel().getPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN);
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, oldvalue));
    }
    execute(compoundCommand);
}
Also used : AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GroupingContainerEditPart(org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) IFigure(org.eclipse.draw2d.IFigure)

Example 12 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class ArrayEditPart method removeChild.

@Override
protected void removeChild(EditPart child) {
    super.removeChild(child);
    AbstractWidgetModel childModel = ((AbstractBaseEditPart) child).getWidgetModel();
    // recover property visibility
    if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
        for (String propId : INVISIBLE_CHILD_PROPIDS) try {
            childModel.setPropertyVisibleAndSavable(propId, true, true);
        } catch (NonExistPropertyException e) {
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) NonExistPropertyException(org.csstudio.opibuilder.model.NonExistPropertyException) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) VString(org.diirt.vtype.VString)

Example 13 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class LinkingContainerEditpart method layout.

@Override
public void layout() {
    AbstractLayoutEditpart layoutter = getLayoutWidget();
    if (layoutter != null && layoutter.getWidgetModel().isEnabled()) {
        List<AbstractWidgetModel> modelChildren = new ArrayList<AbstractWidgetModel>();
        for (Object child : getChildren()) {
            if (child instanceof AbstractBaseEditPart && !(child instanceof AbstractLayoutEditpart)) {
                modelChildren.add(((AbstractBaseEditPart) child).getWidgetModel());
            }
        }
        layoutter.layout(modelChildren, getFigure().getClientArea());
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) AbstractLayoutEditpart(org.csstudio.opibuilder.editparts.AbstractLayoutEditpart)

Example 14 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class GeometryUtil method getChildrenRange.

/**
 *Get the range of children widgets.
 * @param container editpart of the container widget.
 * @return the range (minX, minY, maxX-minX, maxY-minY) relative to the container.
 */
public static Rectangle getChildrenRange(AbstractContainerEditpart container) {
    PointList pointList = new PointList(container.getChildren().size());
    for (Object child : container.getChildren()) {
        AbstractWidgetModel childModel = ((AbstractBaseEditPart) child).getWidgetModel();
        pointList.addPoint(childModel.getLocation());
        pointList.addPoint(childModel.getX() + childModel.getWidth(), childModel.getY() + childModel.getHeight());
    }
    return pointList.getBounds();
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart)

Example 15 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class SelectParentHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    GraphicalViewer viewer = HandlerUtil.getActivePart(event).getAdapter(GraphicalViewer.class);
    if (viewer == null)
        return null;
    ISelection currentSelection = viewer.getSelection();
    if (currentSelection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) currentSelection).getFirstElement();
        if (element instanceof AbstractBaseEditPart && !(element instanceof DisplayEditpart)) {
            if (((AbstractBaseEditPart) element).getParent().isSelectable())
                ((AbstractBaseEditPart) element).getViewer().select(((AbstractBaseEditPart) element).getParent());
            else
                ConsoleUtil.writeWarning("Parent of the selected widget is unselectable. Its grandparent may be locked.");
        }
    }
    return null;
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Aggregations

AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)24 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)16 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)8 ArrayList (java.util.ArrayList)6 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 GraphicalViewer (org.eclipse.gef.GraphicalViewer)4 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 PointList (org.eclipse.draw2d.geometry.PointList)3 EditPart (org.eclipse.gef.EditPart)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 EventObject (java.util.EventObject)2 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)2 SetBoundsCommand (org.csstudio.opibuilder.commands.SetBoundsCommand)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)2