Search in sources :

Example 1 with SettingsModelString

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

the class RulesToTableNodeDialog method createScoreDistribution.

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

Example 2 with SettingsModelString

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

the class String2DateNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_selectedColModel.validateSettings(settings);
    m_newColNameModel.validateSettings(settings);
    SettingsModelString newColNameModel = m_newColNameModel.createCloneWithValidatedValue(settings);
    String newColName = newColNameModel.getStringValue();
    if (newColName == null || newColName.isEmpty()) {
        throw new InvalidSettingsException("Name for the new column must not be empty!");
    }
    m_replace.validateSettings(settings);
    m_formatModel.validateSettings(settings);
    SettingsModelString formatClone = m_formatModel.createCloneWithValidatedValue(settings);
    String format = formatClone.getStringValue();
    if (format == null || format.length() == 0) {
        throw new InvalidSettingsException("Format must not be empty!");
    }
    try {
        new SimpleDateFormat(format);
    } catch (Exception e) {
        String msg = "Invalid date format: \"" + format + "\".";
        String errMsg = e.getMessage();
        if (errMsg != null && !errMsg.isEmpty()) {
            msg += " Reason: " + errMsg;
        }
        throw new InvalidSettingsException(msg, e);
    }
    m_cancelOnFail.validateSettings(settings);
    m_failNumberModel.validateSettings(settings);
}
Also used : 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) ParseException(java.text.ParseException)

Example 3 with SettingsModelString

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

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

the class StringToDurationPeriodNodeModel method createSuffixModel.

/**
 * @param replaceOrAppendModel model for the replace/append button group
 * @return the string model, used in both dialog and model.
 */
public static SettingsModelString createSuffixModel(final SettingsModelString replaceOrAppendModel) {
    final SettingsModelString suffixModel = new SettingsModelString("suffix", "(Duration)");
    replaceOrAppendModel.addChangeListener(e -> suffixModel.setEnabled(replaceOrAppendModel.getStringValue().equals(OPTION_APPEND)));
    suffixModel.setEnabled(false);
    return suffixModel;
}
Also used : SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 5 with SettingsModelString

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

the class CreateDateTimeNodeDialog method updateWarningLabel.

private void updateWarningLabel() {
    m_warningLabel.setText("");
    // === check period duration field ===
    if (m_dialogCompDuration.getModel().isEnabled() && m_updateWarningLabel) {
        final DateTimeType selectedItem = (DateTimeType) m_typeCombobox.getSelectedItem();
        Duration duration = null;
        Period period = null;
        if (((SettingsModelString) m_dialogCompDuration.getModel()).getStringValue() == null) {
            m_warningLabel.setText("Please enter an interval.");
            return;
        }
        try {
            duration = DurationPeriodFormatUtils.parseDuration(((SettingsModelString) m_dialogCompDuration.getModel()).getStringValue());
            if (selectedItem.equals(DateTimeType.LOCAL_DATE)) {
                m_warningLabel.setText("A time-based duration cannot be applied to a local date.");
                return;
            }
        } catch (DateTimeParseException e1) {
            try {
                period = DurationPeriodFormatUtils.parsePeriod(((SettingsModelString) m_dialogCompDuration.getModel()).getStringValue());
                if (selectedItem.equals(DateTimeType.LOCAL_TIME)) {
                    m_warningLabel.setText("A date-based duration cannot be applied to a local time.");
                    return;
                }
            } catch (DateTimeParseException e2) {
                m_warningLabel.setText("Value does not represent a duration.");
                return;
            }
        }
        if (((SettingsModelString) m_dialogCompRowNrOptionSelection.getModel()).getStringValue().equals(RowNrMode.Variable.name())) {
            // === check that duration is not zero and row number variable ===
            if ((duration != null && duration.isZero()) || (period != null && period.isZero())) {
                m_warningLabel.setText("Interval must not be zero.");
            }
            // === check that start is before end and duration positive and vice versa ===
            final Temporal start = ((SettingsModelBoolean) m_dialogCompStartUseExecTime.getModel()).getBooleanValue() ? CreateDateTimeNodeModel.getTemporalExecTimeWithFormat(((SettingsModelDateTime) m_dialogCompEnd.getModel()).getSelectedDateTime()) : ((SettingsModelDateTime) m_dialogCompStart.getModel()).getSelectedDateTime();
            final Temporal end = ((SettingsModelBoolean) m_dialogCompEndUseExecTime.getModel()).getBooleanValue() ? CreateDateTimeNodeModel.getTemporalExecTimeWithFormat(((SettingsModelDateTime) m_dialogCompStart.getModel()).getSelectedDateTime()) : ((SettingsModelDateTime) m_dialogCompEnd.getModel()).getSelectedDateTime();
            if (!selectedItem.equals(DateTimeType.LOCAL_TIME)) {
                final boolean isStartBeforeEnd;
                final boolean isEqual;
                if (selectedItem.equals(DateTimeType.LOCAL_DATE)) {
                    isStartBeforeEnd = ((LocalDate) start).isBefore((LocalDate) end);
                    isEqual = ((LocalDate) start).isEqual((LocalDate) end);
                } else if (selectedItem.equals(DateTimeType.LOCAL_DATE_TIME)) {
                    isStartBeforeEnd = ((LocalDateTime) start).isBefore((LocalDateTime) end);
                    isEqual = ((LocalDateTime) start).isEqual((LocalDateTime) end);
                } else {
                    isStartBeforeEnd = (((ZonedDateTime) start)).toLocalDateTime().isBefore(((LocalDateTime) end));
                    isEqual = (((ZonedDateTime) start)).toLocalDateTime().isEqual(((LocalDateTime) end));
                }
                final boolean isDurationNegative;
                if (duration != null) {
                    isDurationNegative = duration.isNegative();
                } else if (period != null) {
                    isDurationNegative = period.isNegative();
                } else {
                    throw new IllegalStateException("Either duration or period must not be null!");
                }
                if (isStartBeforeEnd && isDurationNegative) {
                    m_warningLabel.setText("Start is before end, but the interval is negative.");
                    return;
                }
                if (!isStartBeforeEnd && !isEqual && !isDurationNegative) {
                    m_warningLabel.setText("Start is after end, but the interval is positive.");
                    return;
                }
            }
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) DateTimeParseException(java.time.format.DateTimeParseException) DateTimeType(org.knime.time.util.DateTimeType) Temporal(java.time.temporal.Temporal) ZonedDateTime(java.time.ZonedDateTime) SettingsModelDateTime(org.knime.time.util.SettingsModelDateTime) Period(java.time.Period) Duration(java.time.Duration) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) LocalDate(java.time.LocalDate)

Aggregations

SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)99 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)39 SettingsModelBoolean (org.knime.core.node.defaultnodesettings.SettingsModelBoolean)15 ChangeListener (javax.swing.event.ChangeListener)13 ChangeEvent (javax.swing.event.ChangeEvent)12 IOException (java.io.IOException)8 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)8 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 File (java.io.File)4 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 DateTimeException (java.time.DateTimeException)3