Search in sources :

Example 16 with InvalidSettingsException

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);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Calendar(java.util.Calendar)

Example 17 with InvalidSettingsException

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;
}
Also used : JPanel(javax.swing.JPanel) FocusAdapter(java.awt.event.FocusAdapter) ItemEvent(java.awt.event.ItemEvent) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) JCheckBox(javax.swing.JCheckBox) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ItemListener(java.awt.event.ItemListener)

Example 18 with InvalidSettingsException

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);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Calendar(java.util.Calendar)

Example 19 with InvalidSettingsException

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();
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType)

Example 20 with InvalidSettingsException

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;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) File(java.io.File) URL(java.net.URL) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IOException(java.io.IOException)

Aggregations

InvalidSettingsException (org.knime.core.node.InvalidSettingsException)818 DataTableSpec (org.knime.core.data.DataTableSpec)278 DataColumnSpec (org.knime.core.data.DataColumnSpec)211 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)153 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)121 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)113 IOException (java.io.IOException)109 DataCell (org.knime.core.data.DataCell)99 ArrayList (java.util.ArrayList)96 DataType (org.knime.core.data.DataType)89 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)82 File (java.io.File)72 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)69 DataRow (org.knime.core.data.DataRow)66 DoubleValue (org.knime.core.data.DoubleValue)58 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)48 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)47 FileInputStream (java.io.FileInputStream)43 LinkedHashMap (java.util.LinkedHashMap)42 NotConfigurableException (org.knime.core.node.NotConfigurableException)41