Search in sources :

Example 16 with Request

use of org.eclipse.gef.Request in project tdi-studio-se by Talend.

the class BusinessItemRelationshipNameEditPart method performDirectEditRequest.

/**
     * @generated
     */
protected void performDirectEditRequest(Request request) {
    final Request theRequest = request;
    try {
        getEditingDomain().runExclusive(new Runnable() {

            public void run() {
                if (isActive() && isEditable()) {
                    if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
                        Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
                        performDirectEdit(initialChar.charValue());
                    } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
                        DirectEditRequest editRequest = (DirectEditRequest) theRequest;
                        performDirectEdit(editRequest.getLocation());
                    } else {
                        performDirectEdit();
                    }
                }
            }
        });
    } catch (InterruptedException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest) Request(org.eclipse.gef.Request) DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest)

Example 17 with Request

use of org.eclipse.gef.Request in project tdi-studio-se by Talend.

the class TerminalBusinessItemNameEditPart method performDirectEditRequest.

/**
     * @generated
     */
protected void performDirectEditRequest(Request request) {
    final Request theRequest = request;
    try {
        getEditingDomain().runExclusive(new Runnable() {

            public void run() {
                if (isActive() && isEditable()) {
                    if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
                        Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
                        performDirectEdit(initialChar.charValue());
                    } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
                        DirectEditRequest editRequest = (DirectEditRequest) theRequest;
                        performDirectEdit(editRequest.getLocation());
                    } else {
                        performDirectEdit();
                    }
                }
            }
        });
    } catch (InterruptedException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest) Request(org.eclipse.gef.Request) DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest)

Example 18 with Request

use of org.eclipse.gef.Request in project knime-core by knime.

the class WorkflowSelectionDragEditPartsTracker method getCommand.

/**
 * Asks each edit part in the
 * {@link org.eclipse.gef.tools.AbstractTool#getOperationSet() operation set}
 * to contribute to a {@link CompoundCommand} after first setting the
 * request type to either {@link org.eclipse.gef.RequestConstants#REQ_MOVE}
 * or {@link org.eclipse.gef.RequestConstants#REQ_ORPHAN}, depending on the
 * result of {@link #isMove()}.
 *
 * Additionally the method creates a command to adapt connections where both
 * node container are include in the drag operation.
 *
 * {@inheritDoc}
 */
@Override
protected Command getCommand() {
    CompoundCommand command = new CompoundCommand();
    command.setDebugLabel("Drag Object Tracker");
    Iterator iter = getOperationSet().iterator();
    Request request = getTargetRequest();
    if (isCloneActive()) {
        request.setType(REQ_CLONE);
    } else if (isMove()) {
        request.setType(REQ_MOVE);
    } else {
        request.setType(REQ_ORPHAN);
    }
    if (!isCloneActive()) {
        while (iter.hasNext()) {
            EditPart editPart = (EditPart) iter.next();
            command.add(editPart.getCommand(request));
        }
    }
    // now add the commands for the node-embraced connections
    ConnectionContainerEditPart[] connectionsToAdapt = getEmbracedConnections(getOperationSet());
    for (ConnectionContainerEditPart connectionPart : connectionsToAdapt) {
        command.add(connectionPart.getBendpointAdaptionCommand(request));
    }
    if (!isMove() || isCloneActive()) {
        if (!isCloneActive()) {
            request.setType(REQ_ADD);
        }
        if (getTargetEditPart() == null) {
            command.add(UnexecutableCommand.INSTANCE);
        } else {
            command.add(getTargetEditPart().getCommand(getTargetRequest()));
        }
    }
    return command;
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) Iterator(java.util.Iterator) Request(org.eclipse.gef.Request) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 19 with Request

use of org.eclipse.gef.Request in project knime-core by knime.

the class WorkflowSelectionTool method getTargetRequest.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
protected Request getTargetRequest() {
    Request targetRequest = super.getTargetRequest();
    Point start = new Point(m_xLocation, m_yLocation);
    ZoomManager zm = (ZoomManager) getCurrentViewer().getProperty(ZoomManager.class.toString());
    WorkflowEditor.adaptZoom(zm, start, true);
    targetRequest.getExtendedData().put(DRAG_START_LOCATION, start);
    return targetRequest;
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) Request(org.eclipse.gef.Request) Point(org.eclipse.draw2d.geometry.Point)

Example 20 with Request

use of org.eclipse.gef.Request in project yamcs-studio by yamcs.

the class OPIRuntimeDelegate method createGUI.

public void createGUI(Composite parent) {
    viewer = new PatchedScrollingGraphicalViewer();
    if (displayModel != null) {
        displayModel.setOpiRuntime(opiRuntime);
        displayModel.setViewer(viewer);
    }
    ScalableFreeformRootEditPart root = new PatchedScalableFreeformRootEditPart() {

        // In Run mode, clicking the Display or container should de-select
        // all widgets.
        @Override
        public DragTracker getDragTracker(Request req) {
            return new DragEditPartsTracker(this);
        }

        @Override
        public boolean isSelectable() {
            return false;
        }
    };
    // 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.createControl(parent);
    viewer.setRootEditPart(root);
    viewer.setEditPartFactory(new WidgetEditPartFactory(ExecutionMode.RUN_MODE, site));
    // viewer.addDropTargetListener(new
    // ProcessVariableNameTransferDropPVTargetListener(viewer));
    // viewer.addDropTargetListener(new
    // TextTransferDropPVTargetListener(viewer));
    // Add drag listener will make click feel stagnant.
    // viewer.addDragSourceListener(new DragPVSourceListener(viewer));
    // this will make viewer as a selection provider
    EditDomain editDomain = new EditDomain() {

        @Override
        public void loadDefaultTool() {
            setActiveTool(new RuntimePatchedSelectionTool());
        }
    };
    editDomain.addViewer(viewer);
    // connect the CSS menu
    ContextMenuProvider cmProvider = new OPIRunnerContextMenuProvider(viewer, opiRuntime);
    viewer.setContextMenu(cmProvider);
    opiRuntime.getSite().registerContextMenu(cmProvider, viewer);
    if (displayModelFilled) {
        viewer.setContents(displayModel);
        displayModel.setViewer(viewer);
        displayModel.setOpiRuntime(opiRuntime);
        updateEditorTitle();
    }
    zoomManager = root.getZoomManager();
    if (zoomManager != null) {
        List<String> zoomLevels = new ArrayList<>(3);
        zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_ALL);
        zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_WIDTH);
        zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_HEIGHT);
        zoomManager.setZoomLevelContributions(zoomLevels);
        zoomManager.setZoomLevels(createZoomLevels());
    // IAction zoomIn = new ZoomInAction(zoomManager);
    // IAction zoomOut = new ZoomOutAction(zoomManager);
    // getActionRegistry().registerAction(zoomIn);
    // getActionRegistry().registerAction(zoomOut);
    }
    /* scroll-wheel zoom */
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON);
    /*
         * When Figure instance which corresponds to RootEditPart is updated, calculate the frame rate and set the
         * measured rate to "frame_rate" property of the corresponding DisplayModel instance.
         *
         * By default, org.eclipse.draw2d.DeferredUpdateManager is used. This update manager queues update requests from
         * figures and others, and it repaints requested figures at once when GUI thread is ready to repaint.
         * notifyPainting() method of UpdateLister is called when it repaints. The frame rate is calculated based on the
         * timing of notifyPainting().
         *
         * Note that the update manager repaints only requested figures. It does not repaint all figures at once. For
         * example, if there are only two widgets in one display, these widgets might be repainted alternately. In that
         * case, the frame rate indicates the inverse of the time between the repainting of one widget and the
         * repainting of the other widget, which is different from our intuition. Thus, you have to be careful about the
         * meaning of "frame rate" calculated by the following code.
         */
    if (displayModelFilled && displayModel.isFreshRateEnabled()) {
        UpdateManager updateManager = root.getFigure().getUpdateManager();
        updateManager.addUpdateListener(new UpdateListener() {

            // in milliseconds
            private long updateCycle = -1;

            private Date previousDate = null;

            @Override
            public void notifyPainting(Rectangle damage, @SuppressWarnings("rawtypes") Map dirtyRegions) {
                Date currentDate = new Date();
                if (previousDate == null) {
                    previousDate = currentDate;
                    return;
                }
                synchronized (previousDate) {
                    updateCycle = currentDate.getTime() - previousDate.getTime();
                    displayModel.setFrameRate(1000.0 / updateCycle);
                    previousDate = currentDate;
                }
            }

            @Override
            public void notifyValidating() {
            // Do nothing
            }
        });
    }
}
Also used : EditDomain(org.eclipse.gef.EditDomain) WidgetEditPartFactory(org.csstudio.opibuilder.editparts.WidgetEditPartFactory) Request(org.eclipse.gef.Request) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DragEditPartsTracker(org.eclipse.gef.tools.DragEditPartsTracker) ConnectionLayer(org.eclipse.draw2d.ConnectionLayer) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) Date(java.util.Date) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) UpdateManager(org.eclipse.draw2d.UpdateManager) UpdateListener(org.eclipse.draw2d.UpdateListener) Map(java.util.Map)

Aggregations

Request (org.eclipse.gef.Request)30 DirectEditRequest (org.eclipse.gef.requests.DirectEditRequest)25 ArrayList (java.util.ArrayList)13 List (java.util.List)12 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)12 Command (org.eclipse.gef.commands.Command)11 NonResizableEditPolicy (org.eclipse.gef.editpolicies.NonResizableEditPolicy)11 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)11 LabelDirectEditPolicy (org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy)11 EditPart (org.eclipse.gef.EditPart)3 Iterator (java.util.Iterator)2 Date (java.util.Date)1 Map (java.util.Map)1 WidgetEditPartFactory (org.csstudio.opibuilder.editparts.WidgetEditPartFactory)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ConnectionLayer (org.eclipse.draw2d.ConnectionLayer)1 UpdateListener (org.eclipse.draw2d.UpdateListener)1 UpdateManager (org.eclipse.draw2d.UpdateManager)1 Point (org.eclipse.draw2d.geometry.Point)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1