use of org.knime.core.node.NodeModel in project knime-core by knime.
the class SubNodeContainer method setHideNodeFromDialog.
/**
* Sets a flag on a given {@link DialogNode}, whether or not it is hidden from a containing metanode dialog
* @param id the node to set the flag on
* @param hide true if the node is supposed to be hidden from a containing metanode dialog, false otherwise
* @since 3.5
* @noreference This method is not intended to be referenced by clients.
*/
public void setHideNodeFromDialog(final NodeID id, final boolean hide) {
try (WorkflowLock lock = lock()) {
NativeNodeContainer nnc = m_wfm.getNodeContainer(id, NativeNodeContainer.class, true);
NodeModel model = nnc.getNodeModel();
CheckUtils.checkArgument(model instanceof DialogNode, "Can't set hide in dialog flag on non-dialog nodes.");
DialogNode<?, ?> dn = (DialogNode<?, ?>) model;
if (hide != dn.isHideInDialog()) {
dn.setHideInDialog(hide);
nnc.saveNodeSettingsToDefault();
nnc.setDirty();
}
}
}
use of org.knime.core.node.NodeModel in project knime-core by knime.
the class WorkflowManager method castNodeModel.
/**
* Retrieves the node with the given ID, fetches the underlying {@link NodeModel} and casts it to the argument
* class.
*
* @param id The node of interest
* @param cl The class object the underlying NodeModel needs to implement
* @param <T> The type the class
* @return The casted node model.
* @throws IllegalArgumentException If the node does not exist, is not a {@link NativeNodeContainer} or the model
* does not implement the requested type.
*/
public <T> T castNodeModel(final NodeID id, final Class<T> cl) {
NodeContainer nc = getNodeContainer(id);
if (!(nc instanceof NativeNodeContainer)) {
throw new IllegalArgumentException("Node \"" + nc + "\" not a native node container");
}
NodeModel model = ((NativeNodeContainer) nc).getNodeModel();
if (!cl.isInstance(model)) {
throw new IllegalArgumentException("Node \"" + nc + "\" not instance of " + cl.getSimpleName());
}
return cl.cast(model);
}
use of org.knime.core.node.NodeModel in project knime-core by knime.
the class ScopeEndNode method getFlowContext.
/**
* @return T the scope context put onto the stack by the matching ScopeStartNode
* or null if something was wrong (illegally wired loops should have been
* reported elsewhere - IllegalLoopExecption is only thrown/caught inside core)
* @since 3.1
*/
default T getFlowContext() {
NodeModel m = castToNodeModel(this);
FlowScopeContext fsc = Node.invokePeekFlowScopeContext(m);
try {
@SuppressWarnings("unchecked") T t = (T) fsc;
return t;
} catch (ClassCastException cce) {
return null;
}
}
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;
NodeAndBundleInformationPersistor 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.getFactoryClassNotNull());
} 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, loadCreationConfig(settings, nodeFactory).orElse(null));
}
use of org.knime.core.node.NodeModel in project knime-core by knime.
the class FileNativeNodeContainerPersistor method loadNodeFactory.
/**
* Creates the node factory instance for the given fully-qualified factory class name.
* Otherwise a respective exception will be thrown.
*
* @since 3.5
*/
@SuppressWarnings("unchecked")
public static final NodeFactory<NodeModel> loadNodeFactory(final String factoryClassName) throws InvalidSettingsException, InstantiationException, IllegalAccessException, InvalidNodeFactoryExtensionException {
Optional<NodeFactory<? extends NodeModel>> facOptional = NodeFactoryExtensionManager.getInstance().createNodeFactory(factoryClassName);
if (facOptional.isPresent()) {
return (NodeFactory<NodeModel>) facOptional.get();
}
List<NodeFactoryClassMapper> classMapperList = NodeFactoryClassMapper.getRegisteredMappers();
for (NodeFactoryClassMapper mapper : classMapperList) {
@SuppressWarnings("rawtypes") NodeFactory factory = mapper.mapFactoryClassName(factoryClassName);
if (factory != null) {
LOGGER.debug(String.format("Replacing stored factory class name \"%s\" by actual factory " + "class \"%s\" (defined by class mapper \"%s\")", factoryClassName, factory.getClass().getName(), mapper.getClass().getName()));
return factory;
}
}
throw new InvalidSettingsException(String.format("Unknown factory class \"%s\" -- not registered via extension point", factoryClassName));
}
Aggregations