use of org.knime.workbench.editor2.commands.AddNewMetaNodeCommand in project knime-core by knime.
the class AddMetaNodeWizard method createMetaNodeFromPorts.
private void createMetaNodeFromPorts(final PortType[] inPorts, final PortType[] outPorts, final String name) {
Viewport viewPort = ((ScalableFreeformRootEditPart) m_wfEditor.getViewer().getRootEditPart()).getZoomManager().getViewport();
// get the currently visible area
Rectangle rect = viewPort.getClientArea();
// translate it to absolute coordinates (with respect to the scrolled
// editor viewer)
viewPort.translateToAbsolute(rect.getLocation());
// now we have an absolute point for the new metanode location
org.eclipse.draw2d.geometry.Point location = new org.eclipse.draw2d.geometry.Point(rect.x + (rect.width / 2), rect.y + (rect.height / 2));
// in order to get a local (relative position we have to substract the
// invisible offset
Point adaptedLoc = new Point(location.x - rect.x, location.y - rect.y);
EditPart ep;
// iterate until we have found a free place on the editor
do {
// we have to use the adaptedLoc (which is the relative position)
ep = m_wfEditor.getViewer().findObjectAt(adaptedLoc);
if (ep instanceof NodeContainerEditPart) {
// offset the absolute location
location.x += ((NodeContainerEditPart) ep).getFigure().getBounds().width;
location.y += ((NodeContainerEditPart) ep).getFigure().getBounds().height;
// offset the relative position
adaptedLoc.x += ((NodeContainerEditPart) ep).getFigure().getBounds().width;
adaptedLoc.y += ((NodeContainerEditPart) ep).getFigure().getBounds().height;
}
} while (ep instanceof NodeContainerEditPart);
AddNewMetaNodeCommand cmd = new AddNewMetaNodeCommand(m_wfEditor.getWorkflowManager().get(), inPorts, outPorts, name, location);
m_wfEditor.getViewer().getEditDomain().getCommandStack().execute(cmd);
}
Aggregations