Search in sources :

Example 86 with SettingsModelString

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

the class DateShiftConfigure method createNumColmodel.

/**
 * @return settings model for the first time column
 */
public static SettingsModelString createNumColmodel() {
    SettingsModelString sms = new SettingsModelString(CFG_COL1, null);
    sms.setEnabled(false);
    return sms;
}
Also used : SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 87 with SettingsModelString

use of org.knime.core.node.defaultnodesettings.SettingsModelString 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 88 with SettingsModelString

use of org.knime.core.node.defaultnodesettings.SettingsModelString 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 89 with SettingsModelString

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

the class DateFieldExtractorNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_selectedColumn.validateSettings(settings);
    m_monthRepresentation.validateSettings(settings);
    SettingsModelString monthRepModel = m_monthRepresentation.createCloneWithValidatedValue(settings);
    String monthRep = monthRepModel.getStringValue();
    if (!monthRep.equals(AbstractFieldExtractorNodeDialog.AS_INT) && !monthRep.equals(AbstractFieldExtractorNodeDialog.AS_STRING)) {
        throw new InvalidSettingsException("Month representation must be one of " + AbstractFieldExtractorNodeDialog.AS_INT + ", " + AbstractFieldExtractorNodeDialog.AS_STRING);
    }
    // year
    m_useYear.validateSettings(settings);
    m_yearColName.validateSettings(settings);
    // quarter
    m_useQuarter.validateSettings(settings);
    m_quarterColName.validateSettings(settings);
    // month
    m_useMonth.validateSettings(settings);
    m_monthColName.validateSettings(settings);
    // day of week
    m_useDayOfWeek.validateSettings(settings);
    m_dayOfWeekColName.validateSettings(settings);
    m_dayOfWeekRepresentationModel.validateSettings(settings);
    // day of month
    m_useDay.validateSettings(settings);
    m_dayColName.validateSettings(settings);
    boolean atLeastOneChecked = false;
    atLeastOneChecked |= AbstractFieldExtractorNodeDialog.validateColumnName(settings, m_useYear, m_yearColName);
    atLeastOneChecked |= AbstractFieldExtractorNodeDialog.validateColumnName(settings, m_useQuarter, m_quarterColName);
    atLeastOneChecked |= AbstractFieldExtractorNodeDialog.validateColumnName(settings, m_useMonth, m_monthColName);
    atLeastOneChecked |= AbstractFieldExtractorNodeDialog.validateColumnName(settings, m_useDay, m_dayColName);
    atLeastOneChecked |= AbstractFieldExtractorNodeDialog.validateColumnName(settings, m_useDayOfWeek, m_dayOfWeekColName);
    try {
        // day of year
        m_useDayOfYear.validateSettings(settings);
        m_dayOfYearColName.validateSettings(settings);
        atLeastOneChecked |= AbstractFieldExtractorNodeDialog.validateColumnName(settings, m_useDayOfYear, m_dayOfYearColName);
    } catch (InvalidSettingsException ise) {
    // nothing to do
    }
    // new since 2.9.1
    try {
        // week of year
        m_useWeekOfYear.validateSettings(settings);
        m_weekOfYearColName.validateSettings(settings);
        atLeastOneChecked |= AbstractFieldExtractorNodeDialog.validateColumnName(settings, m_useWeekOfYear, m_weekOfYearColName);
    } catch (InvalidSettingsException ise) {
    // nothing to do
    }
    // all unchecked?
    if (!atLeastOneChecked) {
        setWarningMessage("No time field selected. Output table will be same as input table!");
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 90 with SettingsModelString

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

the class MaskTimeNodeModel method createNewColumnNameModel.

/**
 * @return settings model to store the mask selection
 */
static SettingsModelString createNewColumnNameModel() {
    SettingsModelString sm = new SettingsModelString(CFG_NEW_COL_NAME, "MaskedTime");
    sm.setEnabled(false);
    return sm;
}
Also used : SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)96 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)36 SettingsModelBoolean (org.knime.core.node.defaultnodesettings.SettingsModelBoolean)15 ChangeListener (javax.swing.event.ChangeListener)13 ChangeEvent (javax.swing.event.ChangeEvent)12 IOException (java.io.IOException)7 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)7 DialogComponentString (org.knime.core.node.defaultnodesettings.DialogComponentString)7 Duration (java.time.Duration)5 Period (java.time.Period)5 DateTimeParseException (java.time.format.DateTimeParseException)5 SettingsModelDateTime (org.knime.time.util.SettingsModelDateTime)5 LocalDate (java.time.LocalDate)4 LocalDateTime (java.time.LocalDateTime)4 ZonedDateTime (java.time.ZonedDateTime)4 Temporal (java.time.temporal.Temporal)4 TemporalAmount (java.time.temporal.TemporalAmount)4 DateTimeType (org.knime.time.util.DateTimeType)4 File (java.io.File)3 DateTimeException (java.time.DateTimeException)3