Search in sources :

Example 86 with NodeContainerEditPart

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;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) HashMap(java.util.HashMap) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation)

Example 87 with NodeContainerEditPart

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());
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AutoLayoutCommand(org.knime.workbench.ui.layout.commands.AutoLayoutCommand)

Example 88 with NodeContainerEditPart

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;
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) PortObject(org.knime.core.node.port.PortObject) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)

Example 89 with NodeContainerEditPart

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;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart)

Example 90 with NodeContainerEditPart

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;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) Point(org.eclipse.draw2d.geometry.Point) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Aggregations

NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)77 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)28 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)24 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)16 EditPart (org.eclipse.gef.EditPart)15 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)14 Point (org.eclipse.draw2d.geometry.Point)11 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)11 NodeContainer (org.knime.core.node.workflow.NodeContainer)9 NodeID (org.knime.core.node.workflow.NodeID)9 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)9 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)9 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)9 ArrayList (java.util.ArrayList)8 GUIWorkflowCipherPrompt (org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)8 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)6 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)6 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 MessageBox (org.eclipse.swt.widgets.MessageBox)5