use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class AnnotationData method load.
/**
* loads new values.
* @param config To load from
* @param loadVersion Version to load
* @throws InvalidSettingsException If fails
*/
public void load(final NodeSettingsRO config, final FileWorkflowPersistor.LoadVersion loadVersion) throws InvalidSettingsException {
setText(config.getString("text"));
setBgColor(config.getInt("bgcolor"));
int x = config.getInt("x-coordinate");
int y = config.getInt("y-coordinate");
int width = config.getInt("width");
int height = config.getInt("height");
// default to 0 for backward compatibility
int borderSize = config.getInt("borderSize", 0);
// default for backward compatibility
int borderColor = config.getInt("borderColor", 0);
// default for backward compatibility
int defFontSize = config.getInt("defFontSize", -1);
// added in 3.0
m_version = config.getInt("annotation-version", VERSION_OLD);
TextAlignment alignment = TextAlignment.LEFT;
if (loadVersion.ordinal() >= FileWorkflowPersistor.LoadVersion.V250.ordinal()) {
String alignmentS = config.getString("alignment");
try {
alignment = TextAlignment.valueOf(alignmentS);
} catch (Exception e) {
throw new InvalidSettingsException("Invalid alignment: " + alignmentS, e);
}
}
setDimension(x, y, width, height);
setAlignment(alignment);
setBorderSize(borderSize);
setBorderColor(borderColor);
setDefaultFontSize(defFontSize);
NodeSettingsRO styleConfigs = config.getNodeSettings("styles");
StyleRange[] styles = new StyleRange[styleConfigs.getChildCount()];
int i = 0;
for (String key : styleConfigs.keySet()) {
NodeSettingsRO cur = styleConfigs.getNodeSettings(key);
styles[i++] = StyleRange.load(cur);
}
setStyleRanges(styles);
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class MetaNodeTemplateInformation method load.
/**
* Load information from argument, throw {@link InvalidSettingsException}
* if that fails.
* @param settings To load from.
* @param version The version this workflow is loading from
* @return a new template loading from the argument settings.
* @throws InvalidSettingsException If that fails.
*/
public static MetaNodeTemplateInformation load(final NodeSettingsRO settings, final FileWorkflowPersistor.LoadVersion version) throws InvalidSettingsException {
if (!settings.containsKey(CFG_TEMPLATE_INFO)) {
return NONE;
}
NodeSettingsRO nestedSettings = settings.getNodeSettings(CFG_TEMPLATE_INFO);
String roleS = nestedSettings.getString("role");
Role role;
Date timestamp;
URI sourceURI;
TemplateType templateType;
try {
role = Role.valueOf(roleS);
} catch (Exception e) {
throw new InvalidSettingsException("Cannot parse template role \"" + roleS + "\": " + e.getMessage(), e);
}
switch(role) {
case None:
return NONE;
case Template:
sourceURI = null;
timestamp = readTimestamp(nestedSettings);
templateType = readTemplateType(nestedSettings, version);
break;
case Link:
sourceURI = readURI(nestedSettings);
templateType = null;
timestamp = readTimestamp(nestedSettings);
break;
default:
throw new InvalidSettingsException("Unsupported role: " + role);
}
return new MetaNodeTemplateInformation(role, templateType, sourceURI, timestamp);
}
use of org.knime.core.node.NodeSettingsRO 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);
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class FileTemplateRepository method addTemplate.
/**
* Add a template to the default location.
* @param template the template
*/
@Override
public void addTemplate(final T template) {
if (m_readonly) {
throw new RuntimeException("This repository is read only." + "Cannot add a template.");
}
try {
File file = getFile(template);
boolean isNew = file.createNewFile();
if (isNew) {
NodeSettings settings = new NodeSettings(file.getName());
template.saveSettings(settings);
settings.saveToXML(new FileOutputStream(file));
// reload settings
NodeSettingsRO settingsro = NodeSettings.loadFromXML(new FileInputStream(file));
// set the reloaded settings so that all references to existing
// objects are broken. This makes sure, that the template is not
// changed from outside.
template.loadSettings(settingsro);
appendTemplates(Collections.singletonList(template));
} else {
throw new IOException("A file with this name does " + "already exist: " + file.getAbsolutePath());
}
} catch (IOException e1) {
NodeLogger.getLogger(this.getClass()).error("Could not create template at the default location.", e1);
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class JavaSnippetTemplate method loadSettings.
/**
* Loads parameters.
* @param settings to load from
*/
@Override
public void loadSettings(final NodeSettingsRO settings) {
try {
String metaCategory = settings.getString(META_CATEGORY, null);
m_metaCategory = getMetaCategoryClass(metaCategory);
m_category = settings.getString(CATEGORY, "default");
m_name = settings.getString(NAME, "?");
m_description = settings.getString(DESCRIPTION, "");
m_version = settings.getString(m_version, JavaSnippetTemplate.VERSION_1_X);
NodeSettingsRO snippet = settings.getNodeSettings(SNIPPET);
m_snippetSettings = new JavaSnippetSettings();
m_snippetSettings.loadSettingsForDialog(snippet);
m_uuid = m_snippetSettings.getTemplateUUID();
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
} catch (InvalidSettingsException e) {
throw new IllegalStateException(e);
}
}
Aggregations