Search in sources :

Example 76 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class WrappedMultipleNodeDialog method doApply.

private boolean doApply() {
    try {
        NodeContainerSettings newSettings = new NodeContainerSettings();
        m_dialogPane.saveSettings(newSettings);
        if (newSettings.equals(m_initValue) || (m_initValue == null && newSettings.getJobManager() == null)) {
            informNothingChanged();
        } else {
            m_parentMgr.applyCommonSettings(newSettings, m_nodes);
        }
        return true;
    } catch (InvalidSettingsException ise) {
        LOGGER.warn("failed to apply settings: " + ise.getMessage(), ise);
        showWarningMessage("Invalid settings:\n" + ise.getMessage());
        // SWT-AWT-Bridge doesn't properly repaint after dialog disappears
        m_dialogPane.repaint();
    } catch (Throwable t) {
        LOGGER.error("failed to apply settings: " + t.getMessage(), t);
        showErrorMessage(t.getClass().getSimpleName() + ": " + t.getMessage());
        // SWT-AWT-Bridge doesn't properly repaint after dialog disappears
        m_dialogPane.repaint();
    }
    return false;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeContainerSettings(org.knime.core.node.workflow.NodeContainer.NodeContainerSettings)

Example 77 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class WrappedNodeDialog method configureShell.

/**
 * Configure shell, create top level menu.
 *
 * {@inheritDoc}
 */
@Override
protected void configureShell(final Shell newShell) {
    super.configureShell(newShell);
    Menu menuBar = new Menu(newShell, SWT.BAR);
    newShell.setMenuBar(menuBar);
    Menu menu = new Menu(newShell, SWT.DROP_DOWN);
    MenuItem rootItem = new MenuItem(menuBar, SWT.CASCADE);
    rootItem.setText("File");
    rootItem.setAccelerator(SWT.MOD1 | 'F');
    rootItem.setMenu(menu);
    final FileDialog openDialog = new FileDialog(newShell, SWT.OPEN);
    final FileDialog saveDialog = new FileDialog(newShell, SWT.SAVE);
    MenuItem itemLoad = new MenuItem(menu, SWT.PUSH);
    itemLoad.setText("Load Settings");
    itemLoad.setAccelerator(SWT.MOD1 | 'L');
    itemLoad.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            String file = openDialog.open();
            if (file != null) {
                NodeContext.pushContext(m_nodeContainer);
                try {
                    m_dialogPane.loadSettingsFrom(new FileInputStream(file));
                } catch (IOException ioe) {
                    showErrorMessage(ioe.getMessage());
                } catch (NotConfigurableException ex) {
                    showErrorMessage(ex.getMessage());
                } finally {
                    NodeContext.removeLastContext();
                }
            }
        }
    });
    MenuItem itemSave = new MenuItem(menu, SWT.PUSH);
    itemSave.setText("Save Settings");
    itemSave.setAccelerator(SWT.MOD1 | 'S');
    itemSave.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            String file = saveDialog.open();
            if (file != null) {
                NodeContext.pushContext(m_nodeContainer);
                try {
                    m_dialogPane.saveSettingsTo(new FileOutputStream(file));
                } catch (IOException ioe) {
                    showErrorMessage(ioe.getMessage());
                    // SWT-AWT-Bridge doesn't properly
                    // repaint after dialog disappears
                    m_dialogPane.getPanel().repaint();
                } catch (InvalidSettingsException ise) {
                    showErrorMessage("Invalid Settings\n" + ise.getMessage());
                    // SWT-AWT-Bridge doesn't properly
                    // repaint after dialog disappears
                    m_dialogPane.getPanel().repaint();
                } finally {
                    NodeContext.removeLastContext();
                }
            }
        }
    });
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FileOutputStream(java.io.FileOutputStream) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputStream(java.io.FileInputStream)

Example 78 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class VariableToTableSettings method loadSettingsFrom.

/**
 * Loads settings.
 *
 * @param settings to load from
 * @throws InvalidSettingsException if settings not present
 */
public void loadSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_variablesOfInterest.clear();
    m_includeAll = settings.getBoolean("all", false);
    NodeSettingsRO sub = settings.getNodeSettings("variables");
    if (sub == null) {
        throw new InvalidSettingsException("No settings available");
    }
    for (String key : sub.keySet()) {
        NodeSettingsRO sub2 = sub.getNodeSettings(key);
        String name = sub2.getString("name");
        String typeS = sub2.getString("type");
        if (name == null || typeS == null) {
            throw new InvalidSettingsException("Name and type must not be null.");
        }
        FlowVariable.Type type;
        try {
            type = FlowVariable.Type.valueOf(typeS);
        } catch (IllegalArgumentException iae) {
            throw new InvalidSettingsException("Can't parse type: " + typeS);
        }
        m_variablesOfInterest.add(new Pair<String, FlowVariable.Type>(name, type));
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 79 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class ReadPNGFromURLNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final DataTableSpec in, final AtomicLong failCounter) throws InvalidSettingsException {
    String colName = m_config.getUrlColName();
    if (colName == null) {
        // throws ISE
        m_config.guessDefaults(in);
        colName = m_config.getUrlColName();
        setWarningMessage("Auto-configuration: Guessing column \"" + colName + "\" to contain locations");
    }
    final int colIndex = in.findColumnIndex(colName);
    if (colIndex < 0) {
        throw new InvalidSettingsException("No such column in input: " + colName);
    }
    DataColumnSpec colSpec = in.getColumnSpec(colIndex);
    if (!colSpec.getType().isCompatible(StringValue.class)) {
        throw new InvalidSettingsException("Selected column \"" + colName + "\" is not string-compatible");
    }
    final String newColName = m_config.getNewColumnName();
    DataColumnSpecCreator colSpecCreator;
    if (newColName != null) {
        String newName = DataTableSpec.getUniqueColumnName(in, newColName);
        colSpecCreator = new DataColumnSpecCreator(newName, PNGImageContent.TYPE);
    } else {
        colSpecCreator = new DataColumnSpecCreator(colSpec);
        colSpecCreator.setType(PNGImageContent.TYPE);
        colSpecCreator.removeAllHandlers();
        colSpecCreator.setDomain(null);
    }
    DataColumnSpec outColumnSpec = colSpecCreator.createSpec();
    ColumnRearranger rearranger = new ColumnRearranger(in);
    CellFactory fac = new SingleCellFactory(outColumnSpec) {

        @Override
        public DataCell getCell(final DataRow row) {
            DataCell cell = row.getCell(colIndex);
            if (cell.isMissing()) {
                return DataType.getMissingCell();
            } else {
                String url = ((StringValue) cell).getStringValue();
                try {
                    return toPNGCell(url);
                } catch (Exception e) {
                    if (m_config.isFailOnInvalid()) {
                        if (e instanceof RuntimeException) {
                            throw (RuntimeException) e;
                        } else {
                            throw new RuntimeException(e.getMessage(), e);
                        }
                    } else {
                        String message = "Failed to read png content from " + "\"" + url + "\": " + e.getMessage();
                        LOGGER.warn(message, e);
                        failCounter.incrementAndGet();
                        return DataType.getMissingCell();
                    }
                }
            }
        }
    };
    if (newColName == null) {
        rearranger.replace(fac, colIndex);
    } else {
        rearranger.append(fac);
    }
    return rearranger;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataRow(org.knime.core.data.DataRow) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataCell(org.knime.core.data.DataCell) StringValue(org.knime.core.data.StringValue) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) CellFactory(org.knime.core.data.container.CellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory)

Example 80 with InvalidSettingsException

use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.

the class AppendVariableToTableNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    ColumnRearranger arranger = new ColumnRearranger(spec);
    Set<String> nameHash = new HashSet<String>();
    for (DataColumnSpec c : spec) {
        nameHash.add(c.getName());
    }
    List<Pair<String, FlowVariable.Type>> vars;
    if (m_settings.getIncludeAll()) {
        vars = getAllVariables();
    } else {
        vars = m_settings.getVariablesOfInterest();
    }
    if (vars.isEmpty()) {
        throw new InvalidSettingsException("No variables selected");
    }
    DataColumnSpec[] specs = new DataColumnSpec[vars.size()];
    final DataCell[] values = new DataCell[vars.size()];
    for (int i = 0; i < vars.size(); i++) {
        Pair<String, FlowVariable.Type> c = vars.get(i);
        String name = c.getFirst();
        DataType type;
        switch(c.getSecond()) {
            case DOUBLE:
                type = DoubleCell.TYPE;
                try {
                    double dValue = peekFlowVariableDouble(name);
                    values[i] = new DoubleCell(dValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type double): " + name);
                }
                break;
            case INTEGER:
                type = IntCell.TYPE;
                try {
                    int iValue = peekFlowVariableInt(name);
                    values[i] = new IntCell(iValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type int): " + name);
                }
                break;
            case STRING:
                type = StringCell.TYPE;
                try {
                    String sValue = peekFlowVariableString(name);
                    sValue = sValue == null ? "" : sValue;
                    values[i] = new StringCell(sValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type String): " + name);
                }
                break;
            default:
                throw new InvalidSettingsException("Unsupported variable type: " + c.getSecond());
        }
        if (nameHash.contains(name) && !name.toLowerCase().endsWith("(variable)")) {
            name = name.concat(" (variable)");
        }
        String newName = name;
        int uniquifier = 1;
        while (!nameHash.add(newName)) {
            newName = name + " (#" + (uniquifier++) + ")";
        }
        specs[i] = new DataColumnSpecCreator(newName, type).createSpec();
    }
    arranger.append(new AbstractCellFactory(specs) {

        /**
         * {@inheritDoc}
         */
        @Override
        public DataCell[] getCells(final DataRow row) {
            return values;
        }
    });
    return arranger;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet) Pair(org.knime.core.util.Pair) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) PortType(org.knime.core.node.port.PortType) DataType(org.knime.core.data.DataType) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) NoSuchElementException(java.util.NoSuchElementException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

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