Search in sources :

Example 16 with Config

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

the class BufferedDataTable method saveSpec.

/**
 * Utility method that is used when the node saves its state. It saves
 * it to a file spec.xml.
 * @param spec To save
 * @param dataPortDir destination directory
 * @throws IOException if that fails for any reason
 */
static void saveSpec(final DataTableSpec spec, final File dataPortDir) throws IOException {
    // is configured but can't calculate output, e.g. transpose node)
    if (spec == null) {
        return;
    }
    File specFile = new File(dataPortDir, TABLE_SPEC_FILE);
    Config c = new NodeSettings(TABLE_SPEC_FILE);
    spec.save(c);
    c.saveToXML(new BufferedOutputStream(new FileOutputStream(specFile)));
}
Also used : Config(org.knime.core.node.config.Config) FileOutputStream(java.io.FileOutputStream) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 17 with Config

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

the class SettingsModelAuthentication method saveSettingsForModel.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsForModel(final NodeSettingsWO settings) {
    Config config = settings.addConfig(m_configName);
    config.addString(CREDENTIAL, m_credentials);
    config.addString(USERNAME, m_username);
    config.addPassword(PASSWORD, secretKey, m_password);
    config.addString(SELECTED_TYPE, m_type.name());
}
Also used : Config(org.knime.core.node.config.Config)

Example 18 with Config

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

the class SettingsModelAuthentication method loadSettingsForDialog.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsForDialog(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    // use the current value, if no value is stored in the settings
    final Config config;
    try {
        config = settings.getConfig(m_configName);
        setValues(AuthenticationType.valueOf(config.getString(SELECTED_TYPE, m_type.name())), config.getString(CREDENTIAL, m_credentials), config.getString(USERNAME, m_username), config.getPassword(PASSWORD, secretKey, m_password));
    } catch (InvalidSettingsException ex) {
        throw new NotConfigurableException(ex.getMessage());
    }
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config)

Example 19 with Config

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

the class SettingsModelAuthentication method validateSettingsForModel.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettingsForModel(final NodeSettingsRO settings) throws InvalidSettingsException {
    final Config config = settings.getConfig(m_configName);
    final String type = config.getString(SELECTED_TYPE);
    final String credential = config.getString(CREDENTIAL);
    final String userName = config.getString(USERNAME);
    final String pwd = config.getPassword(PASSWORD, secretKey);
    final AuthenticationType authType = AuthenticationType.get(type);
    switch(authType) {
        case CREDENTIALS:
            if (credential == null || credential.isEmpty()) {
                throw new InvalidSettingsException("Please select a valid credential");
            }
            break;
        case KERBEROS:
            break;
        case NONE:
            break;
        case USER:
            if (userName == null || userName.isEmpty()) {
                throw new InvalidSettingsException("Please enter a valid user name");
            }
            break;
        case USER_PWD:
            if (userName == null || userName.isEmpty()) {
                throw new InvalidSettingsException("Please enter a valid user name");
            }
            if (pwd == null || pwd.isEmpty()) {
                throw new InvalidSettingsException("Please enter a valid password");
            }
            break;
        default:
            break;
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config)

Example 20 with Config

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

the class SettingsModelColor method loadSettingsForDialog.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsForDialog(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    if (!settings.containsKey(getConfigName())) {
        // use the current value, if no value is stored in the settings
        setColorValue(m_value);
        return;
    }
    try {
        final Config config = settings.getConfig(getConfigName());
        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);
        Color color;
        if (red < 0 || green < 0 || blue < 0 || alpha < 0) {
            // the color is null
            color = null;
        } else {
            color = new Color(red, green, blue, alpha);
        }
        setColorValue(color);
    } catch (final IllegalArgumentException iae) {
    // if the argument is not accepted: keep the old value.
    } catch (final InvalidSettingsException e) {
    // if the argument is not accepted: keep the old value.
    } finally {
        // always notify the listeners. That is, because there could be an
        // invalid value displayed in the listener.
        notifyChangeListeners();
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config) Color(java.awt.Color)

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