Search in sources :

Example 1 with IDemangler

use of com.genericworkflownodes.knime.mime.demangler.IDemangler in project GenericKnimeNodes by genericworkflownodes.

the class DemanglerNodeDialog method loadSettingsFrom.

@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    List<IDemangler> availableDemangler = new ArrayList<IDemangler>();
    String demanglerClassName = "";
    try {
        demanglerClassName = settings.getString(DemanglerNodeModel.SELECTED_DEMANGLER_SETTINGNAME, "");
        configuredFileExtension = settings.getString(DemanglerNodeModel.CONFIGURED_FILE_EXTENSION_SETTINGNAME);
        String mimeType = MIMETypeHelper.getMIMEtypeByExtension(configuredFileExtension);
        availableDemangler = DemanglerRegistry.getDemanglerRegistry().getDemangler(mimeType);
    } catch (InvalidSettingsException e) {
        e.printStackTrace();
    }
    model.removeAllElements();
    for (IDemangler d : availableDemangler) {
        model.addElement(d.getClass().getName());
    }
    // select already configured demangler -> find by class name
    if (!"".equals(demanglerClassName)) {
        int indexToSelect = model.getIndexOf(demanglerClassName);
        if (indexToSelect != -1) {
            model.setSelectedItem(demanglerClassName);
        }
    } else {
        // there is no pre-selected demangler
        model.setSelectedItem(model.getElementAt(0));
    }
}
Also used : IDemangler(com.genericworkflownodes.knime.mime.demangler.IDemangler) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList)

Example 2 with IDemangler

use of com.genericworkflownodes.knime.mime.demangler.IDemangler in project GenericKnimeNodes by genericworkflownodes.

the class DemanglerNodeModel method configure.

@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if (!(inSpecs[0] instanceof URIPortObjectSpec)) {
        throw new InvalidSettingsException("No URIPortObjectSpec compatible port object at port 0");
    }
    URIPortObjectSpec spec = (URIPortObjectSpec) inSpecs[0];
    fileExtension = spec.getFileExtensions().get(0);
    String mimeType = MIMETypeHelper.getMIMEtypeByExtension(fileExtension);
    // try to find a demangler for the data type ...
    List<IDemangler> availableDemanglers = DemanglerRegistry.getDemanglerRegistry().getDemangler(mimeType);
    if (availableDemanglers == null || availableDemanglers.size() == 0) {
        throw new InvalidSettingsException("No IDemangler found for " + fileExtension + ". Please register before transforming the a file with this MIMEType to a KNIME table.");
    }
    if (demangler == null) {
        demangler = availableDemanglers.get(0);
    }
    return new DataTableSpec[] { getDataTableSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) URIPortObjectSpec(org.knime.core.data.uri.URIPortObjectSpec) IDemangler(com.genericworkflownodes.knime.mime.demangler.IDemangler) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 3 with IDemangler

use of com.genericworkflownodes.knime.mime.demangler.IDemangler in project GenericKnimeNodes by genericworkflownodes.

the class DemanglerNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    String demanglerClassName = settings.getString(SELECTED_DEMANGLER_SETTINGNAME, "");
    fileExtension = settings.getString(CONFIGURED_FILE_EXTENSION_SETTINGNAME);
    String mimeType = MIMETypeHelper.getMIMEtypeByExtension(fileExtension);
    List<IDemangler> availableDemangler = DemanglerRegistry.getDemanglerRegistry().getDemangler(mimeType);
    demangler = null;
    if (!"".equals(demanglerClassName)) {
        for (IDemangler de : availableDemangler) {
            if (demanglerClassName.equals(de.getClass().getName())) {
                demangler = de;
                break;
            }
        }
    } else if (availableDemangler.size() > 0) {
        demangler = availableDemangler.get(0);
    }
    if (demangler == null) {
        throw new InvalidSettingsException("Could not find an implementation for the previously selected demangler: " + demanglerClassName);
    }
}
Also used : IDemangler(com.genericworkflownodes.knime.mime.demangler.IDemangler) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 4 with IDemangler

use of com.genericworkflownodes.knime.mime.demangler.IDemangler in project GenericKnimeNodes by genericworkflownodes.

the class ManglerNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    String manglerClassName = settings.getString(SELECTED_DEMANGLER_SETTINGNAME, "");
    List<IDemangler> matchingManglers = DemanglerRegistry.getDemanglerRegistry().getMangler(inputTableSpecification);
    boolean found = false;
    for (IDemangler mangler : matchingManglers) {
        if (manglerClassName.equals(mangler.getClass().getName())) {
            demangler = mangler;
            found = true;
            break;
        }
    }
    if (!found) {
        throw new InvalidSettingsException("Could not find an implementation for the previously selected mangler: " + manglerClassName);
    }
}
Also used : IDemangler(com.genericworkflownodes.knime.mime.demangler.IDemangler) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 5 with IDemangler

use of com.genericworkflownodes.knime.mime.demangler.IDemangler in project GenericKnimeNodes by genericworkflownodes.

the class ManglerNodeModel method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) {
    settings.addString(SELECTED_DEMANGLER_SETTINGNAME, demangler.getClass().getName());
    String[] manglers = new String[availableMangler.size()];
    int i = 0;
    for (IDemangler mangler : availableMangler) {
        manglers[i++] = mangler.getClass().getName();
    }
    settings.addStringArray(AVAILABLE_MIMETYPE_SETTINGNAME, manglers);
}
Also used : IDemangler(com.genericworkflownodes.knime.mime.demangler.IDemangler)

Aggregations

IDemangler (com.genericworkflownodes.knime.mime.demangler.IDemangler)5 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)4 ArrayList (java.util.ArrayList)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 URIPortObjectSpec (org.knime.core.data.uri.URIPortObjectSpec)1