Search in sources :

Example 21 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class SettingsModelColor method validateSettingsForModel.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettingsForModel(final NodeSettingsRO settings) throws InvalidSettingsException {
    final Config config = settings.getConfig(getConfigName());
    // check all color values
    final int red = config.getInt(CNFG_RED);
    final int green = config.getInt(CNFG_GREEN);
    final int blue = config.getInt(CNFG_BLUE);
    final int alpha = config.getInt(CNFG_ALPHA);
    if (red < 0 || green < 0 || blue < 0 || alpha < 0) {
        // the color is null
        return;
    }
    // constructor checks the value ranges
    new Color(red, green, blue, alpha);
}
Also used : Config(org.knime.core.node.config.Config) Color(java.awt.Color)

Example 22 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class SettingsModelFilterString method saveSettingsForModel.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsForModel(final NodeSettingsWO settings) {
    Config lists = settings.addConfig(m_configName);
    lists.addStringArray(CFGKEY_INCL, getIncludeList().toArray(new String[0]));
    lists.addStringArray(CFGKEY_EXCL, getExcludeList().toArray(new String[0]));
    lists.addBoolean(CFGKEY_KEEPALL, m_keepAll);
}
Also used : Config(org.knime.core.node.config.Config)

Example 23 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class SettingsModelFilterString method loadSettingsForDialog.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsForDialog(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    try {
        Config lists = settings.getConfig(m_configName);
        // the way we do this, partially correct settings will be partially
        // transferred into the dialog. Which is okay, I guess.
        setIncludeList(lists.getStringArray(CFGKEY_INCL, (String[]) null));
        setExcludeList(lists.getStringArray(CFGKEY_EXCL, (String[]) null));
        setKeepAllSelected(lists.getBoolean(CFGKEY_KEEPALL, false));
    } catch (IllegalArgumentException iae) {
    // if the argument is not accepted: keep the old value.
    } catch (InvalidSettingsException ise) {
    // no settings - keep the old value.
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config)

Example 24 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class SettingsModel method readEnableStatusAndCheckModelID.

/**
 * Checks the modelID stored in the settings object and throws an assertion
 * if it doesn't match the ID of this model. It also reads the enabled
 * status back in - and throws an exeption if any of these settings is
 * missing (the enabled status will remain unchanged then).
 *
 * @param settings the config object to read the enable state and model ID
 *            from
 */
private void readEnableStatusAndCheckModelID(final NodeSettingsRO settings) throws InvalidSettingsException {
    Config idCfg = null;
    try {
        idCfg = settings.getConfig(getConfigName() + CFGKEY_INTERNAL);
    } catch (InvalidSettingsException ise) {
        // doesn't exist.
        return;
    }
    String settingsID = idCfg.getString(CFGKEY_MODELID);
    m_enabled = idCfg.getBoolean(CFGKEY_ENABLESTAT);
    assert getModelTypeID().equals(settingsID) : "Incorrect Implementation:" + "The SettingsModel used to write the values is" + " different from the one that reads them. (WriteID = " + settingsID + ", ReadID = " + getModelTypeID() + ", Reading settings model: " + this.toString() + ")";
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config)

Example 25 with Config

use of org.knime.core.node.config.Config in project knime-core by knime.

the class FilterDefinitionHandlerPortObject method getViews.

/**
 * {@inheritDoc}
 */
@Override
public JComponent[] getViews() {
    ModelContent model = new ModelContent("FilterDefinition");
    Config columnConfig = model.addConfig("Column");
    getSpec().forEach(col -> col.getFilterHandler().ifPresent(handler -> handler.save(columnConfig.addConfig(col.getName()))));
    return new JComponent[] { new ModelContentOutPortView(model) };
}
Also used : JComponent(javax.swing.JComponent) PortTypeRegistry(org.knime.core.node.port.PortTypeRegistry) ModelContent(org.knime.core.node.ModelContent) ModelContentOutPortView(org.knime.core.node.workflow.ModelContentOutPortView) DataTableSpec(org.knime.core.data.DataTableSpec) Config(org.knime.core.node.config.Config) PortType(org.knime.core.node.port.PortType) ModelContent(org.knime.core.node.ModelContent) Config(org.knime.core.node.config.Config) JComponent(javax.swing.JComponent) ModelContentOutPortView(org.knime.core.node.workflow.ModelContentOutPortView)

Aggregations

Config (org.knime.core.node.config.Config)84 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)25 Color (java.awt.Color)10 File (java.io.File)10 FileOutputStream (java.io.FileOutputStream)8 NodeSettings (org.knime.core.node.NodeSettings)8 ArrayList (java.util.ArrayList)7 DataColumnSpec (org.knime.core.data.DataColumnSpec)7 ConfigRO (org.knime.core.node.config.ConfigRO)7 HashMap (java.util.HashMap)6 GZIPOutputStream (java.util.zip.GZIPOutputStream)6 LinkedHashMap (java.util.LinkedHashMap)5 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 DataCell (org.knime.core.data.DataCell)4