Search in sources :

Example 1 with SingleNodeContainerSettings

use of org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings in project knime-core by knime.

the class FileSingleNodeContainerPersistor method loadNodeContainer.

/**
 * {@inheritDoc}
 */
@Override
public void loadNodeContainer(final Map<Integer, BufferedDataTable> tblRep, final ExecutionMonitor exec, final LoadResult result) throws InvalidSettingsException, CanceledExecutionException, IOException {
    final NodeSettingsRO settingsForNode = loadSettingsForNode(result);
    m_sncSettings = new SingleNodeContainerSettings();
    exec.checkCanceled();
    try {
        m_sncSettings.setMemoryPolicy(loadMemoryPolicySettings(m_nodeSettings));
    } catch (InvalidSettingsException e) {
        String error = "Unable to load SNC settings: " + e.getMessage();
        result.addError(error);
        getLogger().debug(error, e);
        setDirtyAfterLoad();
        return;
    }
    NodeSettingsRO modelSettings = null;
    try {
        modelSettings = loadModelSettings(settingsForNode);
    } catch (InvalidSettingsException ise) {
        String error = "Unable to load model settings: " + ise.getMessage();
        result.addError(error);
        getLogger().debug(error, ise);
        setDirtyAfterLoad();
    }
    try {
        modelSettings = loadNCAndWashModelSettings(settingsForNode, modelSettings, tblRep, exec, result);
    } catch (InvalidSettingsException ise) {
        String error = "Unable to load node container and wash settings: " + ise.getMessage();
        result.addError(error);
        getLogger().debug(error, ise);
        setDirtyAfterLoad();
    }
    m_sncSettings.setModelSettings(modelSettings);
    try {
        m_sncSettings.setVariablesSettings(loadVariableSettings(settingsForNode));
    } catch (InvalidSettingsException e) {
        String msg = "Could load variable settings: " + e.getMessage();
        result.addError(msg);
        setDirtyAfterLoad();
        setNeedsResetAfterLoad();
    }
    try {
        m_flowObjects = loadFlowObjects(m_nodeSettings);
    } catch (Exception e) {
        m_flowObjects = Collections.emptyList();
        String error = "Error loading flow variables: " + e.getMessage();
        getLogger().warn(error, e);
        result.addError(error);
        setDirtyAfterLoad();
        setNeedsResetAfterLoad();
    }
    exec.setProgress(1.0);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SingleNodeContainerSettings(org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) LockFailedException(org.knime.core.util.LockFailedException) IOException(java.io.IOException)

Example 2 with SingleNodeContainerSettings

use of org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings in project knime-core by knime.

the class NodeDialogPane method internalLoadSettingsFrom.

/**
 * Method being called from the node when the dialog shall load the
 * settings from a NodeSettingsRO object. This method will call the
 * abstract loadSettingsFrom method and finally load internals
 * (i.e. memory policy of outports, if any).
 * @param settings To load from.
 * @param specs Specs at input ports
 * @param data Data from input ports
 * @param foStack Flow object stack (contains flow variables)
 * @param credentialsProvider The credentials available in the flow
 * @param isWriteProtected Whether ok/apply should be disabled
 *        (write protected metanode)
 * @throws NotConfigurableException
 * If loadSettingsFrom throws this exception.
 * @see #loadSettingsFrom(NodeSettingsRO, PortObjectSpec[])
 */
final void internalLoadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs, final PortObject[] data, final FlowObjectStack foStack, final CredentialsProvider credentialsProvider, final boolean isWriteProtected) throws NotConfigurableException {
    NodeSettingsRO modelSettings = null;
    NodeSettingsRO flowVariablesSettings = null;
    m_flowObjectStack = foStack;
    m_credentialsProvider = credentialsProvider;
    m_specs = specs;
    m_data = data;
    m_isWriteProtected = isWriteProtected;
    SingleNodeContainerSettings sncSettings;
    try {
        sncSettings = new SingleNodeContainerSettings(settings);
        modelSettings = sncSettings.getModelSettings();
        flowVariablesSettings = sncSettings.getVariablesSettings();
    } catch (InvalidSettingsException ise) {
        // silently ignored here, variables get assigned default values
        // if they are null
        sncSettings = new SingleNodeContainerSettings();
    }
    if (modelSettings == null) {
        modelSettings = new NodeSettings("empty");
    }
    if (m_memPolicyTab != null) {
        MemoryPolicy memoryPolicy = sncSettings.getMemoryPolicy();
        if (memoryPolicy == null) {
            memoryPolicy = MemoryPolicy.CacheSmallInMemory;
        }
        m_memPolicyTab.setStatus(memoryPolicy);
    }
    final AtomicReference<Throwable> exRef = new AtomicReference<Throwable>();
    final NodeSettingsRO ms = modelSettings;
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                callDerivedLoadSettingsFrom(ms, specs, data);
            } catch (Throwable ex) {
                exRef.set(ex);
            }
        }
    };
    ViewUtils.invokeAndWaitInEDT(r);
    if (exRef.get() instanceof NotConfigurableException) {
        throw (NotConfigurableException) exRef.get();
    } else if (exRef.get() != null) {
        m_logger.error("Error loading model settings", exRef.get());
    }
    // add the flow variables tab
    addFlowVariablesTab();
    m_flowVariablesModelChanged = false;
    initFlowVariablesTab(modelSettings, flowVariablesSettings);
    // output memory policy and job manager (stored in NodeContainer)
    if (m_memPolicyTab != null || m_jobMgrTab != null) {
        NodeContainerSettings ncSettings;
        try {
            ncSettings = new NodeContainerSettings();
            ncSettings.load(settings);
        } catch (InvalidSettingsException ise) {
            ncSettings = new NodeContainerSettings();
        }
        if (m_jobMgrTab != null) {
            m_jobMgrTab.loadSettings(ncSettings, specs);
        }
    }
    updateFlowVariablesOverwriteWarning();
}
Also used : MemoryPolicy(org.knime.core.node.workflow.SingleNodeContainer.MemoryPolicy) SingleNodeContainerSettings(org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings) NodeContainerSettings(org.knime.core.node.workflow.NodeContainer.NodeContainerSettings) SingleNodeContainerSettings(org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 3 with SingleNodeContainerSettings

use of org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings in project knime-core by knime.

the class NodeDialogPane method internalSaveSettingsTo.

/**
 * Called from the node when the current settings shall be written to
 * a NodeSettings object. It will call the abstract saveSettingsTo method
 * and finally write "misc" settings to the argument object.
 * @param settings To write to. Forwarded to abstract saveSettings method.
 * @throws InvalidSettingsException If any of the writing fails.
 */
void internalSaveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    NodeSettings model = new NodeSettings("field_ignored");
    NodeContext.pushContext(m_nodeContext);
    try {
        saveSettingsTo(model);
    } catch (InvalidSettingsException ise) {
        throw ise;
    } catch (Throwable e) {
        m_logger.coding("Wrong exception type thrown " + "while saving dialog settings", e);
        throw new InvalidSettingsException(e);
    } finally {
        NodeContext.removeLastContext();
    }
    if (m_flowVariablesModelChanged) {
        updateFlowVariablesTab();
    }
    NodeSettings variables = m_flowVariableTab.getVariableSettings();
    SingleNodeContainerSettings s = new SingleNodeContainerSettings();
    s.setModelSettings(model);
    s.setVariablesSettings(variables);
    if (m_memPolicyTab != null) {
        s.setMemoryPolicy(m_memPolicyTab.getStatus());
    }
    NodeContainerSettings ncSet = new NodeContainerSettings();
    if (m_jobMgrTab != null) {
        m_jobMgrTab.saveSettings(ncSet);
    }
    ncSet.save(settings);
    s.save(settings);
}
Also used : SingleNodeContainerSettings(org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings) NodeContainerSettings(org.knime.core.node.workflow.NodeContainer.NodeContainerSettings) SingleNodeContainerSettings(org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings)

Example 4 with SingleNodeContainerSettings

use of org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings in project knime-core by knime.

the class WorkflowManager method saveSettings.

/**
 * {@inheritDoc}
 */
@Override
void saveSettings(final NodeSettingsWO settings) {
    super.saveSettings(settings);
    // TODO: as we don't have a node model associated with the wfm, we must
    // do the same thing a dialog does when saving settings (it assumes
    // existance of a node).
    // Node.SettingsLoaderAndWriter l = new Node.SettingsLoaderAndWriter();
    // NodeSettings model = new NodeSettings("field_ignored");
    // NodeSettings variables;
    // l.setModelSettings(model);
    // l.setVariablesSettings(variables);
    // l.save(settings);
    NodeSettingsWO modelSettings = settings.addNodeSettings("model");
    for (Map.Entry<NodeID, QuickFormInputNode> e : findNodes(QuickFormInputNode.class, false).entrySet()) {
        String nodeID = Integer.toString(e.getKey().getIndex());
        NodeSettingsWO subSettings = modelSettings.addNodeSettings(nodeID);
        @SuppressWarnings("unchecked") AbstractQuickFormConfiguration<AbstractQuickFormValueInConfiguration> config = (AbstractQuickFormConfiguration<AbstractQuickFormValueInConfiguration>) e.getValue().getConfiguration();
        if (config != null) {
            config.getValueConfiguration().saveValue(subSettings);
        }
    }
    SingleNodeContainerSettings s = new SingleNodeContainerSettings();
    NodeContainerSettings ncSet = new NodeContainerSettings();
    ncSet.save(settings);
    s.save(settings);
}
Also used : AbstractQuickFormValueInConfiguration(org.knime.core.quickform.AbstractQuickFormValueInConfiguration) AbstractQuickFormConfiguration(org.knime.core.quickform.AbstractQuickFormConfiguration) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) SingleNodeContainerSettings(org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings) SingleNodeContainerSettings(org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings) QuickFormInputNode(org.knime.core.quickform.in.QuickFormInputNode) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Aggregations

SingleNodeContainerSettings (org.knime.core.node.workflow.SingleNodeContainer.SingleNodeContainerSettings)4 NodeContainerSettings (org.knime.core.node.workflow.NodeContainer.NodeContainerSettings)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)1 MemoryPolicy (org.knime.core.node.workflow.SingleNodeContainer.MemoryPolicy)1 AbstractQuickFormConfiguration (org.knime.core.quickform.AbstractQuickFormConfiguration)1 AbstractQuickFormValueInConfiguration (org.knime.core.quickform.AbstractQuickFormValueInConfiguration)1 QuickFormInputNode (org.knime.core.quickform.in.QuickFormInputNode)1 LockFailedException (org.knime.core.util.LockFailedException)1