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));
}
}
});
}
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);
}
}
});
}
}
}
}
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;
}
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);
}
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);
}
Aggregations