Search in sources :

Example 31 with WorkflowManagerUI

use of org.knime.core.ui.node.workflow.WorkflowManagerUI in project knime-core by knime.

the class AbstractWorkflowPortBarEditPart method getMinMaxXcoordInWorkflow.

/**
 * returns the minX coordinate and the maxX coordinate of all nodes, annotations and bendpoints in the flow (taking
 * the size of the elements into account). Or Integer.MIN/MAX_value if no elements exist.
 * @return new int[] {minX, maxX};
 */
protected int[] getMinMaxXcoordInWorkflow() {
    int maxX = Integer.MIN_VALUE;
    int minX = Integer.MAX_VALUE;
    // find the smallest and the biggest X coordinate in all the UI infos in the flow
    WorkflowManagerUI manager = ((WorkflowPortBar) getModel()).getWorkflowManager();
    for (NodeContainerUI nc : manager.getNodeContainers()) {
        int nodeWidth = NodeContainerFigure.WIDTH;
        NodeAnnotation nodeAnno = nc.getNodeAnnotation();
        if ((nodeAnno != null) && (nodeAnno.getWidth() > nodeWidth)) {
            nodeWidth = nodeAnno.getWidth();
        }
        NodeUIInformation uiInfo = nc.getUIInformation();
        if (uiInfo != null) {
            int x = uiInfo.getBounds()[0];
            // right border of node
            x = x + (nodeWidth / 2);
            if (maxX < x) {
                maxX = x;
            }
            // left border of node
            x = x - nodeWidth;
            if (minX > x) {
                minX = x;
            }
        }
    }
    for (WorkflowAnnotation anno : manager.getWorkflowAnnotations()) {
        int x = anno.getX();
        if (minX > x) {
            minX = x;
        }
        x = x + anno.getWidth();
        if (maxX < x) {
            maxX = x;
        }
    }
    for (ConnectionContainerUI conn : manager.getConnectionContainers()) {
        ConnectionUIInformation uiInfo = conn.getUIInfo();
        if (uiInfo != null) {
            int[][] bendpoints = uiInfo.getAllBendpoints();
            if (bendpoints != null) {
                for (int[] b : bendpoints) {
                    if (maxX < b[0]) {
                        maxX = b[0];
                    }
                    if (minX > b[0]) {
                        minX = b[0];
                    }
                }
            }
        }
    }
    return new int[] { minX, maxX };
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Example 32 with WorkflowManagerUI

use of org.knime.core.ui.node.workflow.WorkflowManagerUI in project knime-core by knime.

the class WorkflowInPortBarEditPart method getModelChildren.

/**
 * {@inheritDoc}
 */
@Override
protected List<NodePortUI> getModelChildren() {
    WorkflowManagerUI manager = ((WorkflowPortBar) getModel()).getWorkflowManager();
    List<NodePortUI> ports = new ArrayList<NodePortUI>();
    for (int i = 0; i < manager.getNrWorkflowIncomingPorts(); i++) {
        ports.add(manager.getInPort(i));
    }
    return ports;
}
Also used : WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) ArrayList(java.util.ArrayList) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodePortUI(org.knime.core.ui.node.workflow.NodePortUI)

Example 33 with WorkflowManagerUI

use of org.knime.core.ui.node.workflow.WorkflowManagerUI 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 34 with WorkflowManagerUI

use of org.knime.core.ui.node.workflow.WorkflowManagerUI in project knime-core by knime.

the class NodeContainerEditPart method getFreeInPort.

/**
 * @param sourceNode
 * @param srcPortIdx
 * @return the first free port the specified port could be connected to. Or -1 if there is none.
 */
public int getFreeInPort(final ConnectableEditPart sourceNode, final int srcPortIdx) {
    WorkflowManagerUI wm = getWorkflowManager();
    if (wm == null || sourceNode == null || srcPortIdx < 0) {
        return -1;
    }
    // skip variable ports
    int startPortIdx = 1;
    int connPortIdx = -1;
    NodeContainerUI nc = getNodeContainer();
    if (nc instanceof WorkflowManagerUI) {
        startPortIdx = 0;
    }
    for (int i = startPortIdx; i < nc.getNrInPorts(); i++) {
        if (wm.canAddNewConnection(sourceNode.getNodeContainer().getID(), srcPortIdx, nc.getID(), i)) {
            connPortIdx = i;
            break;
        }
    }
    if ((connPortIdx < 0) && (startPortIdx == 1) && wm.canAddConnection(sourceNode.getNodeContainer().getID(), srcPortIdx, nc.getID(), 0)) {
        // if the src is a flow var port, connect it to impl flow var port
        connPortIdx = 0;
    }
    return connPortIdx;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) Point(org.eclipse.draw2d.geometry.Point)

Example 35 with WorkflowManagerUI

use of org.knime.core.ui.node.workflow.WorkflowManagerUI in project knime-core by knime.

the class KnimeResourceContentProvider method hasChildren.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasChildren(final Object element) {
    if (element instanceof IFile) {
        return false;
    }
    if (isKNIMEWorkflow(element)) {
        IContainer project = (IContainer) element;
        NodeContainerUI workflow = ProjectWorkflowMap.getWorkflowUI(project.getLocationURI());
        if (workflow != null) {
            // the number of contained nodes is returned
            return ((WorkflowManagerUI) workflow).getNodeContainers().size() > 0;
        }
    } else if (element instanceof WorkflowManagerUI) {
        return ((WorkflowManagerUI) element).getNodeContainers().size() > 0;
    }
    // then it is a node and has no children
    if (element instanceof IContainer) {
        IContainer container = (IContainer) element;
        if (isKNIMEWorkflow(container.getParent())) {
            return false;
        }
    }
    return getFolders(element).length > 0;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) IFile(org.eclipse.core.resources.IFile) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) IContainer(org.eclipse.core.resources.IContainer)

Aggregations

WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)37 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)16 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)12 SubNodeContainerUI (org.knime.core.ui.node.workflow.SubNodeContainerUI)7 ArrayList (java.util.ArrayList)6 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)6 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)5 URI (java.net.URI)3 IContainer (org.eclipse.core.resources.IContainer)3 Point (org.eclipse.draw2d.geometry.Point)3 EditPart (org.eclipse.gef.EditPart)3 Image (org.eclipse.swt.graphics.Image)3 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)3 NodeID (org.knime.core.node.workflow.NodeID)3 SingleNodeContainerUI (org.knime.core.ui.node.workflow.SingleNodeContainerUI)3 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)3 WorkflowInPortEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)3 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2