Search in sources :

Example 1 with SettingsModelStringArray

use of org.knime.core.node.defaultnodesettings.SettingsModelStringArray in project GenericKnimeNodes by genericworkflownodes.

the class ListMimeFileImporterNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    SettingsModelStringArray tmp_filenames = m_filenames.createCloneWithValidatedValue(settings);
    if (tmp_filenames == null || tmp_filenames.getStringArrayValue().length == 0) {
        throw new InvalidSettingsException("No Files selected.");
    }
    SettingsModelOptionalString tmp_file_extension = m_file_extension.createCloneWithValidatedValue(settings);
    if (tmp_file_extension.isActive()) {
        if (tmp_file_extension.getStringValue().equals("")) {
            throw new InvalidSettingsException("No File extension (override) provided.");
        } else if (MIMETypeHelper.getMIMEtypeByExtension(tmp_file_extension.getStringValue()) == null) {
            throw new InvalidSettingsException("No MIMEtype registered for file extension: " + tmp_file_extension.getStringValue());
        }
    } else {
        List<String> mts = new ArrayList<String>();
        String mt = null;
        for (String filename : tmp_filenames.getStringArrayValue()) {
            mt = MIMETypeHelper.getMIMEtype(filename);
            if (mt == null) {
                throw new InvalidSettingsException("Files of unknown MIMEtype selected: " + filename);
            }
            mts.add(mt);
        }
        for (String mimeType : mts) {
            if (!mimeType.equals(mt)) {
                throw new InvalidSettingsException("Files with mixed MIMEType loaded");
            }
        }
    }
}
Also used : SettingsModelStringArray(org.knime.core.node.defaultnodesettings.SettingsModelStringArray) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelOptionalString(org.knime.core.node.defaultnodesettings.SettingsModelOptionalString) ArrayList(java.util.ArrayList) SettingsModelOptionalString(org.knime.core.node.defaultnodesettings.SettingsModelOptionalString)

Example 2 with SettingsModelStringArray

use of org.knime.core.node.defaultnodesettings.SettingsModelStringArray in project GenericKnimeNodes by genericworkflownodes.

the class DialogComponentMultiFileChooser method validateSettingsBeforeSave.

@Override
protected void validateSettingsBeforeSave() throws InvalidSettingsException {
    String[] filenames = new String[listbox.getModel().getSize()];
    int idx = 0;
    for (File file : ((FileListModel) listbox.getModel()).getFiles()) {
        String filename = file.getAbsolutePath();
        filenames[idx] = filename;
        idx++;
    }
    ((SettingsModelStringArray) getModel()).setStringArrayValue(filenames);
}
Also used : SettingsModelStringArray(org.knime.core.node.defaultnodesettings.SettingsModelStringArray) File(java.io.File)

Aggregations

SettingsModelStringArray (org.knime.core.node.defaultnodesettings.SettingsModelStringArray)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 SettingsModelOptionalString (org.knime.core.node.defaultnodesettings.SettingsModelOptionalString)1