use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class VerticAlignmentCenter method doLayout.
/**
* @param wfm the manager holding the nodes to layout
* @param nodeParts the nodes to align
* @return a map with offsets for the nodes
*/
static Map<NodeContainerEditPart, Integer> doLayout(final WorkflowManagerUI wfm, final NodeContainerEditPart[] nodeParts) {
if (nodeParts.length == 0) {
return Collections.emptyMap();
}
NodeContainerEditPart[] nodes = nodeParts.clone();
// sorts by the y position
Arrays.sort(nodes, new Comparator<NodeContainerEditPart>() {
@Override
public int compare(final NodeContainerEditPart o1, final NodeContainerEditPart o2) {
NodeUIInformation ui1 = o1.getNodeContainer().getUIInformation();
NodeUIInformation ui2 = o2.getNodeContainer().getUIInformation();
if (ui1 == null || ui2 == null) {
return 0;
}
if (ui1.getBounds()[1] < ui2.getBounds()[1]) {
return -1;
} else {
return (ui1.getBounds()[1] > ui2.getBounds()[1]) ? 1 : 0;
}
}
});
// most left node is the anchor that doesn't change
HashMap<NodeContainerEditPart, Integer> offsets = new HashMap<NodeContainerEditPart, Integer>();
NodeUIInformation nui = nodes[0].getNodeContainer().getUIInformation();
if (nui == null) {
LOGGER.warn("Only nodes with location information can be aligned.");
return Collections.emptyMap();
}
int refX = nui.getBounds()[0];
for (int i = 1; /* idx 0 is anchor */
i < nodes.length; i++) {
NodeContainerUI nc = nodes[i].getNodeContainer();
NodeUIInformation ui = nc.getUIInformation();
if (ui.getBounds()[0] != refX) {
offsets.put(nodes[i], refX - ui.getBounds()[0]);
}
}
return offsets;
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class AutoLayoutAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public synchronized void runOnNodes(final NodeContainerEditPart[] parts) {
ScrollingGraphicalViewer provider = (ScrollingGraphicalViewer) getEditor().getEditorSite().getSelectionProvider();
if (provider == null) {
return;
}
ArrayList<NodeContainerUI> nodes = null;
if (parts != null && parts.length > 0) {
nodes = new ArrayList<NodeContainerUI>(parts.length);
for (NodeContainerEditPart p : parts) {
nodes.add(p.getNodeContainer());
}
}
AutoLayoutCommand alc = new AutoLayoutCommand(getManager(), nodes);
// enables undo
getCommandStack().execute(alc);
// 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.editparts.NodeContainerEditPart in project knime-core by knime.
the class NodeOutputView method selectionChanged.
/**
* The method updating the content of the monitor.
*
* {@inheritDoc}
*/
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (!(selection instanceof IStructuredSelection)) {
// showErrorAndClear("");
return;
}
IStructuredSelection structSel = (IStructuredSelection) selection;
if (m_pinned) {
m_lastSelectionWhilePinned = structSel;
if (m_branchLocked && m_selectionWhenLocked == null) {
m_selectionWhenLocked = structSel;
}
return;
}
if (structSel.equals(m_lastSelection)) {
// selection hasn't changed - return.
return;
}
m_lastSelection = structSel;
if (structSel.size() < 1) {
// Nothing selected
showErrorAndClear("No node selected");
return;
}
if (structSel.size() > 1) {
// too many selected items
showErrorAndClear("Multiple elements selected");
return;
}
// retrieve first (and only!) selection:
Iterator<?> selIt = structSel.iterator();
Object sel = selIt.next();
//
if (sel instanceof NodeContainerEditPart) {
// a NodeContainer was selected, display it's name and status
NodeContainer nc = Wrapper.unwrapNC(((NodeContainerEditPart) sel).getNodeContainer());
WorkflowManager wfm = nc.getParent();
checkWorkflowManagerListener(wfm);
updateNodeContainerInfo(nc.getID());
} else if (sel instanceof WorkflowInPortBarEditPart) {
WorkflowManager wfm = Wrapper.unwrapWFM(((WorkflowInPortBarEditPart) sel).getNodeContainer());
checkWorkflowManagerListener(wfm);
} else {
// unsupported selection
showErrorAndClear("No info available for this selection");
return;
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class PortGraphicalRoleEditPolicy method getConnectionCreateCommand.
/**
* This tries to initialize the command to create a connection as far as
* possible. However, it is completed by
* <code>getConnectionCompleteCommand</code>
*
* {@inheritDoc}
*/
@Override
protected Command getConnectionCreateCommand(final CreateConnectionRequest req) {
if (!(getHost() instanceof AbstractPortEditPart)) {
return null;
}
ConnectableEditPart nodePart = (ConnectableEditPart) getHost().getParent();
WorkflowManagerUI wm;
// TODO: if NodeContainerEditPart -> getParent
if (nodePart instanceof NodeContainerEditPart) {
NodeContainerEditPart p = (NodeContainerEditPart) nodePart;
wm = p.getWorkflowManager();
} else if (nodePart instanceof WorkflowInPortBarEditPart) {
WorkflowInPortBarEditPart barEditPart = (WorkflowInPortBarEditPart) nodePart;
WorkflowPortBar model = (WorkflowPortBar) barEditPart.getModel();
wm = model.getWorkflowManager();
} else {
return null;
}
CreateConnectionCommand cmd = new CreateConnectionCommand(Wrapper.unwrapWFM(wm));
if (getHost() instanceof NodeOutPortEditPart || getHost() instanceof WorkflowInPortEditPart || getHost() instanceof MetaNodeOutPortEditPart) {
// request started on out port?
cmd.setSourceNode(nodePart);
cmd.setSourcePortID(((AbstractPortEditPart) getHost()).getIndex());
cmd.setStartedOnOutPort(true);
} else if (getHost() instanceof NodeInPortEditPart || getHost() instanceof WorkflowOutPortEditPart) {
return null;
}
// we need the manager to execute the command
// we must remember this partially initialized command in the request.
req.setStartCommand(cmd);
return cmd;
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class SnapIconToGrid method getReferencePart.
/**
* Returns the part the request started on (the part that was dragged to move all selected nodes).
* @param parts
* @param mouseLoc
* @param moveDelta
* @return
*/
private EditPart getReferencePart(@SuppressWarnings("rawtypes") final List parts, final Point mouseLoc, final Point moveDelta) {
int i = 0;
Point loc = mouseLoc.getCopy().translate(moveDelta.getCopy().negate());
makeRelative(m_container.getContentPane(), loc);
while (i < parts.size()) {
GraphicalEditPart result = (GraphicalEditPart) parts.get(i);
if (result.getFigure().containsPoint(loc)) {
return result;
}
if (result instanceof NodeContainerEditPart) {
NodeAnnotationEditPart annoPart = ((NodeContainerEditPart) result).getNodeAnnotationEditPart();
if (annoPart.getFigure().containsPoint(loc)) {
return annoPart;
}
}
i++;
}
return null;
}
Aggregations