Search in sources :

Example 1 with SettingsModelBoolean

use of org.knime.core.node.defaultnodesettings.SettingsModelBoolean in project knime-core by knime.

the class Time2StringNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_newColName.validateSettings(settings);
    m_replaceCol.validateSettings(settings);
    m_selectedCol.validateSettings(settings);
    SettingsModelBoolean replaceModelClone = m_replaceCol.createCloneWithValidatedValue(settings);
    // only if the original column is not replaced we need to check the new
    // column name
    boolean replace = replaceModelClone.getBooleanValue();
    if (replace) {
        return;
    }
    // check for valid and unique column name != null && !empty
    SettingsModelString colNameClone = m_newColName.createCloneWithValidatedValue(settings);
    String newColName = colNameClone.getStringValue();
    if (newColName == null || newColName.isEmpty()) {
        throw new InvalidSettingsException("New column name must not be empty!");
    }
    m_pattern.validateSettings(settings);
    SettingsModelString patternStringModel = m_pattern.createCloneWithValidatedValue(settings);
    String patternString = patternStringModel.getStringValue();
    // validate the pattern
    try {
        new SimpleDateFormat(patternString);
    } catch (Exception e) {
        throw new InvalidSettingsException("Pattern " + patternString + " is invalid!", e);
    }
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SimpleDateFormat(java.text.SimpleDateFormat) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 2 with SettingsModelBoolean

use of org.knime.core.node.defaultnodesettings.SettingsModelBoolean in project knime-core by knime.

the class RulePanel method loadSettingsFrom.

/**
 * Loads the settings from the serialized model ({@code settings}).
 *
 * @param settings The container for the model.
 * @param specs The current {@link DataTableSpec}s.
 * @param availableFlowVariables The {@link FlowVariable}s.
 * @throws NotConfigurableException The information in the {@code settings} model is invalid.
 */
public void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs, final Map<String, FlowVariable> availableFlowVariables) throws NotConfigurableException {
    if (specs == null || specs.length == 0 || specs[0] == null) /*|| specs[0].getNumColumns() == 0*/
    {
        throw new NotConfigurableException("No columns available!");
    }
    m_spec = specs[0];
    m_parser.setDataTableSpec(m_spec);
    m_parser.setFlowVariables(availableFlowVariables);
    RuleEngineSettings ruleSettings = new RuleEngineSettings();
    ruleSettings.loadSettingsForDialog(settings);
    update(specs[0], availableFlowVariables);
    if (m_nodeType.hasOutput()) {
        String newColName = ruleSettings.getNewColName();
        m_newColumnName.setText(newColName);
        if (m_replaceColumn != null) {
            m_outputGroup.setSelected(m_outputGroup.getElements().nextElement().getModel(), ruleSettings.isAppendColumn());
            m_outputGroup.setSelected(m_replaceColRadio.getModel(), !ruleSettings.isAppendColumn());
            for (ActionListener listener : m_replaceColRadio.getActionListeners()) {
                listener.actionPerformed(null);
            }
            m_replaceColumn.setSelectedColumn(ruleSettings.getReplaceColumn());
        }
    }
    m_disallowLongOutputForCompatibility = ruleSettings.isDisallowLongOutputForCompatibility();
    update(m_spec, availableFlowVariables);
    final KnimeSyntaxTextArea textEditor = m_mainPanel.getTextEditor();
    textEditor.setText("");
    StringBuilder text = new StringBuilder();
    for (Iterator<String> it = ruleSettings.rules().iterator(); it.hasNext(); ) {
        final String rs = it.next();
        text.append(rs);
        if (it.hasNext()) {
            text.append('\n');
        }
    }
    if (!ruleSettings.rules().iterator().hasNext()) {
        final String defaultText = m_nodeType.defaultText();
        final String noText = RuleSupport.toComment(defaultText);
        textEditor.setText(noText);
        text.append(noText);
    }
    if (!m_nodeType.hasOutput()) {
        try {
            final SettingsModelBoolean includeOnMatch = new SettingsModelBoolean(RuleEngineFilterNodeModel.CFGKEY_INCLUDE_ON_MATCH, RuleEngineFilterNodeModel.DEFAULT_INCLUDE_ON_MATCH);
            includeOnMatch.loadSettingsFrom(settings);
            m_top.setSelected(includeOnMatch.getBooleanValue());
            m_bottom.setSelected(!includeOnMatch.getBooleanValue());
        } catch (InvalidSettingsException e) {
            boolean defaultTop = true;
            m_top.setSelected(defaultTop);
            m_bottom.setSelected(!defaultTop);
        }
    }
    updateText(text.toString());
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) ActionListener(java.awt.event.ActionListener) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) KnimeSyntaxTextArea(org.knime.base.node.util.KnimeSyntaxTextArea)

Example 3 with SettingsModelBoolean

use of org.knime.core.node.defaultnodesettings.SettingsModelBoolean in project knime-core by knime.

the class RulePanel method saveSettings.

/**
 * Saves the settings to the model ({@code settings}).
 *
 * @param settings The container for the model.
 * @throws InvalidSettingsException When there should be a column/flow variable outcome, but no column/flow variable
 *             is selected or the rules do not parse without error.
 */
public void saveSettings(final NodeSettingsWO settings) throws InvalidSettingsException {
    RuleEngineSettings ruleSettings = new RuleEngineSettings();
    if (m_nodeType.hasOutput()) {
        ruleSettings.setNewcolName(m_newColumnName.getText());
        if (m_replaceColumn != null) {
            ruleSettings.setAppendColumn(m_newColumnName.isEnabled());
            ruleSettings.setReplaceColumn(m_replaceColumn.getSelectedColumn());
            if (m_outputGroup.isSelected(m_replaceColRadio.getModel()) && m_replaceColumn.getSelectedColumn() == null) {
                throw new InvalidSettingsException("No column was selected for replacement!");
            }
        }
    } else {
        ruleSettings.setNewcolName("");
    }
    // Check the rule integrity, configure will also check.
    try {
        computeRules();
    } catch (ParseException e) {
        throw new InvalidSettingsException(e.getMessage(), e);
    }
    for (String r : m_mainPanel.getExpression().split("\n", -1)) {
        if (!r.trim().isEmpty()) {
            ruleSettings.addRule(r);
        }
    }
    ruleSettings.saveSettings(settings);
    if (!m_nodeType.hasOutput()) {
        final SettingsModelBoolean settingsModelBoolean = new SettingsModelBoolean(RuleEngineFilterNodeModel.CFGKEY_INCLUDE_ON_MATCH, RuleEngineFilterNodeModel.DEFAULT_INCLUDE_ON_MATCH);
        settingsModelBoolean.setBooleanValue(m_top.isSelected());
        settingsModelBoolean.saveSettingsTo(settings);
    }
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ParseException(java.text.ParseException)

Example 4 with SettingsModelBoolean

use of org.knime.core.node.defaultnodesettings.SettingsModelBoolean in project knime-core by knime.

the class ExtractDateTimeFieldsNodeModel method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) {
    m_colSelectModel.saveSettingsTo(settings);
    for (final SettingsModelBoolean sm : m_dateModels) {
        sm.saveSettingsTo(settings);
    }
    for (final SettingsModelBoolean sm : m_timeModels) {
        sm.saveSettingsTo(settings);
    }
    m_subsecondUnitsModel.saveSettingsTo(settings);
    for (final SettingsModelBoolean sm : m_timeZoneModels) {
        sm.saveSettingsTo(settings);
    }
    m_localeModel.saveSettingsTo(settings);
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean)

Example 5 with SettingsModelBoolean

use of org.knime.core.node.defaultnodesettings.SettingsModelBoolean in project knime-core by knime.

the class DateTimeBasedRowFilterNodeDialog method updateEnableStatusOfDateTimeComponents.

private void updateEnableStatusOfDateTimeComponents(final SettingsModelDateTime startDateTimeModel, final SettingsModelDateTime endDateTimeModel) {
    try {
        final DataType type = m_dialogCompColSelection.getSelectedAsSpec().getType();
        startDateTimeModel.setEnabled(!((SettingsModelBoolean) m_dialogCompStartAlwaysNow.getModel()).getBooleanValue() && ((SettingsModelBoolean) m_dialogCompStartBoolean.getModel()).getBooleanValue());
        startDateTimeModel.setUseDate(!type.isCompatible(LocalTimeValue.class));
        startDateTimeModel.setUseTime(!type.isCompatible(LocalDateValue.class));
        startDateTimeModel.setUseZone(type.isCompatible(ZonedDateTimeValue.class));
        endDateTimeModel.setEnabled(!((SettingsModelBoolean) m_dialogCompEndAlwaysNow.getModel()).getBooleanValue() && ((SettingsModelBoolean) m_dialogCompEndBoolean.getModel()).getBooleanValue());
        endDateTimeModel.setUseDate(!type.isCompatible(LocalTimeValue.class));
        endDateTimeModel.setUseTime(!type.isCompatible(LocalDateValue.class));
        endDateTimeModel.setUseZone(type.isCompatible(ZonedDateTimeValue.class));
    } catch (NullPointerException e) {
    }
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) DataType(org.knime.core.data.DataType) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue)

Aggregations

SettingsModelBoolean (org.knime.core.node.defaultnodesettings.SettingsModelBoolean)36 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)15 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)13 ChangeEvent (javax.swing.event.ChangeEvent)5 ChangeListener (javax.swing.event.ChangeListener)5 IOException (java.io.IOException)4 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)4 DialogComponentBoolean (org.knime.core.node.defaultnodesettings.DialogComponentBoolean)4 DialogComponentString (org.knime.core.node.defaultnodesettings.DialogComponentString)4 File (java.io.File)3 DataTableSpec (org.knime.core.data.DataTableSpec)3 RowKey (org.knime.core.data.RowKey)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 ExecutionContext (org.knime.core.node.ExecutionContext)3 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)3 NodeModel (org.knime.core.node.NodeModel)3 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)3 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)3 DateTimeException (java.time.DateTimeException)2 Duration (java.time.Duration)2