Search in sources :

Example 26 with WorkflowManagerUI

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

the class SaveAsMetaNodeTemplateAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of
 *         <code>WorkflowManager</code> and there is no link associated
 *         with it, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    if (getManager().isWriteProtected()) {
        return false;
    }
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    Object model = nodes[0].getModel();
    if (model instanceof WorkflowManagerUI) {
        WorkflowManagerUI wm = (WorkflowManagerUI) model;
        switch(Wrapper.unwrapWFM(wm).getTemplateInformation().getRole()) {
            case None:
                break;
            default:
                return false;
        }
        for (AbstractContentProvider p : ExplorerMountTable.getMountedContent().values()) {
            if (p.canHostMetaNodeTemplates()) {
                return true;
            }
        }
    }
    return false;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) ContentObject(org.knime.workbench.explorer.view.ContentObject)

Example 27 with WorkflowManagerUI

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

the class AbstractCreateNewConnectedNodeCommand method getMatchingPorts.

private Map<Integer, Integer> getMatchingPorts(final NodeContainer left, final NodeContainer right) {
    // don't auto connect to flow var ports - start with port index 1
    int leftFirst = (left instanceof WorkflowManagerUI) ? 0 : 1;
    int rightFirst = (right instanceof WorkflowManagerUI) ? 0 : 1;
    Map<Integer, Integer> matchingPorts = new TreeMap<Integer, Integer>();
    Map<Integer, Integer> possibleMatches = new TreeMap<Integer, Integer>();
    Set<Integer> assignedRight = new HashSet<Integer>();
    for (int rightPidx = rightFirst; rightPidx < right.getNrInPorts(); rightPidx++) {
        for (int leftPidx = leftFirst; leftPidx < left.getNrOutPorts(); leftPidx++) {
            NodeOutPort leftPort = left.getOutPort(leftPidx);
            NodeInPort rightPort = right.getInPort(rightPidx);
            PortType leftPortType = leftPort.getPortType();
            PortType rightPortType = rightPort.getPortType();
            if (leftPortType.isSuperTypeOf(rightPortType)) {
                if (getHostWFM().getOutgoingConnectionsFor(left.getID(), leftPidx).size() == 0) {
                    if (!matchingPorts.containsKey(leftPidx) && !assignedRight.contains(rightPidx)) {
                        // output not connected: use it.
                        matchingPorts.put(leftPidx, rightPidx);
                        assignedRight.add(rightPidx);
                    }
                } else {
                    // port already connected - we MAY use it
                    if (!possibleMatches.containsKey(leftPidx) && !assignedRight.contains(rightPidx)) {
                        possibleMatches.put(leftPidx, rightPidx);
                    }
                }
            }
        }
    }
    for (Map.Entry<Integer, Integer> entry : possibleMatches.entrySet()) {
        Integer pl = entry.getKey();
        Integer pr = entry.getValue();
        if (!matchingPorts.containsKey(pl) && !assignedRight.contains(pr)) {
            matchingPorts.put(pl, pr);
            assignedRight.add(pr);
        }
    }
    return matchingPorts;
}
Also used : NodeInPort(org.knime.core.node.workflow.NodeInPort) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Point(org.eclipse.draw2d.geometry.Point) HashSet(java.util.HashSet) PortType(org.knime.core.node.port.PortType)

Example 28 with WorkflowManagerUI

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

the class RepositoryFactory method createMetaNode.

/**
 * @param configuration content of the extension
 * @return a meta node template
 */
public static MetaNodeTemplate createMetaNode(final IConfigurationElement configuration) {
    String id = configuration.getAttribute("id");
    String name = configuration.getAttribute("name");
    String workflowDir = configuration.getAttribute("workflowDir");
    String after = configuration.getAttribute("after");
    String iconPath = configuration.getAttribute("icon");
    String categoryPath = configuration.getAttribute("category-path");
    String pluginId = configuration.getDeclaringExtension().getNamespaceIdentifier();
    String description = configuration.getAttribute("description");
    WorkflowManagerUI manager = loadMetaNode(pluginId, workflowDir);
    if (manager == null) {
        LOGGER.error("MetaNode  " + name + " could not be loaded. " + "Skipped.");
        return null;
    }
    MetaNodeTemplate template = new MetaNodeTemplate(id, name, categoryPath, configuration.getContributor().getName(), manager);
    if (after != null && !after.isEmpty()) {
        template.setAfterID(after);
    }
    if (description != null) {
        template.setDescription(description);
    }
    if (!Boolean.getBoolean("java.awt.headless")) {
        // Load images from declaring plugin
        Image icon = null;
        if (iconPath != null) {
            icon = ImageRepository.getIconImage(pluginId, iconPath);
        }
        if (icon == null) {
            LOGGER.coding("Icon '" + iconPath + "' for metanode " + categoryPath + "/" + name + " does not exist");
            icon = ImageRepository.getIconImage(SharedImages.DefaultMetaNodeIcon);
        }
        template.setIcon(icon);
    }
    return template;
}
Also used : MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) Image(org.eclipse.swt.graphics.Image)

Example 29 with WorkflowManagerUI

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

the class DynamicNodeDescriptionCreator method addSubWorkflowDescription.

private void addSubWorkflowDescription(final NodeContainerUI nc, final boolean useSingleLine, final StringBuilder bld) {
    WorkflowManagerUI wfm;
    if (nc instanceof SubNodeContainerUI) {
        wfm = ((SubNodeContainerUI) nc).getWorkflowManager();
    } else {
        wfm = (WorkflowManagerUI) nc;
    }
    if (!useSingleLine) {
        bld.append(getHeader());
        bld.append("<h1>");
        bld.append(nc.getName());
        bld.append("</h1>");
        if (nc.getCustomDescription() != null) {
            bld.append("<h2>Description:</h2>");
            bld.append("<p>" + nc.getCustomDescription() + "</p>");
        }
        bld.append("<h2>Contained nodes: </h2>");
        for (NodeContainerUI child : wfm.getNodeContainers()) {
            addDescription(child, true, bld);
        }
        bld.append("</body></html>");
    } else {
        bld.append("<dt><b>");
        bld.append(nc.getName() + " contained nodes:");
        bld.append("</b></dt>");
        bld.append("<dd>");
        bld.append("<dl>");
        for (NodeContainerUI child : wfm.getNodeContainers()) {
            addDescription(child, true, bld);
        }
        bld.append("</dl>");
        bld.append("</dd>");
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI)

Example 30 with WorkflowManagerUI

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

the class ShiftConnectionCommand method getLastConnectedPort.

/**
 * @return the lowest index of a port that is not connected.
 */
private int getLastConnectedPort() {
    NodeContainerUI nc = m_node.getNodeContainer();
    int startIdx = 1;
    if (nc instanceof WorkflowManagerUI) {
        startIdx = 0;
    }
    int lastConnPort = -1;
    for (int p = startIdx; p < nc.getNrInPorts(); p++) {
        if (getHostWFM().getIncomingConnectionFor(m_nodeID, p) != null) {
            lastConnPort = p;
        }
    }
    if ((lastConnPort < 0) && (startIdx > 0) && (getHostWFM().getIncomingConnectionFor(m_nodeID, 0) != null)) {
        // test the implicit flow var port, if it is the only connected port
        lastConnPort = 0;
    }
    return lastConnPort;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI)

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