Search in sources :

Example 1 with Filter

use of org.knime.base.node.io.listfiles2.ListFiles.Filter in project knime-core by knime.

the class ListFilesSettings method loadSettingsInDialog.

/**
 * Load settings in dialog (no fail).
 *
 * @param settings To load from.
 */
protected void loadSettingsInDialog(final NodeSettingsRO settings) {
    m_locationString = settings.getString(LOCATION_SETTINGS, "");
    m_extensionsString = settings.getString(EXTENSIONS_SETTINGS, "");
    m_recursive = settings.getBoolean(RECURSIVE_SETTINGS, false);
    final Filter defFilter = Filter.None;
    String filterS = settings.getString(FILTER_SETTINGS, defFilter.name());
    if (filterS == null) {
        filterS = defFilter.name();
    }
    try {
        m_filter = Filter.valueOf(filterS);
    } catch (IllegalArgumentException iae) {
        m_filter = defFilter;
    }
    m_caseSensitive = settings.getBoolean(CASE_SENSITIVE_STRING, false);
}
Also used : Filter(org.knime.base.node.io.listfiles2.ListFiles.Filter)

Example 2 with Filter

use of org.knime.base.node.io.listfiles2.ListFiles.Filter in project knime-core by knime.

the class ListFilesNodeDialog method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    // check if all entered Locations are valid
    String location = m_localdirectory.getSelectedFile();
    if (location.trim().isEmpty()) {
        throw new InvalidSettingsException("Please select a file!");
    }
    ListFilesSettings set = new ListFilesSettings();
    set.setLocationString(location);
    set.setRecursive(m_recursive.isSelected());
    set.setCaseSensitive(m_caseSensitive.isSelected());
    String extensions = m_extensionField.getEditor().getItem().toString();
    set.setExtensionsString(extensions);
    // save the selected radio-Button
    Filter filter;
    if (m_filterALLRadio.isSelected()) {
        filter = Filter.None;
    } else if (m_filterExtensionsRadio.isSelected()) {
        filter = Filter.Extensions;
    } else if (m_filterRegExpRadio.isSelected()) {
        if (extensions.trim().isEmpty()) {
            throw new InvalidSettingsException("Enter valid regular expressin pattern");
        }
        try {
            String pattern = extensions;
            Pattern.compile(pattern);
        } catch (PatternSyntaxException pse) {
            throw new InvalidSettingsException("Error in pattern: ('" + pse.getMessage(), pse);
        }
        filter = Filter.RegExp;
    } else if (m_filterWildCardsRadio.isSelected()) {
        if ((extensions).length() <= 0) {
            throw new InvalidSettingsException("Enter valid wildcard pattern");
        }
        try {
            String pattern = extensions;
            pattern = WildcardMatcher.wildcardToRegex(pattern);
            Pattern.compile(pattern);
        } catch (PatternSyntaxException pse) {
            throw new InvalidSettingsException("Error in pattern: '" + pse.getMessage(), pse);
        }
        filter = Filter.Wildcards;
    } else {
        // one button must be selected though
        filter = Filter.None;
    }
    set.setFilter(filter);
    set.saveSettingsTo(settings);
    m_localdirectory.addToHistory();
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Filter(org.knime.base.node.io.listfiles2.ListFiles.Filter) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

Filter (org.knime.base.node.io.listfiles2.ListFiles.Filter)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1