Search in sources :

Example 26 with SettingsModelBoolean

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

the class AbstractFieldExtractorNodeDialog method createUIComponentWithFormatSelection.

/**
 * Creates the necessary {@link SettingsModel}s, adds the listener to the
 * checkbox and creates the UI component with a horizontally oriented group
 * containing the checkbox and text field for the new column name.
 * Then closes the group.
 *
 * @param timeField name of the time field for which a checkbox,
 * a text field and a format selection (int or string) should be created
 */
protected void createUIComponentWithFormatSelection(final String timeField) {
    // create the settings models and add listener
    SettingsModelBoolean checkBoxModel = createUseTimeFieldModel(timeField);
    SettingsModelString colNameModel = createTimeFieldColumnNameModel(timeField);
    SettingsModelString formatModel = createRepresentationModelFor(timeField);
    addListener(checkBoxModel, colNameModel);
    addListener(checkBoxModel, formatModel);
    createNewGroup("");
    setHorizontalPlacement(true);
    addDialogComponent(new DialogComponentBoolean(checkBoxModel, timeField));
    // add radio buttons for string or int representation
    addDialogComponent(new DialogComponentButtonGroup(formatModel, true, "Value as", AS_STRING, AS_INT));
    addDialogComponent(new DialogComponentString(colNameModel, "Column name:", true, 20));
    closeCurrentGroup();
    setHorizontalPlacement(false);
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) DialogComponentButtonGroup(org.knime.core.node.defaultnodesettings.DialogComponentButtonGroup) DialogComponentString(org.knime.core.node.defaultnodesettings.DialogComponentString) DialogComponentBoolean(org.knime.core.node.defaultnodesettings.DialogComponentBoolean) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 27 with SettingsModelBoolean

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

the class AbstractFieldExtractorNodeDialog method validateColumnName.

// general helper methods
/**
 * @param settings settings to read from
 * @param enabledModel the check box model in order to validate only active
 * column name models
 * @param colNameModel the column name model for which the value should be
 * validated
 * @return true if the name is enabled and valid, false if the name is not
 * enabled
 * @throws InvalidSettingsException if the string value of the column model
 * is either <code>null</code> or empty
 */
public static boolean validateColumnName(final NodeSettingsRO settings, final SettingsModelBoolean enabledModel, final SettingsModelString colNameModel) throws InvalidSettingsException {
    SettingsModelBoolean isEnabled = enabledModel.createCloneWithValidatedValue(settings);
    if (!isEnabled.getBooleanValue()) {
        return false;
    }
    SettingsModelString colNameClone = colNameModel.createCloneWithValidatedValue(settings);
    String colName = colNameClone.getStringValue();
    if (colName == null || colName.isEmpty()) {
        throw new InvalidSettingsException("A column name must not be empty!");
    }
    return true;
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DialogComponentString(org.knime.core.node.defaultnodesettings.DialogComponentString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 28 with SettingsModelBoolean

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

the class DateGeneratorNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_from.validateSettings(settings);
    m_to.validateSettings(settings);
    m_noOfRows.validateSettings(settings);
    // we only validate the true date if we do not use the execution time
    boolean checkFrom = true;
    try {
        SettingsModelBoolean useEx = m_useExecution.createCloneWithValidatedValue(settings);
        if (useEx.getBooleanValue()) {
            checkFrom = false;
        }
    } catch (Exception e) {
    // Do nothing, backward compatibility
    }
    if (checkFrom) {
        SettingsModelCalendar from = m_from.createCloneWithValidatedValue(settings);
        validateDates(from);
    }
    SettingsModelCalendar to = m_to.createCloneWithValidatedValue(settings);
    validateDates(to);
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) SettingsModelCalendar(org.knime.timeseries.util.SettingsModelCalendar) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 29 with SettingsModelBoolean

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

the class MovingAggregationNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_winLength.validateSettings(settings);
    m_windowType.validateSettings(settings);
    m_cumulativeComputing.validateSettings(settings);
    m_handleMissings.validateSettings(settings);
    m_removeRetainedCols.validateSettings(settings);
    m_maxUniqueVals.validateSettings(settings);
    m_valueDelimiter.validateSettings(settings);
    final List<ColumnAggregator> aggregators = ColumnAggregator.loadColumnAggregators(settings);
    final List<DataTypeAggregator> typeAggregators = new LinkedList<>();
    final List<PatternAggregator> regexAggregators = new LinkedList<>();
    try {
        regexAggregators.addAll(PatternAggregator.loadAggregators(settings, CFG_PATTERN_AGGREGATORS));
        typeAggregators.addAll(DataTypeAggregator.loadAggregators(settings, CFG_DATA_TYPE_AGGREGATORS));
    } catch (InvalidSettingsException e) {
    // introduced in 2.11
    }
    if (aggregators.isEmpty() && regexAggregators.isEmpty() && typeAggregators.isEmpty()) {
        throw new IllegalArgumentException("Please select at least one aggregation option");
    }
    final String policyLabel = ((SettingsModelString) m_columnNamePolicy.createCloneWithValidatedValue(settings)).getStringValue();
    final ColumnNamePolicy namePolicy = ColumnNamePolicy.getPolicy4Label(policyLabel);
    try {
        GroupByNodeModel.checkDuplicateAggregators(namePolicy, aggregators);
    } catch (IllegalArgumentException e) {
        throw new InvalidSettingsException(e.getMessage());
    }
    final boolean removeAggrCols = ((SettingsModelBoolean) m_removeAggregationCols.createCloneWithValidatedValue(settings)).getBooleanValue();
    if (ColumnNamePolicy.KEEP_ORIGINAL_NAME.equals(namePolicy) && !removeAggrCols) {
        throw new InvalidSettingsException("'" + ColumnNamePolicy.KEEP_ORIGINAL_NAME.getLabel() + "' option only valid if aggregation columns are filtered");
    }
}
Also used : PatternAggregator(org.knime.base.data.aggregation.dialogutil.pattern.PatternAggregator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataTypeAggregator(org.knime.base.data.aggregation.dialogutil.type.DataTypeAggregator) LinkedList(java.util.LinkedList) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) ColumnNamePolicy(org.knime.base.node.preproc.groupby.ColumnNamePolicy) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 30 with SettingsModelBoolean

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

the class FromDecisionTreeNodeDialog method createScoreDistribution.

/**
 * {@inheritDoc}
 */
@Override
protected void createScoreDistribution(final FromDecisionTreeSettings settings) {
    createNewGroup("Score distribution");
    setHorizontalPlacement(true);
    // Record count
    m_scorePmmlRecordCount = settings.getScorePmmlRecordCount();
    final SettingsModelBoolean scoreTableRecordCount = settings.getScoreTableRecordCount();
    final SettingsModelString scoreTableRecordCountPrefix = settings.getScoreTableRecordCountPrefix();
    addDialogComponent(new DialogComponentBoolean(m_scorePmmlRecordCount, "Provide score distibution record count in PMML"));
    addDialogComponent(new DialogComponentBoolean(scoreTableRecordCount, "Provide score distibution record count in table with column name prefix:"));
    addDialogComponent(new DialogComponentString(scoreTableRecordCountPrefix, ""));
    setHorizontalPlacement(false);
    setHorizontalPlacement(true);
    // Probability
    final SettingsModelBoolean scorePmmlProbability = settings.getScorePmmlProbability();
    final SettingsModelBoolean scoreTableProbability = settings.getScoreTableProbability();
    final SettingsModelString scoreTableProbabilityPrefix = settings.getScoreTableProbabilityPrefix();
    addDialogComponent(new DialogComponentBoolean(scorePmmlProbability, "Provide score distibution probability in PMML"));
    addDialogComponent(new DialogComponentBoolean(scoreTableProbability, "Provide score distibution probability in table with column name prefix:"));
    addDialogComponent(new DialogComponentString(scoreTableProbabilityPrefix, ""));
    m_scorePmmlRecordCount.addChangeListener(c -> scoreTableRecordCount.setEnabled(m_scorePmmlRecordCount.getBooleanValue()));
    m_scorePmmlRecordCount.addChangeListener(c -> scorePmmlProbability.setEnabled(m_scorePmmlRecordCount.getBooleanValue()));
    scoreTableRecordCount.addChangeListener(c -> scoreTableRecordCountPrefix.setEnabled(scoreTableRecordCount.isEnabled() && scoreTableRecordCount.getBooleanValue()));
    scorePmmlProbability.addChangeListener(c -> scoreTableProbability.setEnabled(scorePmmlProbability.isEnabled() && scorePmmlProbability.getBooleanValue()));
    scoreTableProbability.addChangeListener(c -> scoreTableProbabilityPrefix.setEnabled(scoreTableProbability.isEnabled() && scoreTableProbability.getBooleanValue()));
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) DialogComponentString(org.knime.core.node.defaultnodesettings.DialogComponentString) DialogComponentBoolean(org.knime.core.node.defaultnodesettings.DialogComponentBoolean) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

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