Search in sources :

Example 21 with SettingsModelBoolean

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

the class CreateDateTimeNodeModel method createEndModel.

/**
 * @return the date&time model, used in both dialog and model.
 */
static SettingsModelDateTime createEndModel(final SettingsModelString rowNrOptionSelectionModel, final SettingsModelString durationOrEndSelectionModel, final SettingsModelBoolean useExecTimeModel) {
    final SettingsModelDateTime settingsModelDateTime = new SettingsModelDateTime("end", LocalDateTime.now().withNano(0));
    final ChangeListener changeListener = e -> {
        if (durationOrEndSelectionModel.getStringValue() != null && rowNrOptionSelectionModel.getStringValue() != null) {
            settingsModelDateTime.setEnabled((rowNrOptionSelectionModel.getStringValue().equals(RowNrMode.Variable.name()) || (rowNrOptionSelectionModel.getStringValue().equals(RowNrMode.Fixed.name()) && durationOrEndSelectionModel.getStringValue().equals(EndMode.End.name()))) && !useExecTimeModel.getBooleanValue());
        }
    };
    rowNrOptionSelectionModel.addChangeListener(changeListener);
    durationOrEndSelectionModel.addChangeListener(changeListener);
    useExecTimeModel.addChangeListener(changeListener);
    changeListener.stateChanged(new ChangeEvent(rowNrOptionSelectionModel));
    return settingsModelDateTime;
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO) RowKey(org.knime.core.data.RowKey) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) SettingsModelLongBounded(org.knime.core.node.defaultnodesettings.SettingsModelLongBounded) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) ExecutionContext(org.knime.core.node.ExecutionContext) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Duration(java.time.Duration) LocalTime(java.time.LocalTime) TemporalAmount(java.time.temporal.TemporalAmount) DateTimeType(org.knime.time.util.DateTimeType) ChangeListener(javax.swing.event.ChangeListener) DataCell(org.knime.core.data.DataCell) DateTimeException(java.time.DateTimeException) Period(java.time.Period) ChangeEvent(javax.swing.event.ChangeEvent) DurationPeriodFormatUtils(org.knime.time.util.DurationPeriodFormatUtils) DefaultRow(org.knime.core.data.def.DefaultRow) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) IOException(java.io.IOException) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) NodeModel(org.knime.core.node.NodeModel) File(java.io.File) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DateTimeParseException(java.time.format.DateTimeParseException) BufferedDataTable(org.knime.core.node.BufferedDataTable) ChronoUnit(java.time.temporal.ChronoUnit) SettingsModelLong(org.knime.core.node.defaultnodesettings.SettingsModelLong) LocalDate(java.time.LocalDate) SettingsModelDateTime(org.knime.time.util.SettingsModelDateTime) Temporal(java.time.temporal.Temporal) ChangeEvent(javax.swing.event.ChangeEvent) SettingsModelDateTime(org.knime.time.util.SettingsModelDateTime) ChangeListener(javax.swing.event.ChangeListener)

Example 22 with SettingsModelBoolean

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

the class CreateDateTimeNodeModel method createEndUseExecTimeModel.

/**
 * @return the boolean model, used in both dialog and model.
 */
static SettingsModelBoolean createEndUseExecTimeModel(final SettingsModelString rowNrOptionSelectionModel, final SettingsModelString durationOrEndSelectionModel) {
    SettingsModelBoolean settingsModelBoolean = new SettingsModelBoolean("end_use_exec_time", false);
    final ChangeListener changeListener = e -> {
        if (durationOrEndSelectionModel.getStringValue() != null && rowNrOptionSelectionModel.getStringValue() != null) {
            settingsModelBoolean.setEnabled(rowNrOptionSelectionModel.getStringValue().equals(RowNrMode.Variable.name()) || (rowNrOptionSelectionModel.getStringValue().equals(RowNrMode.Fixed.name()) && durationOrEndSelectionModel.getStringValue().equals(EndMode.End.name())));
        }
    };
    rowNrOptionSelectionModel.addChangeListener(changeListener);
    durationOrEndSelectionModel.addChangeListener(changeListener);
    changeListener.stateChanged(new ChangeEvent(rowNrOptionSelectionModel));
    return settingsModelBoolean;
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO) RowKey(org.knime.core.data.RowKey) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) SettingsModelLongBounded(org.knime.core.node.defaultnodesettings.SettingsModelLongBounded) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) ExecutionContext(org.knime.core.node.ExecutionContext) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Duration(java.time.Duration) LocalTime(java.time.LocalTime) TemporalAmount(java.time.temporal.TemporalAmount) DateTimeType(org.knime.time.util.DateTimeType) ChangeListener(javax.swing.event.ChangeListener) DataCell(org.knime.core.data.DataCell) DateTimeException(java.time.DateTimeException) Period(java.time.Period) ChangeEvent(javax.swing.event.ChangeEvent) DurationPeriodFormatUtils(org.knime.time.util.DurationPeriodFormatUtils) DefaultRow(org.knime.core.data.def.DefaultRow) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) IOException(java.io.IOException) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) NodeModel(org.knime.core.node.NodeModel) File(java.io.File) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DateTimeParseException(java.time.format.DateTimeParseException) BufferedDataTable(org.knime.core.node.BufferedDataTable) ChronoUnit(java.time.temporal.ChronoUnit) SettingsModelLong(org.knime.core.node.defaultnodesettings.SettingsModelLong) LocalDate(java.time.LocalDate) SettingsModelDateTime(org.knime.time.util.SettingsModelDateTime) Temporal(java.time.temporal.Temporal) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 23 with SettingsModelBoolean

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

the class ExtractDurationPeriodFieldsNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    final ColumnRearranger rearranger = new ColumnRearranger(spec);
    if (m_colSelectModel.getStringValue() == null) {
        throw new InvalidSettingsException("Node must be configured!");
    }
    if (spec.findColumnIndex(m_colSelectModel.getStringValue()) < 0) {
        throw new InvalidSettingsException("Column '" + m_colSelectModel.getStringValue() + "' not found in the input table.");
    }
    final boolean isDurationColumn = spec.getColumnSpec(m_colSelectModel.getStringValue()).getType().isCompatible(DurationValue.class);
    final List<DataColumnSpec> colSpecs = new ArrayList<>();
    if (isDurationColumn) {
        for (final SettingsModelBoolean model : m_durModels) {
            if (model.getBooleanValue()) {
                if (model.equals(m_hourModel)) {
                    colSpecs.add(new UniqueNameGenerator(spec).newColumn(model.getConfigName(), LongCell.TYPE));
                } else {
                    colSpecs.add(new UniqueNameGenerator(spec).newColumn(model.getConfigName(), IntCell.TYPE));
                }
            }
        }
        if (m_subSecondModel.getBooleanValue()) {
            colSpecs.add(new UniqueNameGenerator(spec).newColumn(m_subSecondUnitsModel.getStringValue(), IntCell.TYPE));
        }
    } else {
        for (final SettingsModelBoolean model : m_perModels) {
            if (model.getBooleanValue()) {
                colSpecs.add(new UniqueNameGenerator(spec).newColumn(model.getConfigName(), LongCell.TYPE));
            }
        }
    }
    final DataColumnSpec[] colSpecsArray = new DataColumnSpec[colSpecs.size()];
    colSpecs.toArray(colSpecsArray);
    final CellFactory cellFac;
    if (isDurationColumn) {
        cellFac = new ExtractDurationFieldsCellFactory(spec.findColumnIndex(m_colSelectModel.getStringValue()), colSpecsArray);
    } else {
        cellFac = new ExtractPeriodFieldsCellFactory(spec.findColumnIndex(m_colSelectModel.getStringValue()), colSpecsArray);
    }
    rearranger.append(cellFac);
    return rearranger;
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) CellFactory(org.knime.core.data.container.CellFactory) IntCellFactory(org.knime.core.data.def.IntCell.IntCellFactory) LongCellFactory(org.knime.core.data.def.LongCell.LongCellFactory)

Example 24 with SettingsModelBoolean

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

the class ExtractDateTimeFieldsNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_colSelectModel.validateSettings(settings);
    for (final SettingsModelBoolean sm : m_dateModels) {
        sm.validateSettings(settings);
    }
    for (final SettingsModelBoolean sm : m_timeModels) {
        sm.validateSettings(settings);
    }
    m_subsecondUnitsModel.validateSettings(settings);
    for (final SettingsModelBoolean sm : m_timeZoneModels) {
        sm.validateSettings(settings);
    }
    m_localeModel.validateSettings(settings);
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean)

Example 25 with SettingsModelBoolean

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

the class ExtractDateTimeFieldsNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_colSelectModel.loadSettingsFrom(settings);
    for (final SettingsModelBoolean sm : m_dateModels) {
        sm.loadSettingsFrom(settings);
    }
    for (final SettingsModelBoolean sm : m_timeModels) {
        sm.loadSettingsFrom(settings);
    }
    m_subsecondUnitsModel.loadSettingsFrom(settings);
    for (final SettingsModelBoolean sm : m_timeZoneModels) {
        sm.loadSettingsFrom(settings);
    }
    m_localeModel.loadSettingsFrom(settings);
}
Also used : SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean)

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