Search in sources :

Example 11 with SetWidgetPropertyCommand

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

the class PastePropertiesAction method createPasteCommand.

public Command createPasteCommand() {
    PropertiesCopyData propData = getPropetiesCopyDataFromClipboard();
    CompoundCommand cmd = new CompoundCommand("Paste Properties");
    for (AbstractWidgetModel targetWidget : getSelectedWidgetModels()) {
        for (String prop_id : propData.getPropIDList()) {
            if (targetWidget.getAllPropertyIDs().contains(prop_id)) {
                cmd.add(new SetWidgetPropertyCommand(targetWidget, prop_id, propData.getWidgetModel().getPropertyValue(prop_id)));
            }
        }
    }
    return cmd;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) PropertiesCopyData(org.csstudio.opibuilder.datadefinition.PropertiesCopyData) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 12 with SetWidgetPropertyCommand

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

the class OPIEditor method configureGraphicalViewer.

@Override
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) getGraphicalViewer();
    viewer.setEditPartFactory(new WidgetEditPartFactory(ExecutionMode.EDIT_MODE));
    ScalableFreeformRootEditPart root = new ScalableFreeformRootEditPart() {

        /**
         * {@inheritDoc}
         */
        @Override
        public Object getAdapter(@SuppressWarnings("rawtypes") final Class key) {
            if (key == AutoexposeHelper.class) {
                return new ViewportAutoexposeHelper(this);
            }
            return super.getAdapter(key);
        }
    };
    // set clipping strategy for connection layer of connection can be hide
    // when its source or target is not showing.
    ConnectionLayer connectionLayer = (ConnectionLayer) root.getLayer(LayerConstants.CONNECTION_LAYER);
    connectionLayer.setClippingStrategy(new PatchedConnectionLayerClippingStrategy(connectionLayer));
    viewer.setRootEditPart(root);
    viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer).setParent(getCommonKeyHandler()));
    ContextMenuProvider cmProvider = new OPIEditorContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(cmProvider);
    getSite().registerContextMenu(cmProvider, viewer);
    // Grid Action
    IAction action = new ToggleGridAction(getGraphicalViewer()) {

        @Override
        public boolean isChecked() {
            return getDisplayModel().isShowGrid();
        }

        @Override
        public void run() {
            getCommandStack().execute(new SetWidgetPropertyCommand(displayModel, DisplayModel.PROP_SHOW_GRID, !isChecked()));
        }
    };
    getActionRegistry().registerAction(action);
    // Ruler Action
    configureRuler();
    action = new ToggleRulerVisibilityAction(getGraphicalViewer()) {

        @Override
        public boolean isChecked() {
            return getDisplayModel().isShowRuler();
        }

        @Override
        public void run() {
            getCommandStack().execute(new SetWidgetPropertyCommand(displayModel, DisplayModel.PROP_SHOW_RULER, !isChecked()));
        }
    };
    getActionRegistry().registerAction(action);
    // Snap to Geometry Action
    IAction geometryAction = new ToggleSnapToGeometryAction(getGraphicalViewer()) {

        @Override
        public boolean isChecked() {
            return getDisplayModel().isSnapToGeometry();
        }

        @Override
        public void run() {
            getCommandStack().execute(new SetWidgetPropertyCommand(displayModel, DisplayModel.PROP_SNAP_GEOMETRY, !isChecked()));
        }
    };
    getActionRegistry().registerAction(geometryAction);
    // configure zoom actions
    ZoomManager zm = root.getZoomManager();
    if (zm != null) {
        List<String> zoomLevels = new ArrayList<>(3);
        zoomLevels.add(ZoomManager.FIT_ALL);
        zoomLevels.add(ZoomManager.FIT_WIDTH);
        zoomLevels.add(ZoomManager.FIT_HEIGHT);
        zm.setZoomLevelContributions(zoomLevels);
        zm.setZoomLevels(createZoomLevels());
        IAction zoomIn = new ZoomInAction(zm);
        IAction zoomOut = new ZoomOutAction(zm);
        getActionRegistry().registerAction(zoomIn);
        getActionRegistry().registerAction(zoomOut);
    }
    /* scroll-wheel zoom */
    getGraphicalViewer().setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON);
    // status line listener
    getGraphicalViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        private IStatusLineManager statusLine = ((ActionBarContributor) getEditorSite().getActionBarContributor()).getActionBars().getStatusLineManager();

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateStatusLine(statusLine);
        }
    });
}
Also used : ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) WidgetEditPartFactory(org.csstudio.opibuilder.editparts.WidgetEditPartFactory) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ViewportAutoexposeHelper(org.eclipse.gef.editparts.ViewportAutoexposeHelper) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) IAction(org.eclipse.jface.action.IAction) RunOPIAction(org.csstudio.opibuilder.actions.RunOPIAction) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ToggleRulerVisibilityAction(org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction) ConnectionLayer(org.eclipse.draw2d.ConnectionLayer) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) PatchedConnectionLayerClippingStrategy(org.csstudio.opibuilder.runmode.PatchedConnectionLayerClippingStrategy)

Example 13 with SetWidgetPropertyCommand

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

the class LockUnlockChildrenAction method createLockUnlockCommand.

public static Command createLockUnlockCommand(final GroupingContainerModel containerModel) {
    Command cmd = new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, !containerModel.isLocked()) {

        @Override
        public void execute() {
            super.execute();
            selectWidgets();
        }

        @Override
        public void undo() {
            super.undo();
            selectWidgets();
        }

        private void selectWidgets() {
            // must be queued so it is executed after property has been changed.
            GUIRefreshThread.getInstance(false).addIgnorableTask(new WidgetIgnorableUITask(this, new Runnable() {

                public void run() {
                    // if(!containerModel.isLocked())
                    // containerModel.selectWidgets(containerModel.getChildren(), false);
                    // else
                    containerModel.getParent().selectWidget(containerModel, false);
                }
            }, Display.getCurrent()));
        }
    };
    cmd.setLabel(containerModel.isLocked() ? "Unlock Children" : "Lock Children");
    return cmd;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) Command(org.eclipse.gef.commands.Command) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) WidgetIgnorableUITask(org.csstudio.opibuilder.datadefinition.WidgetIgnorableUITask)

Example 14 with SetWidgetPropertyCommand

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

the class DropPVtoXYGraphEditPolicy 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 XYGraphEditPart) {
            CompoundCommand command = new CompoundCommand("Add Traces");
            XYGraphModel xyGraphModel = (XYGraphModel) dropPVRequest.getTargetWidget().getWidgetModel();
            int existTraces = xyGraphModel.getTracesAmount();
            if (existTraces >= XYGraphModel.MAX_TRACES_AMOUNT)
                return null;
            command.add(new SetWidgetPropertyCommand(xyGraphModel, XYGraphModel.PROP_TRACE_COUNT, dropPVRequest.getPvNames().length + existTraces));
            int i = existTraces;
            for (String pvName : dropPVRequest.getPvNames()) {
                command.add(new SetWidgetPropertyCommand(xyGraphModel, XYGraphModel.makeTracePropID(XYGraphModel.TraceProperty.YPV.propIDPre, i), pvName));
                command.add(new SetWidgetPropertyCommand(xyGraphModel, XYGraphModel.makeTracePropID(XYGraphModel.TraceProperty.NAME.propIDPre, i), pvName));
                if (++i >= XYGraphModel.MAX_TRACES_AMOUNT)
                    break;
            }
            return command;
        }
    }
    return super.getCommand(request);
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) XYGraphModel(org.csstudio.opibuilder.widgets.model.XYGraphModel) DropPVRequest(org.csstudio.opibuilder.dnd.DropPVRequest) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 15 with SetWidgetPropertyCommand

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

the class DistributeWidgetsAction method getVerticalCompressCommand.

private Command getVerticalCompressCommand() {
    AbstractWidgetModel[] sortedModelArray = getSortedModelArray(false);
    CompoundCommand cmd = new CompoundCommand("Vertical Compress Distribution");
    int startX = sortedModelArray[0].getY() + sortedModelArray[0].getHeight();
    for (int i = 1; i < sortedModelArray.length; i++) {
        cmd.add(new SetWidgetPropertyCommand(sortedModelArray[i], AbstractWidgetModel.PROP_YPOS, startX));
        startX += sortedModelArray[i].getHeight();
    }
    return cmd;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

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