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 };
}
};
}
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());
}
Aggregations