use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class DialogComponentTime method updateHour.
/**
* Writes the hour immediately into the model's calendar or
* throws an exception if entered value is not an integer.
*
* @throws InvalidSettingsException if entered value is not an int
*/
protected void updateHour() throws InvalidSettingsException {
SettingsModelCalendar model = (SettingsModelCalendar) getModel();
if (!model.useTime()) {
return;
}
String hourText = m_hourUI.getText();
if (!isValidHour(hourText)) {
throw new InvalidSettingsException("Hour must be between 0 and 23 but is " + hourText + "!");
}
Calendar calendar = model.getCalendar();
int hour = Integer.parseInt(hourText);
calendar.set(Calendar.HOUR_OF_DAY, hour);
model.setCalendar(calendar);
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class DialogComponentTime method createTimePanel.
private JPanel createTimePanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JPanel timePanel = new JPanel();
timePanel.setLayout(new BoxLayout(timePanel, BoxLayout.X_AXIS));
m_hourUI = new JTextField(2);
m_hourUI.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
m_hourUI.selectAll();
}
});
m_hourUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {
@Override
protected void validate() {
try {
updateHour();
} catch (InvalidSettingsException e) {
showError(m_hourUI);
}
}
});
timePanel.add(new JLabel("Hour:"));
timePanel.add(m_hourUI);
timePanel.add(Box.createHorizontalStrut(WIDTH));
m_minuteUI = new JTextField(2);
m_minuteUI.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
m_minuteUI.selectAll();
}
});
m_minuteUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {
@Override
protected void validate() {
try {
updateMinute();
} catch (InvalidSettingsException e) {
showError(m_minuteUI);
}
}
});
timePanel.add(new JLabel("Minute:"));
timePanel.add(m_minuteUI);
timePanel.add(Box.createHorizontalStrut(WIDTH));
m_secondUI = new JTextField(2);
m_secondUI.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
m_secondUI.selectAll();
}
});
m_secondUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {
@Override
protected void validate() {
try {
updateSecond();
} catch (InvalidSettingsException e) {
showError(m_secondUI);
}
}
});
timePanel.add(new JLabel("Second:"));
timePanel.add(m_secondUI);
timePanel.add(Box.createHorizontalStrut(WIDTH));
m_useMillis = new JCheckBox();
m_useMillis.setSelected(false);
m_milliUI = new JTextField(3);
m_milliUI.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
m_milliUI.selectAll();
}
});
m_milliUI.getDocument().addDocumentListener(new AbstractValidateDocumentListener() {
@Override
protected void validate() {
try {
updateMillisecond();
} catch (InvalidSettingsException e) {
showError(m_milliUI);
}
}
});
m_useMillis.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
boolean enable = m_useMillis.isSelected();
if (!enable) {
// if we are disabled -> clear all errors
// DialogComponent sets default (active!) colors
clearError(m_milliUI);
}
// now enable or disable the text field (in order to get the
// inactive default colors
m_milliUI.setEnabled(enable);
// immediately update the model
SettingsModelCalendar model = (SettingsModelCalendar) getModel();
model.setUseMilliseconds(enable);
if (enable) {
// into the model: if !useMillis it is not validated
try {
// call update milliseconds in order to set error
updateMillisecond();
} catch (InvalidSettingsException ise) {
showError(m_milliUI);
}
}
}
});
timePanel.add(m_useMillis);
timePanel.add(new JLabel("Milli:"));
timePanel.add(m_milliUI);
panel.add(timePanel);
return panel;
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class DialogComponentTime method updateSecond.
/**
* Writes the second immediately into the model's calendar or throws an
* exception if the entered value is not a valid second.
*
* @throws InvalidSettingsException if the entered value is not an int in
* the range of 0-59
*/
protected void updateSecond() throws InvalidSettingsException {
SettingsModelCalendar model = (SettingsModelCalendar) getModel();
if (!model.useTime()) {
// do not validate if time is not used by the model
return;
}
String secondText = m_secondUI.getText();
if (!isValidMinuteOrSecond(secondText)) {
throw new InvalidSettingsException("Second must be between 0 and 59 but is " + secondText + "!");
}
Calendar calendar = model.getCalendar();
int second = Integer.parseInt(secondText);
calendar.set(Calendar.SECOND, second);
model.setCalendar(calendar);
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class StringManipulationSettings method getNewColSpec.
/**
* The column spec of the generated column.
* @return The col spec.
* @throws InvalidSettingsException If settings are inconsistent.
*/
public DataColumnSpec getNewColSpec() throws InvalidSettingsException {
Class<?> returnType = getReturnType();
String colName = getColName();
boolean isArrayReturn = false;
DataType type = null;
for (JavaSnippetType<?, ?, ?> t : JavaSnippetType.TYPES) {
if (t.getJavaClass(false).equals(returnType)) {
type = t.getKNIMEDataType(isArrayReturn);
}
}
if (type == null) {
throw new InvalidSettingsException("Illegal return type: " + returnType.getName());
}
return new DataColumnSpecCreator(colName, type).createSpec();
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class StringManipulationSettings method toFile.
/**
* Convert jar file location to File. Also accepts file in URL format
* (e.g. local drop files as URL).
* @param location The location string.
* @return The file to the location
* @throws InvalidSettingsException if argument is null, empty or the file
* does not exist.
*/
public static final File toFile(final String location) throws InvalidSettingsException {
if (location == null || location.length() == 0) {
throw new InvalidSettingsException("Invalid (empty) jar file location");
}
File result;
if (location.startsWith("file:/")) {
try {
URL fileURL = new URL(location);
result = new File(fileURL.toURI());
} catch (Exception e) {
throw new InvalidSettingsException("Can't read file " + "URL \"" + location + "\"; invalid class path", e);
}
} else {
result = new File(location);
}
if (!result.exists()) {
throw new InvalidSettingsException("Can't read file \"" + location + "\"; invalid class path");
}
return result;
}
Aggregations