Search in sources :

Example 1 with ShiftCalculator

use of org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator in project knime-core by knime.

the class PasteActionContextMenu method newShiftCalculator.

/**
 * {@inheritDoc}
 */
@Override
protected ShiftCalculator newShiftCalculator() {
    return new ShiftCalculator() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int[] calculateShift(final Iterable<int[]> boundsList, final WorkflowManager manager, final ClipboardObject clipObject) {
            int x = getEditor().getSelectionTool().getXLocation();
            int y = getEditor().getSelectionTool().getYLocation();
            int smallestX = Integer.MAX_VALUE;
            int smallestY = Integer.MAX_VALUE;
            for (int[] bounds : boundsList) {
                int currentX = bounds[0];
                int currentY = bounds[1];
                if (currentX < smallestX) {
                    smallestX = currentX;
                }
                if (currentY < smallestY) {
                    smallestY = currentY;
                }
            }
            ZoomManager zoomManager = (ZoomManager) getEditor().getViewer().getProperty(ZoomManager.class.toString());
            Point viewPortLocation = zoomManager.getViewport().getViewLocation();
            x += viewPortLocation.x;
            y += viewPortLocation.y;
            double zoom = zoomManager.getZoom();
            x /= zoom;
            y /= zoom;
            int shiftx = x - smallestX;
            int shifty = y - smallestY;
            if (getEditor().getEditorSnapToGrid()) {
                shiftx = getEditor().getEditorGridXOffset(shiftx);
                shifty = getEditor().getEditorGridYOffset(shifty);
            }
            return new int[] { shiftx, shifty };
        }
    };
}
Also used : ClipboardObject(org.knime.workbench.editor2.ClipboardObject) ZoomManager(org.eclipse.gef.editparts.ZoomManager) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Point(org.eclipse.draw2d.geometry.Point) ShiftCalculator(org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator) Point(org.eclipse.draw2d.geometry.Point)

Example 2 with ShiftCalculator

use of org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator in project knime-core by knime.

the class PasteAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    ClipboardObject clipObject = getEditor().getClipboardContent();
    ShiftCalculator shiftCalculator = newShiftCalculator();
    PasteFromWorkflowPersistorCommand pasteCommand = new PasteFromWorkflowPersistorCommand(getEditor(), clipObject, shiftCalculator);
    // enables undo
    getCommandStack().execute(pasteCommand);
    // update the actions
    getEditor().updateActions();
    // Give focus to the editor again. Otherwise the actions (selection)
    // is not updated correctly.
    getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
Also used : ClipboardObject(org.knime.workbench.editor2.ClipboardObject) PasteFromWorkflowPersistorCommand(org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand) ShiftCalculator(org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator)

Aggregations

ClipboardObject (org.knime.workbench.editor2.ClipboardObject)2 ShiftCalculator (org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator)2 Point (org.eclipse.draw2d.geometry.Point)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 PasteFromWorkflowPersistorCommand (org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand)1