use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class NodeExecutorJobManagerDialogTab method saveSettings.
/**
* Writes the current settings of the job manager tab into the provided
* settings object.
*
* @param settings the object to write settings into
* @throws InvalidSettingsException if the settings in the pane are
* unacceptable
*/
public void saveSettings(final NodeContainerSettings settings) throws InvalidSettingsException {
String selected = (String) m_jobManagerSelect.getSelectedItem();
NodeExecutionJobManager selMgr = null;
if (!DEFAULT_ENTRY.equals(selected)) {
// any "real" node execution manager was selected
selMgr = m_panels.get(selected).getFirst();
NodeSettings panelSets = new NodeSettings("job_manager_settings");
m_currentPanel.saveSettings(panelSets);
selMgr.load(panelSets);
}
settings.setJobManager(selMgr);
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class ObsoleteMetaNodeFileWorkflowPersistor method loadInPortsSetting.
/**
* {@inheritDoc}
*/
@Override
protected NodeSettingsRO loadInPortsSetting(final NodeSettingsRO settings) throws InvalidSettingsException {
NodeSettings template = new NodeSettings("inports");
for (int i = 0; i < m_dataInNodeIDs.length; i++) {
NodeSettingsWO sub = template.addNodeSettings("data_" + i);
sub.addInt("index", i);
sub.addInt("node", m_dataInNodeIDs[i]);
sub.addString("type", "data");
}
return template;
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class SubNodeContainer method setInPorts.
/**
* @param portTypes Types of the new ports
* @since 2.10
*/
public void setInPorts(final PortType[] portTypes) {
m_inports = new NodeInPort[portTypes.length + 1];
for (int i = 0; i < portTypes.length; i++) {
m_inports[i + 1] = new NodeInPort(i + 1, portTypes[i]);
}
NodeContainer oldVNode = m_wfm.getNodeContainer(getVirtualInNodeID());
m_inports[0] = new NodeInPort(0, FlowVariablePortObject.TYPE_OPTIONAL);
NodeSettings settings = new NodeSettings("node settings");
try {
m_wfm.saveNodeSettings(oldVNode.getID(), settings);
} catch (InvalidSettingsException e) {
// no valid settings available, skip
}
m_virtualInNodeIDSuffix = m_wfm.addNode(new VirtualSubNodeInputNodeFactory(this, portTypes)).getIndex();
NodeContainer newVNode = m_wfm.getNodeContainer(getVirtualInNodeID());
newVNode.setUIInformation(oldVNode.getUIInformation());
// copy settings from old to new node
try {
m_wfm.loadNodeSettings(newVNode.getID(), settings);
} catch (InvalidSettingsException e) {
// ignore
}
oldVNode.setDeletable(true);
m_wfm.removeNode(oldVNode.getID());
getInPort(0).setPortName("Variable Inport");
newVNode.addNodeStateChangeListener(new RefreshPortNamesListener());
refreshPortNames();
m_wfm.setDirty();
setDirty();
notifyNodePropertyChangedListener(NodeProperty.MetaNodePorts);
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class SubNodeContainer method saveAsTemplate.
/**
* {@inheritDoc}
*/
@Override
public MetaNodeTemplateInformation saveAsTemplate(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, LockFailedException, InvalidSettingsException {
WorkflowManager tempParent = WorkflowManager.lazyInitTemplateWorkflowRoot();
SubNodeContainer copy = null;
ReferencedFile workflowDirRef = new ReferencedFile(directory);
directory.mkdir();
workflowDirRef.lock();
try {
WorkflowCopyContent.Builder cntBuilder = WorkflowCopyContent.builder();
cntBuilder.setNodeIDs(getID());
WorkflowCopyContent cnt;
synchronized (m_nodeMutex) {
cnt = tempParent.copyFromAndPasteHere(getParent(), cntBuilder.build());
}
NodeID cID = cnt.getNodeIDs()[0];
copy = ((SubNodeContainer) tempParent.getNodeContainer(cID));
try (WorkflowLock copyLock = copy.lock()) {
SingleNodeContainerSettings sncSettings = copy.getSingleNodeContainerSettings().clone();
sncSettings.setModelSettings(new NodeSettings("empty model"));
sncSettings.setVariablesSettings(new NodeSettings("empty variables setting"));
NodeSettings newSettings = new NodeSettings("new settings");
sncSettings.save(newSettings);
copy.loadSettings(newSettings);
MetaNodeTemplateInformation template = MetaNodeTemplateInformation.createNewTemplate(SubNodeContainer.class);
synchronized (copy.m_nodeMutex) {
copy.setTemplateInformation(template);
copy.setName(null);
NodeSettings templateSettings = MetaNodeTemplateInformation.createNodeSettingsForTemplate(copy);
templateSettings.saveToXML(new FileOutputStream(new File(workflowDirRef.getFile(), WorkflowPersistor.TEMPLATE_FILE)));
FileSingleNodeContainerPersistor.save(copy, workflowDirRef, exec, new WorkflowSaveHelper(true, false));
}
return template;
}
} finally {
if (copy != null) {
tempParent.removeNode(copy.getID());
}
workflowDirRef.unlock();
}
}
use of org.knime.core.node.NodeSettings in project knime-core by knime.
the class SubNodeContainer method checkInOutNodesAfterLoad.
/**
* Fixes in- and output nodes after loading (in case they don't exist or have errors).
*/
private void checkInOutNodesAfterLoad(final SubNodeContainerPersistor subNodePersistor, final LoadResult loadResult) {
/* Fix output node */
NodeID virtualOutID = getVirtualOutNodeID();
// non null in case not is not present of of wrong type
String error = null;
// settings of previous node if present or null
NodeSettings outputSettings = null;
// assigned with node insertion, used for node placement
Pair<int[], int[]> minMaxCoordinates;
if (m_wfm.containsNodeContainer(virtualOutID)) {
NodeContainer virtualOutNC = m_wfm.getNodeContainer(virtualOutID);
if (virtualOutNC instanceof NativeNodeContainer) {
NodeModel virtualOutModel = ((NativeNodeContainer) virtualOutNC).getNodeModel();
if (!(virtualOutModel instanceof VirtualSubNodeOutputNodeModel)) {
// this is very likely a missing node (placeholder)
error = String.format("Virtual output node is not of expected type (expected %s, actual %s)", VirtualSubNodeOutputNodeModel.class.getName(), virtualOutModel.getClass().getName());
try {
NodeSettings temp = new NodeSettings("temp");
m_wfm.saveNodeSettings(virtualOutID, temp);
outputSettings = temp;
} catch (InvalidSettingsException ise) {
// silently ignore; this is minor given that the node is not there.
}
}
} else {
error = String.format("Virtual output node with ID %s is not a native node", virtualOutID);
}
} else {
error = String.format("Virtual output node with ID %s does not exist", virtualOutID);
}
if (error != null) {
minMaxCoordinates = getMinMaxCoordinates();
m_virtualOutNodeIDSuffix = addVirtualOutNode(Output.getPortTypesNoFlowVariablePort(m_outputs), minMaxCoordinates).getIndex();
error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualOutNodeIDSuffix));
loadResult.addError(error);
if (outputSettings != null) {
try {
m_wfm.loadNodeSettings(getVirtualOutNodeID(), outputSettings);
} catch (InvalidSettingsException e) {
// again, ignore as the node was missing, which is much more critical
}
}
}
/* Fix input node */
NodeID virtualInID = getVirtualInNodeID();
// non null in case not is not present of of wrong type
error = null;
// settings of previous node if present or null
NodeSettings inputSettings = null;
if (m_wfm.containsNodeContainer(virtualInID)) {
NodeContainer virtualInNC = m_wfm.getNodeContainer(virtualInID);
if (virtualInNC instanceof NativeNodeContainer) {
NodeModel virtualInModel = ((NativeNodeContainer) virtualInNC).getNodeModel();
if (!(virtualInModel instanceof VirtualSubNodeInputNodeModel)) {
// this is very likely a missing node (placeholder)
error = String.format("Virtual input node is not of expected type (expected %s, actual %s)", VirtualSubNodeInputNodeModel.class.getName(), virtualInModel.getClass().getName());
try {
NodeSettings temp = new NodeSettings("temp");
m_wfm.saveNodeSettings(virtualInID, temp);
inputSettings = temp;
} catch (InvalidSettingsException ise) {
// silently ignore; this is minor given that the node is not there.
}
}
} else {
error = String.format("Virtual input node with ID %s is not a native node", virtualInID);
}
} else {
error = String.format("Virtual input node with ID %s does not exist", virtualInID);
}
if (error != null) {
minMaxCoordinates = getMinMaxCoordinates();
// skip flow var port
PortType[] inportTypes = new PortType[getNrInPorts() - 1];
for (int i = 1; i < getNrInPorts(); i++) {
inportTypes[i - 1] = getInPort(i).getPortType();
}
m_virtualInNodeIDSuffix = addVirtualInNode(inportTypes, minMaxCoordinates).getIndex();
error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualInNodeIDSuffix));
loadResult.addError(error);
if (inputSettings != null) {
try {
m_wfm.loadNodeSettings(getVirtualInNodeID(), inputSettings);
} catch (InvalidSettingsException e) {
// again, ignore as the node was missing, which is much more critical
}
}
}
}
Aggregations