Search in sources :

Example 6 with WidgetCreateCommand

use of org.csstudio.opibuilder.commands.WidgetCreateCommand in project yamcs-studio by yamcs.

the class DropPVtoContainerEditPolicy method getCommand.

@Override
public Command getCommand(Request request) {
    if (request.getType() == DropPVRequest.REQ_DROP_PV && request instanceof DropPVRequest) {
        DropPVRequest dropPVRequest = (DropPVRequest) request;
        if (dropPVRequest.getTargetWidget() != null && dropPVRequest.getTargetWidget() instanceof AbstractContainerEditpart) {
            WidgetsSelectDialog dialog = new WidgetsSelectDialog(getHost().getViewer().getControl().getShell(), dropPVRequest.getPvNames().length, true);
            if (dialog.open() == Window.OK) {
                String typeID = dialog.getOutput();
                CompoundCommand command = new CompoundCommand("Create Widget");
                // $NON-NLS-1$
                String[] pvNames = dropPVRequest.getPvNames();
                Point location = dropPVRequest.getLocation().getCopy();
                AbstractContainerModel container = ((AbstractContainerEditpart) dropPVRequest.getTargetWidget()).getWidgetModel();
                AbstractContainerModel parent = container.getParent();
                AbstractContainerModel temp = container;
                while (parent != null) {
                    location.translate(temp.getLocation().getNegated());
                    temp = parent;
                    parent = parent.getParent();
                }
                int i = 1;
                int lastWidth = 0, lastHeight = 0;
                for (String pvName : pvNames) {
                    AbstractWidgetModel widgetModel = WidgetsService.getInstance().getWidgetDescriptor(typeID).getWidgetModel();
                    command.add(new WidgetCreateCommand(widgetModel, container, new Rectangle(location.getCopy().translate(lastWidth, lastHeight), new Dimension(-1, -1)), i != 1, true));
                    command.add(new SetWidgetPropertyCommand(widgetModel, AbstractPVWidgetModel.PROP_PVNAME, pvName.trim()));
                    if (i % WIDGETS_ACCOUNT_ON_A_ROW == 0) {
                        lastWidth = 0;
                        lastHeight += widgetModel.getHeight();
                    } else
                        lastWidth += widgetModel.getWidth();
                    i++;
                }
                return command;
            }
        }
    }
    return null;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) WidgetsSelectDialog(org.csstudio.opibuilder.visualparts.WidgetsSelectDialog)

Aggregations

WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)5 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)4 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ChangeGuideCommand (org.csstudio.opibuilder.commands.ChangeGuideCommand)1 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)1 OrphanChildCommand (org.csstudio.opibuilder.commands.OrphanChildCommand)1 WidgetSetConstraintCommand (org.csstudio.opibuilder.commands.WidgetSetConstraintCommand)1 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)1 IGraphicalFeedbackFactory (org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1 WidgetsSelectDialog (org.csstudio.opibuilder.visualparts.WidgetsSelectDialog)1 GroupingContainerModel (org.csstudio.opibuilder.widgets.model.GroupingContainerModel)1