Search in sources :

Example 26 with NodeModel

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

the class AbstractRepositoryView method hookDoubleClickAction.

private void hookDoubleClickAction() {
    m_viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(final DoubleClickEvent event) {
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (o instanceof NodeTemplate) {
                NodeTemplate tmplt = (NodeTemplate) o;
                NodeFactory<? extends NodeModel> nodeFact;
                try {
                    nodeFact = tmplt.createFactoryInstance();
                } catch (Exception e) {
                    LOGGER.error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
                    return;
                }
                boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
                if (added) {
                    NodeUsageRegistry.addNode(tmplt);
                }
            } else if (o instanceof MetaNodeTemplate) {
                MetaNodeTemplate mnt = (MetaNodeTemplate) o;
                NodeID metaNode = mnt.getManager().getID();
                NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
            } else if (o instanceof Category) {
                m_viewer.setExpandedState(o, !m_viewer.getExpandedState(o));
            }
        }
    });
}
Also used : NodeModel(org.knime.core.node.NodeModel) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) Category(org.knime.workbench.repository.model.Category) NodeFactory(org.knime.core.node.NodeFactory) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) NodeID(org.knime.core.node.workflow.NodeID) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) AbstractRepositoryObject(org.knime.workbench.repository.model.AbstractRepositoryObject) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) IContainerObject(org.knime.workbench.repository.model.IContainerObject) PartInitException(org.eclipse.ui.PartInitException) ConcurrentModificationException(java.util.ConcurrentModificationException)

Example 27 with NodeModel

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

the class AbstractRepositoryView method enrichWithAdditionalInfo.

/**
 * This methods recursively retrieves and enriches the repository objects with additional information,
 * e.g. number of ports, whether the node is streamable and/or distributable, etc.
 * Should be called only after the repository content was already loaded with {@link #readRepository(Composite, IProgressMonitor)}.
 */
protected void enrichWithAdditionalInfo(final IRepositoryObject parent, final IProgressMonitor monitor, final boolean updateTreeStructure) {
    if (monitor.isCanceled()) {
        return;
    }
    if (!m_additionalInfoAvailable) {
        if (parent instanceof IContainerObject) {
            IRepositoryObject[] children = ((IContainerObject) parent).getChildren();
            for (IRepositoryObject child : children) {
                enrichWithAdditionalInfo(child, monitor, updateTreeStructure);
            }
        } else if (parent instanceof NodeTemplate) {
            NodeTemplate nodeTemplate = (NodeTemplate) parent;
            try {
                NodeFactory<? extends NodeModel> nf = nodeTemplate.createFactoryInstance();
                NodeModel nm = nf.createNodeModel();
                // check whether the current node model overrides the #createStreamableOperator-method
                Method m = nm.getClass().getMethod("createStreamableOperator", PartitionInfo.class, PortObjectSpec[].class);
                if (m.getDeclaringClass() != NodeModel.class) {
                    // method has been overriden -> node is probably streamable or distributable
                    nodeTemplate.addAdditionalInfo(KEY_INFO_STREAMABLE, "streamable");
                }
            // possible TODO: parse xml description and get some more additional information (e.g. short description, ...)
            // nodeTemplate.addAdditionalInfo(KEY_INFO_SHORT_DESCRIPTION,
            // "this could be the short description, number of ports etc.");
            } catch (Throwable t) {
                LOGGER.error("Unable to instantiate the node " + nodeTemplate.getFactory().getName(), t);
                return;
            }
            if (!updateTreeStructure) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!m_viewer.getControl().isDisposed()) {
                            m_viewer.update(parent, null);
                        }
                    }
                });
            } else {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!m_viewer.getControl().isDisposed()) {
                            m_viewer.update(parent, null);
                            TreeViewerUpdater.update(m_viewer, true, false);
                        }
                    }
                });
            }
        }
    }
}
Also used : NodeModel(org.knime.core.node.NodeModel) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) NodeFactory(org.knime.core.node.NodeFactory) IContainerObject(org.knime.workbench.repository.model.IContainerObject) Method(java.lang.reflect.Method) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject)

Example 28 with NodeModel

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

the class RepositoryFactory method createNodeSet.

/**
 * Creates the set of dynamic node templates.
 *
 * @param root the root to add the missing categories in
 * @param element from the extension points
 * @return the created dynamic node templates
 */
public static Collection<DynamicNodeTemplate> createNodeSet(final Root root, final IConfigurationElement element) {
    String iconPath = element.getAttribute("default-category-icon");
    // Try to load the node set factory class...
    NodeSetFactory nodeSet;
    // this ensures that the class is loaded by the correct eclipse
    // classloaders
    GlobalClassCreator.lock.lock();
    try {
        nodeSet = (NodeSetFactory) 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();
    }
    Collection<DynamicNodeTemplate> dynamicNodeTemplates = new ArrayList<DynamicNodeTemplate>();
    // for all nodes in the node set
    for (String factoryId : nodeSet.getNodeFactoryIds()) {
        @SuppressWarnings("unchecked") Class<NodeFactory<? extends NodeModel>> factoryClass = (Class<NodeFactory<? extends NodeModel>>) nodeSet.getNodeFactory(factoryId);
        // 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 = DynamicNodeTemplate.createFactoryInstance(factoryClass, nodeSet, factoryId);
        } catch (Throwable e) {
            throw new IllegalArgumentException("Can't load factory class for node: " + factoryClass.getName() + "-" + factoryId, e);
        } finally {
            GlobalClassCreator.lock.unlock();
        }
        // DynamicNodeFactory implementations can set deprecation independently from extension
        if (factory.isDeprecated()) {
            continue;
        }
        DynamicNodeTemplate node = new DynamicNodeTemplate(factoryClass, factoryId, nodeSet, factory.getNodeName());
        node.setAfterID(nodeSet.getAfterID(factoryId));
        if (!Boolean.getBoolean("java.awt.headless")) {
            Image icon = ImageRepository.getIconImage(factory);
            node.setIcon(icon);
        }
        node.setCategoryPath(nodeSet.getCategoryPath(factoryId));
        dynamicNodeTemplates.add(node);
        String pluginID = element.getDeclaringExtension().getNamespaceIdentifier();
        // 
        // Insert in proper location, create all categories on
        // the path
        // if not already there
        // 
        String path = node.getCategoryPath();
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        // split the path
        String[] segments = path.split("/");
        // start at root
        IContainerObject container = root;
        String currentPath = "";
        for (int i = 0; i < segments.length; i++) {
            IRepositoryObject obj = container.getChildByID(segments[i], false);
            currentPath += segments[i];
            if (obj == null) {
                Category cat = createCategory(pluginID, segments[i], "", segments[i], "", iconPath, currentPath);
                // append the newly created category to the container
                container.addChild(cat);
                obj = cat;
            }
            currentPath += "/";
            // continue at this level
            container = (IContainerObject) obj;
        }
    }
    return dynamicNodeTemplates;
}
Also used : Category(org.knime.workbench.repository.model.Category) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) NodeModel(org.knime.core.node.NodeModel) NodeFactory(org.knime.core.node.NodeFactory) DynamicNodeFactory(org.knime.core.node.DynamicNodeFactory) NodeSetFactory(org.knime.core.node.NodeSetFactory) IContainerObject(org.knime.workbench.repository.model.IContainerObject)

Example 29 with NodeModel

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

the class SetupSubnodeWizard method addPages.

/**
 * {@inheritDoc}
 */
@Override
public void addPages() {
    setWindowTitle("Setup Wrapped Metanode Wizard");
    setDefaultPageImageDescriptor(ImageDescriptor.createFromImage(ImageRepository.getImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/meta/meta_node_wizard2.png")));
    WorkflowManager wfManager = m_subNode.getWorkflowManager();
    Map<NodeID, NodeModel> allNodes = wfManager.findNodes(NodeModel.class, false);
    LinkedHashMap<NodeID, NodeModel> usageNodes = new LinkedHashMap<NodeID, NodeModel>();
    List<NodeID> nodeIDs = new ArrayList<NodeID>();
    nodeIDs.addAll(allNodes.keySet());
    Collections.sort(nodeIDs);
    for (NodeID id : nodeIDs) {
        NodeModel model = allNodes.get(id);
        if (considerNodeForUsage(model)) {
            usageNodes.put(id, model);
        }
    }
    m_portsPage = new ConfigureMetaNodePortsPage("Change the Wrapped Metanode configuration");
    m_portsPage.setSubNode(m_subNode);
    m_portsPage.setTemplate(null);
    addPage(m_portsPage);
}
Also used : NodeModel(org.knime.core.node.NodeModel) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) ConfigureMetaNodePortsPage(org.knime.workbench.editor2.meta.ConfigureMetaNodePortsPage) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with NodeModel

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

the class FileNativeNodeContainerPersistor method preLoadNodeContainer.

/**
 * {@inheritDoc}
 */
@Override
public void preLoadNodeContainer(final WorkflowPersistor parentPersistor, final NodeSettingsRO parentSettings, final LoadResult result) throws InvalidSettingsException, IOException {
    super.preLoadNodeContainer(parentPersistor, parentSettings, result);
    m_parentPersistor = parentPersistor;
    NodeSettingsRO settings = getNodeSettings();
    String error;
    NodeAndBundleInformation nodeInfo;
    try {
        nodeInfo = loadNodeFactoryInfo(parentSettings, settings);
    } catch (InvalidSettingsException e) {
        setDirtyAfterLoad();
        throw e;
    }
    NodeSettingsRO additionalFactorySettings;
    try {
        additionalFactorySettings = loadAdditionalFactorySettings(settings);
    } catch (Exception e) {
        error = "Unable to load additional factory settings for \"" + nodeInfo + "\"";
        setDirtyAfterLoad();
        throw new InvalidSettingsException(error, e);
    }
    NodeFactory<NodeModel> nodeFactory;
    try {
        nodeFactory = loadNodeFactory(nodeInfo.getFactoryClass());
    } catch (Exception e) {
        // setDirtyAfterLoad(); // don't set dirty, missing node placeholder will be used instead
        throw new NodeFactoryUnknownException(nodeInfo, additionalFactorySettings, e);
    }
    try {
        if (additionalFactorySettings != null) {
            nodeFactory.loadAdditionalFactorySettings(additionalFactorySettings);
        }
    } catch (Exception e) {
        error = "Unable to load additional factory settings into node factory (node \"" + nodeInfo + "\")";
        getLogger().error(error);
        throw new NodeFactoryUnknownException(error, nodeInfo, additionalFactorySettings, e);
    }
    m_nodeAndBundleInformation = nodeInfo;
    m_node = new Node(nodeFactory);
}
Also used : NodeAndBundleInformation(org.knime.core.node.NodeAndBundleInformation) NodeModel(org.knime.core.node.NodeModel) NodeFactoryUnknownException(org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Node(org.knime.core.node.Node) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeFactoryUnknownException(org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException) IOException(java.io.IOException)

Aggregations

NodeModel (org.knime.core.node.NodeModel)30 NodeFactory (org.knime.core.node.NodeFactory)9 HashMap (java.util.HashMap)6 ExecutionContext (org.knime.core.node.ExecutionContext)6 Node (org.knime.core.node.Node)6 PortType (org.knime.core.node.port.PortType)6 Before (org.junit.Before)5 DefaultNodeProgressMonitor (org.knime.core.node.DefaultNodeProgressMonitor)5 VirtualParallelizedChunkPortObjectInNodeFactory (org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory)5 LinkedHashMap (java.util.LinkedHashMap)3 DataProvider (org.knime.base.node.viz.plotter.DataProvider)3 HiLiteHandler (org.knime.core.node.property.hilite.HiLiteHandler)3 VirtualParallelizedChunkPortObjectInNodeModel (org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeModel)3 IContainerObject (org.knime.workbench.repository.model.IContainerObject)3 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)3 MetaNodeTemplate (org.knime.workbench.repository.model.MetaNodeTemplate)3 NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2