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