Search in sources :

Example 1 with ClipboardObject

use of org.knime.workbench.editor2.ClipboardObject 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 ClipboardObject

use of org.knime.workbench.editor2.ClipboardObject in project knime-core by knime.

the class CopyAction method runInSWT.

/**
 * {@inheritDoc}
 */
@Override
public void runInSWT() {
    m_nodeParts = getSelectedParts(NodeContainerEditPart.class);
    m_annotationParts = getSelectedParts(AnnotationEditPart.class);
    NodeID[] ids = new NodeID[m_nodeParts.length];
    for (int i = 0; i < m_nodeParts.length; i++) {
        NodeContainerEditPart nodeEP = m_nodeParts[i];
        ids[i] = nodeEP.getNodeContainer().getID();
    }
    WorkflowAnnotation[] annotations = AnnotationEditPart.extractWorkflowAnnotations(m_annotationParts);
    WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
    content.setNodeIDs(ids);
    content.setAnnotation(annotations);
    WorkflowPersistor copyPersistor = getManager().copy(false, content.build());
    // the information about the nodes is stored in the config XML format
    // also used to store workflow information in the kflow files
    getEditor().setClipboardContent(new ClipboardObject(copyPersistor));
    // 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 : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) ClipboardObject(org.knime.workbench.editor2.ClipboardObject) NodeID(org.knime.core.node.workflow.NodeID) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 3 with ClipboardObject

use of org.knime.workbench.editor2.ClipboardObject 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)3 ShiftCalculator (org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator)2 Point (org.eclipse.draw2d.geometry.Point)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 NodeID (org.knime.core.node.workflow.NodeID)1 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)1 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 WorkflowPersistor (org.knime.core.node.workflow.WorkflowPersistor)1 PasteFromWorkflowPersistorCommand (org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand)1 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)1 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)1