Search in sources :

Example 1 with SplitterFactory

use of com.genericworkflownodes.knime.cluster.filesplitter.SplitterFactory in project GenericKnimeNodes by genericworkflownodes.

the class FileSplitterNodeDialog method loadAdditionalSettingsFrom.

@Override
public void loadAdditionalSettingsFrom(NodeSettingsRO settings, PortObjectSpec[] specs) throws NotConfigurableException {
    String factoryId;
    SettingsModelString facId = FileSplitterNodeModel.createFactoryIDSettingsModel();
    try {
        facId.loadSettingsFrom(settings);
        factoryId = facId.getStringValue();
    } catch (InvalidSettingsException e) {
        factoryId = null;
    }
    URIPortObjectSpec spec = (URIPortObjectSpec) specs[0];
    String ext = spec.getFileExtensions().get(0);
    String mimetype = MIMETypeHelper.getMIMEtypeByExtension(ext);
    List<SplitterFactory> factories = SplitterFactoryManager.getInstance().getFactories(mimetype);
    List<String> facs = new ArrayList<String>();
    if (factories.size() == 0) {
        facs = Collections.singletonList(NO_FACTORY);
    }
    for (SplitterFactory f : factories) {
        facs.add(f.getID());
    }
    m_factories.replaceListItems(facs, factoryId != null ? factoryId : facs.get(0));
}
Also used : SplitterFactory(com.genericworkflownodes.knime.cluster.filesplitter.SplitterFactory) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 2 with SplitterFactory

use of com.genericworkflownodes.knime.cluster.filesplitter.SplitterFactory in project GenericKnimeNodes by genericworkflownodes.

the class FileSplitterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    String factoryID = m_factoryID.getStringValue();
    URIPortObjectSpec spec = (URIPortObjectSpec) inSpecs[0];
    // If no factory has been selected in the dialog, we take the first one that matches
    if (factoryID == null) {
        String ext = spec.getFileExtensions().get(0);
        String mime = MIMETypeHelper.getMIMEtypeByExtension(ext);
        Iterator<SplitterFactory> factories = SplitterFactoryManager.getInstance().getFactories(mime).iterator();
        if (!factories.hasNext()) {
            throw new InvalidSettingsException("No suitable splitter found for mimetype " + mime + ".");
        }
        SplitterFactory fac = factories.next();
        factoryID = fac.getID();
        m_factoryID.setStringValue(factoryID);
        setWarningMessage("No splitter selected. Choosing " + factoryID + ".");
    }
    return new PortObjectSpec[] { createSpec() };
}
Also used : SplitterFactory(com.genericworkflownodes.knime.cluster.filesplitter.SplitterFactory) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

SplitterFactory (com.genericworkflownodes.knime.cluster.filesplitter.SplitterFactory)2 URIPortObjectSpec (org.knime.core.data.uri.URIPortObjectSpec)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)2 ArrayList (java.util.ArrayList)1 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1