use of org.knime.time.util.SettingsModelDateTime 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;
}
}
}
}
}
use of org.knime.time.util.SettingsModelDateTime in project knime-core by knime.
the class CreateDateTimeNodeModel method createStartModel.
/**
* @return the date&time model, used in both dialog and model.
*/
static SettingsModelDateTime createStartModel(final SettingsModelBoolean useExecTimeModel) {
final SettingsModelDateTime settingsModelDateTime = new SettingsModelDateTime("start", LocalDateTime.now().withNano(0).minusYears(1).minusHours(1));
useExecTimeModel.addChangeListener(l -> settingsModelDateTime.setEnabled(!useExecTimeModel.getBooleanValue()));
return settingsModelDateTime;
}
use of org.knime.time.util.SettingsModelDateTime 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;
}
use of org.knime.time.util.SettingsModelDateTime in project knime-core by knime.
the class DateTimeBasedRowFilterNodeDialog method checkStartAndEnd.
/**
* Checks if start and end string can be parsed with the set format and locale
*/
private void checkStartAndEnd() {
if (m_dialogCompStartDateTime.getModel().isEnabled() && m_dialogCompEndDateTime.getModel().isEnabled() && ((SettingsModelString) m_dialogCompEndSelection.getModel()).getStringValue().equals(EndMode.DateTime.name())) {
boolean isStartAfterEnd = false;
final DataType dataType = m_dialogCompColSelection.getSelectedAsSpec().getType();
if (dataType.isCompatible(LocalDateValue.class)) {
isStartAfterEnd = ((SettingsModelDateTime) m_dialogCompStartDateTime.getModel()).getLocalDate().isAfter(((SettingsModelDateTime) m_dialogCompEndDateTime.getModel()).getLocalDate());
}
if (dataType.isCompatible(LocalTimeValue.class)) {
isStartAfterEnd = ((SettingsModelDateTime) m_dialogCompStartDateTime.getModel()).getLocalTime().isAfter(((SettingsModelDateTime) m_dialogCompEndDateTime.getModel()).getLocalTime());
}
if (dataType.isCompatible(LocalDateTimeValue.class)) {
isStartAfterEnd = ((SettingsModelDateTime) m_dialogCompStartDateTime.getModel()).getLocalDateTime().isAfter(((SettingsModelDateTime) m_dialogCompEndDateTime.getModel()).getLocalDateTime());
}
if (dataType.isCompatible(ZonedDateTimeValue.class)) {
isStartAfterEnd = ((SettingsModelDateTime) m_dialogCompStartDateTime.getModel()).getZonedDateTime().isAfter(((SettingsModelDateTime) m_dialogCompEndDateTime.getModel()).getZonedDateTime());
}
if (isStartAfterEnd) {
m_typeWarningLabel.setText("End date must not be before start date!");
}
}
}
Aggregations