Search in sources :

Example 1 with InvalidParameterValueException

use of com.genericworkflownodes.knime.parameter.InvalidParameterValueException in project GenericKnimeNodes by genericworkflownodes.

the class ParamCellEditor method getCellEditorValue.

@Override
public Object getCellEditorValue() {
    if (param instanceof StringParameter || param instanceof DoubleParameter || param instanceof IntegerParameter) {
        try {
            if ((new ParameterVerifier(param)).verify(field)) {
                param.fillFromString(field.getText());
            } else {
                JOptionPane.showMessageDialog(null, String.format("Invalid parameter value. Please provide a valid value for: %s", param.getMnemonic()));
            }
        } catch (InvalidParameterValueException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    if (param instanceof StringChoiceParameter) {
        StringChoiceParameter scp = (StringChoiceParameter) param;
        String selectedValue = (String) choiceComboBox.getSelectedItem();
        scp.setValue(selectedValue);
    }
    if (param instanceof BoolParameter) {
        try {
            param.fillFromString(choiceComboBox.getSelectedItem().toString());
        } catch (InvalidParameterValueException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    if (param instanceof ListParameter) {
        String workaround = listEditorComponent.getParameterValue();
        try {
            param.fillFromString(workaround);
        } catch (InvalidParameterValueException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    return param;
}
Also used : IntegerParameter(com.genericworkflownodes.knime.parameter.IntegerParameter) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter) InvalidParameterValueException(com.genericworkflownodes.knime.parameter.InvalidParameterValueException) ParameterVerifier(com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.verifier.ParameterVerifier) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) ListParameter(com.genericworkflownodes.knime.parameter.ListParameter)

Example 2 with InvalidParameterValueException

use of com.genericworkflownodes.knime.parameter.InvalidParameterValueException in project GenericKnimeNodes by genericworkflownodes.

the class GenericKnimeNodeDialog method loadSettingsFrom.

@Override
protected void loadSettingsFrom(NodeSettingsRO settings, PortObjectSpec[] specs) throws NotConfigurableException {
    String errorsFound = "";
    for (String key : config.getParameterKeys()) {
        Parameter<?> param = config.getParameter(key);
        // skip file parameters
        if (param instanceof IFileParameter) {
            continue;
        }
        String value = null;
        try {
            value = settings.getString(key);
            param.fillFromString(value);
        } catch (InvalidSettingsException e) {
            errorsFound += "- Entry for " + key + " not found in settings.xml.\n";
        } catch (InvalidParameterValueException e) {
            errorsFound += "- Entry for " + key + " in settings.xml has a value that does not match it restrictions.\n";
        // Do not hard fail. Users should be able to edit the value in the dialog.
        /*throw new NotConfigurableException(e.getMessage(), e);*/
        }
    }
    if (!errorsFound.isEmpty()) {
        LOGGER.error("Errors found loading Settings from disk. Maybe you are loading a node created with another version." + "\nUsing default values as defined in the Tool description." + "\nWe recommend to check the parameters highlighted in red carefully before clicking OK: \n" + errorsFound);
    }
    int nP = config.getNumberOfOutputPorts();
    int[] selectedPorts = new int[nP];
    for (int i = 0; i < nP; i++) {
        try {
            int idx = settings.getInt(GenericKnimeNodeModel.GENERIC_KNIME_NODES_OUTTYPE_PREFIX + i);
            selectedPorts[i] = idx;
        } catch (InvalidSettingsException e) {
            throw new NotConfigurableException(e.getMessage(), e);
        }
    }
    mtc.setSelectedTypes(selectedPorts);
}
Also used : IFileParameter(com.genericworkflownodes.knime.parameter.IFileParameter) NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidParameterValueException(com.genericworkflownodes.knime.parameter.InvalidParameterValueException)

Aggregations

InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)2 ParameterVerifier (com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.verifier.ParameterVerifier)1 BoolParameter (com.genericworkflownodes.knime.parameter.BoolParameter)1 DoubleParameter (com.genericworkflownodes.knime.parameter.DoubleParameter)1 IFileParameter (com.genericworkflownodes.knime.parameter.IFileParameter)1 IntegerParameter (com.genericworkflownodes.knime.parameter.IntegerParameter)1 ListParameter (com.genericworkflownodes.knime.parameter.ListParameter)1 StringChoiceParameter (com.genericworkflownodes.knime.parameter.StringChoiceParameter)1 StringParameter (com.genericworkflownodes.knime.parameter.StringParameter)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1