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