Search in sources :

Example 1 with NodeFactory

use of org.knime.core.node.NodeFactory in project knime-core by knime.

the class RepositoryFactory method createNode.

/**
 * Creates a new node repository object. Throws an exception, if this fails
 *
 * @param element Configuration element from the contributing plugin
 * @return NodeTemplate object to be used within the repository.
 * @throws IllegalArgumentException If the element is not compatible (e.g.
 *             wrong attributes, or factory class not found)
 */
@SuppressWarnings("unchecked")
public static NodeTemplate createNode(final IConfigurationElement element) {
    // Try to load the node factory class...
    NodeFactory<? extends NodeModel> factory;
    // this ensures that the class is loaded by the correct eclipse
    // classloaders
    GlobalClassCreator.lock.lock();
    try {
        factory = (NodeFactory<? extends NodeModel>) element.createExecutableExtension("factory-class");
    } catch (Throwable e) {
        throw new IllegalArgumentException("Can't load factory class for node: " + element.getAttribute("factory-class"), e);
    } finally {
        GlobalClassCreator.lock.unlock();
    }
    if (factory instanceof DynamicNodeFactory) {
        throw new IllegalArgumentException("Dynamic node factory '" + element.getAttribute("factory-class") + "'" + " registered as normal node factory.");
    }
    String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
    NodeTemplate node = new NodeTemplate((Class<NodeFactory<? extends NodeModel>>) factory.getClass(), factory.getNodeName(), pluginID);
    node.setAfterID(str(element.getAttribute("after"), ""));
    node.setType(factory.getType());
    if (!Boolean.valueOf(System.getProperty("java.awt.headless", "false"))) {
        // Load images from declaring plugin
        Image icon = ImageRepository.getIconImage(factory);
        node.setIcon(icon);
    }
    node.setCategoryPath(str(element.getAttribute("category-path"), "/"));
    return node;
}
Also used : NodeModel(org.knime.core.node.NodeModel) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) NodeFactory(org.knime.core.node.NodeFactory) DynamicNodeFactory(org.knime.core.node.DynamicNodeFactory) Image(org.eclipse.swt.graphics.Image) DynamicNodeFactory(org.knime.core.node.DynamicNodeFactory)

Example 2 with NodeFactory

use of org.knime.core.node.NodeFactory in project knime-core by knime.

the class NewWorkflowContainerEditPolicy method getCreateCommand.

/**
 * {@inheritDoc}
 */
@Override
protected Command getCreateCommand(final CreateRequest request) {
    // point where the command occurred
    // The node/description should be initially located here
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    WorkflowRootEditPart workflowPart = (WorkflowRootEditPart) this.getHost();
    if (!Wrapper.wraps(workflowPart.getWorkflowManager(), WorkflowManager.class)) {
        // adding new nodes not supported yet by UI-interfaces and implemenations
        LOGGER.error("Adding new nodes not supported by '" + workflowPart.getWorkflowManager().getClass().getSimpleName() + "'.");
        return null;
    }
    WorkflowManager manager = Wrapper.unwrapWFM(workflowPart.getWorkflowManager());
    if (request instanceof CreateDropRequest) {
        Object obj = request.getNewObject();
        CreateDropRequest cdr = (CreateDropRequest) request;
        if (obj instanceof NodeFactory) {
            return handleNodeDrop(manager, (NodeFactory<? extends NodeModel>) obj, cdr);
        } else if (obj instanceof AbstractExplorerFileStore) {
            AbstractExplorerFileStore fs = (AbstractExplorerFileStore) obj;
            if (AbstractExplorerFileStore.isWorkflowTemplate(fs)) {
                return handleMetaNodeTemplateDrop(manager, cdr, fs);
            }
        } else if (obj instanceof WorkflowPersistor) {
            return handleMetaNodeDrop(manager, (WorkflowPersistor) obj, cdr);
        } else if (obj instanceof ReaderNodeSettings) {
            ReaderNodeSettings settings = (ReaderNodeSettings) obj;
            return new DropNodeCommand(manager, settings.getFactory(), new NodeCreationContext(settings.getUrl()), request.getLocation(), snapToGrid);
        } else {
            LOGGER.error("Illegal drop object: " + obj);
        }
    }
    return null;
}
Also used : CreateDropRequest(org.knime.workbench.editor2.CreateDropRequest) DropNodeCommand(org.knime.workbench.editor2.commands.DropNodeCommand) ReaderNodeSettings(org.knime.workbench.editor2.ReaderNodeSettings) NodeFactory(org.knime.core.node.NodeFactory) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) NodeCreationContext(org.knime.core.node.NodeCreationContext)

Example 3 with NodeFactory

use of org.knime.core.node.NodeFactory in project knime-core by knime.

the class FileNativeNodeContainerPersistor method guessPortTypesFromConnectedNodes.

/**
 * {@inheritDoc}
 */
@Override
public void guessPortTypesFromConnectedNodes(final NodeAndBundleInformation nodeInfo, final NodeSettingsRO additionalFactorySettings, final ArrayList<PersistorWithPortIndex> upstreamNodes, final ArrayList<List<PersistorWithPortIndex>> downstreamNodes) {
    if (m_node == null) {
        /* Input ports from the connection table. */
        // first is flow var port
        PortType[] inPortTypes = new PortType[Math.max(upstreamNodes.size() - 1, 0)];
        // default to BDT for unconnected ports
        Arrays.fill(inPortTypes, BufferedDataTable.TYPE);
        for (int i = 0; i < inPortTypes.length; i++) {
            // first is flow var port
            PersistorWithPortIndex p = upstreamNodes.get(i + 1);
            if (p != null) {
                PortType portTypeFromUpstreamNode = p.getPersistor().getUpstreamPortType(p.getPortIndex());
                if (portTypeFromUpstreamNode != null) {
                    // null if upstream is missing, too
                    inPortTypes[i] = portTypeFromUpstreamNode;
                }
            }
        }
        /* Output ports from node settings (saved ports) -- if possible (executed) */
        String nodeName = nodeInfo.getNodeNameNotNull();
        PortType[] outPortTypes;
        try {
            LoadResult guessLoadResult = new LoadResult("Port type guessing for missing node \"" + nodeName + "\"");
            NodeSettingsRO settingsForNode = loadSettingsForNode(guessLoadResult);
            FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
            outPortTypes = nodePersistor.guessOutputPortTypes(guessLoadResult, nodeName);
            if (guessLoadResult.hasErrors()) {
                getLogger().debug("Errors guessing port types for missing node \"" + nodeName + "\": " + guessLoadResult.getFilteredError("", LoadResultEntryType.Error));
            }
        } catch (Exception e) {
            getLogger().debug("Unable to guess port types for missing node \"" + nodeName + "\"", e);
            outPortTypes = null;
        }
        if (outPortTypes == null) {
            // couldn't guess port types from looking at node settings (e.g. not executed)
            // default to BDT for unconnected ports
            outPortTypes = new PortType[Math.max(downstreamNodes.size() - 1, 0)];
        }
        for (int i = 0; i < outPortTypes.length; i++) {
            PortType type = outPortTypes[i];
            // output types may be partially filled by settings guessing above, list may be empty or too short
            List<PersistorWithPortIndex> list = i < downstreamNodes.size() - 1 ? downstreamNodes.get(i + 1) : null;
            if (list != null) {
                assert !list.isEmpty();
                for (PersistorWithPortIndex p : list) {
                    PortType current = p.getPersistor().getDownstreamPortType(p.getPortIndex());
                    if (current == null) {
                    // ignore, downstream node is also missing
                    } else if (type == null) {
                        type = current;
                    } else if (type.equals(current)) {
                    // keep type
                    } else {
                        // this shouldn't really happen - someone changed port types between versions
                        type = PortObject.TYPE;
                    }
                }
                outPortTypes[i] = type;
            }
            if (outPortTypes[i] == null) {
                // might still be null if missing node is only connected to missing node, fallback: BDT
                outPortTypes[i] = BufferedDataTable.TYPE;
            }
        }
        MissingNodeFactory nodefactory = new MissingNodeFactory(nodeInfo, additionalFactorySettings, inPortTypes, outPortTypes);
        if (getLoadVersion().ordinal() < FileWorkflowPersistor.VERSION_LATEST.ordinal()) {
            nodefactory.setCopyInternDirForWorkflowVersionChange(true);
        }
        nodefactory.init();
        m_node = new Node((NodeFactory) nodefactory);
    }
}
Also used : Node(org.knime.core.node.Node) FileNodePersistor(org.knime.core.node.FileNodePersistor) LoadResult(org.knime.core.node.workflow.WorkflowPersistor.LoadResult) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeFactoryUnknownException(org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException) IOException(java.io.IOException) NodeFactory(org.knime.core.node.NodeFactory) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) PortType(org.knime.core.node.port.PortType)

Example 4 with NodeFactory

use of org.knime.core.node.NodeFactory in project knime-core by knime.

the class JoinerJoinAnyTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    NodeFactory<NodeModel> dummyFactory = (NodeFactory) new VirtualParallelizedChunkPortObjectInNodeFactory(new PortType[0]);
    m_exec = new ExecutionContext(new DefaultNodeProgressMonitor(), new Node(dummyFactory), SingleNodeContainer.MemoryPolicy.CacheOnDisc, new HashMap<Integer, ContainerTable>());
}
Also used : NodeModel(org.knime.core.node.NodeModel) ExecutionContext(org.knime.core.node.ExecutionContext) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) NodeFactory(org.knime.core.node.NodeFactory) HashMap(java.util.HashMap) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) Node(org.knime.core.node.Node) PortType(org.knime.core.node.port.PortType) Before(org.junit.Before)

Example 5 with NodeFactory

use of org.knime.core.node.NodeFactory in project knime-core by knime.

the class WorkflowManager method internalAddNewNode.

@SuppressWarnings("unchecked")
private NodeID internalAddNewNode(final NodeFactory<?> factory, final NodeCreationContext context) {
    try (WorkflowLock lock = lock()) {
        // TODO synchronize to avoid messing with running workflows!
        assert factory != null;
        // insert node
        NodeID newID = m_workflow.createUniqueID();
        NativeNodeContainer container = new NativeNodeContainer(this, new Node((NodeFactory<NodeModel>) factory, context), newID);
        addNodeContainer(container, true);
        configureNodeAndSuccessors(newID, true);
        if (context != null) {
            // save node settings if source URL/context was provided (bug 5772)
            container.saveNodeSettingsToDefault();
        }
        LOGGER.debug("Added new node " + newID);
        setDirty();
        return newID;
    }
}
Also used : VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) NodeFactory(org.knime.core.node.NodeFactory) VirtualParallelizedChunkPortObjectOutNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectOutNodeFactory) InteractiveNode(org.knime.core.node.interactive.InteractiveNode) Node(org.knime.core.node.Node) InputNode(org.knime.core.node.dialog.InputNode) DialogNode(org.knime.core.node.dialog.DialogNode) QuickFormInputNode(org.knime.core.quickform.in.QuickFormInputNode) OutputNode(org.knime.core.node.dialog.OutputNode) CredentialsNode(org.knime.core.node.workflow.CredentialsStore.CredentialsNode) MetaNodeDialogNode(org.knime.core.node.dialog.MetaNodeDialogNode)

Aggregations

NodeFactory (org.knime.core.node.NodeFactory)17 Node (org.knime.core.node.Node)11 NodeModel (org.knime.core.node.NodeModel)11 HashMap (java.util.HashMap)7 PortType (org.knime.core.node.port.PortType)7 VirtualParallelizedChunkPortObjectInNodeFactory (org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory)7 Before (org.junit.Before)6 DefaultNodeProgressMonitor (org.knime.core.node.DefaultNodeProgressMonitor)6 ExecutionContext (org.knime.core.node.ExecutionContext)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 MissingNodeFactory (org.knime.core.node.missing.MissingNodeFactory)3 IContainerObject (org.knime.workbench.repository.model.IContainerObject)3 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)3 IOException (java.io.IOException)2 Image (org.eclipse.swt.graphics.Image)2 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)2 ConfigurableNodeFactory (org.knime.core.node.ConfigurableNodeFactory)2 FileNodePersistor (org.knime.core.node.FileNodePersistor)2 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)2 DialogNode (org.knime.core.node.dialog.DialogNode)2