Search in sources :

Example 16 with SetWidgetPropertyCommand

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

the class DistributeWidgetsAction method getHorizontalCenterCommand.

private Command getHorizontalCenterCommand() {
    AbstractWidgetModel[] sortedModelArray = getSortedModelArray(true);
    CompoundCommand cmd = new CompoundCommand("Horizontal Center Distribution");
    int averageGap = (getCenterLoc(sortedModelArray[sortedModelArray.length - 1], true) - getCenterLoc(sortedModelArray[0], true)) / (sortedModelArray.length - 1);
    int startX = getCenterLoc(sortedModelArray[0], true);
    for (int i = 1; i < sortedModelArray.length - 1; i++) {
        cmd.add(new SetWidgetPropertyCommand(sortedModelArray[i], AbstractWidgetModel.PROP_XPOS, startX + averageGap - sortedModelArray[i].getWidth() / 2));
        startX += averageGap;
    }
    return cmd;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 17 with SetWidgetPropertyCommand

use of org.csstudio.opibuilder.commands.SetWidgetPropertyCommand 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)

Example 18 with SetWidgetPropertyCommand

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

the class WidgetNodeEditPolicy method getReconnectSourceCommand.

@Override
protected Command getReconnectSourceCommand(ReconnectRequest request) {
    ConnectionModel connection = (ConnectionModel) request.getConnectionEditPart().getModel();
    AbstractWidgetModel newSource = getWidgetEditPart().getWidgetModel();
    ConnectionAnchor anchor = getWidgetEditPart().getTargetConnectionAnchor(request);
    String newTerminal = getWidgetEditPart().getTerminalNameFromAnchor(anchor);
    ConnectionReconnectCommand cmd = new ConnectionReconnectCommand(connection);
    cmd.setNewSource(newSource);
    cmd.setNewSourceTerminal(newTerminal);
    // clear point list
    return cmd.chain(new SetWidgetPropertyCommand(connection, ConnectionModel.PROP_POINTS, new PointList()));
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) PointList(org.eclipse.draw2d.geometry.PointList) ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) ConnectionReconnectCommand(org.csstudio.opibuilder.commands.ConnectionReconnectCommand)

Aggregations

SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)18 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)12 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)11 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)3 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 PointList (org.eclipse.draw2d.geometry.PointList)3 Command (org.eclipse.gef.commands.Command)3 ArrayList (java.util.ArrayList)2 ConnectionReconnectCommand (org.csstudio.opibuilder.commands.ConnectionReconnectCommand)2 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)2 WidgetSetConstraintCommand (org.csstudio.opibuilder.commands.WidgetSetConstraintCommand)2 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)2 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)2 ConnectionAnchor (org.eclipse.draw2d.ConnectionAnchor)2 Point (org.eclipse.draw2d.geometry.Point)2 RunOPIAction (org.csstudio.opibuilder.actions.RunOPIAction)1 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)1 ChangeGuideCommand (org.csstudio.opibuilder.commands.ChangeGuideCommand)1