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()));
}
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);
}
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);
}
}
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;
}
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;
}
}
}
}
}
Aggregations