Search in sources :

Example 1 with DoubleParameter

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

the class GalaxyNodeConfigurationReaderTest method testReader.

@Test
public void testReader() throws Exception {
    INodeConfiguration config = null;
    GalaxyNodeConfigurationReader reader = new GalaxyNodeConfigurationReader();
    config = reader.read(TestDataSource.class.getResourceAsStream("emboss_water.xml"));
    assertEquals("Smith-Waterman local alignment", config.getDescription());
    assertEquals("water", config.getName());
    assertEquals("5.0.0", config.getVersion());
    assertEquals("help text", config.getManual());
    assertEquals(2, config.getNumberOfInputPorts());
    assertEquals(1, config.getNumberOfOutputPorts());
    assertNotNull(config.getParameter("gapopen"));
    assertNotNull(config.getParameter("gapextend"));
    Parameter<?> p1 = config.getParameter("gapopen");
    Parameter<?> p2 = config.getParameter("gapextend");
    StringChoiceParameter p3 = (StringChoiceParameter) config.getParameter("menu");
    assertTrue(p1 instanceof StringParameter);
    assertTrue(p2 instanceof DoubleParameter);
    assertTrue(p3 instanceof StringChoiceParameter);
    assertEquals(p1.getValue(), "10.0");
    assertEquals(p2.getValue(), 0.5);
    assertEquals("1", p3.getValue());
    assertEquals("A", p3.getLabels().get(0));
    assertEquals("B", p3.getLabels().get(1));
    assertEquals("C", p3.getLabels().get(2));
}
Also used : StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter) GalaxyNodeConfigurationReader(com.genericworkflownodes.knime.config.impl.GalaxyNodeConfigurationReader) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) Test(org.junit.Test)

Example 2 with DoubleParameter

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

the class ParamHandler method handleDoubleType.

/**
 * Convert the current element into a DoubleParameter.
 *
 * @param paramName
 *            The name of the Parameter
 * @param paramValue
 *            The value of the Parameter as given in the param file.
 * @param attributes
 *            Attributes of the Parameter.
 */
private void handleDoubleType(final String paramName, final String paramValue, Attributes attributes) {
    m_currentParameter = new DoubleParameter(paramName, paramValue);
    // check for restrictions
    String restrs = attributes.getValue(ATTR_RESTRICTIONS);
    if (restrs != null) {
        ((DoubleParameter) m_currentParameter).setLowerBound(new DoubleRangeExtractor().getLowerBound(restrs));
        ((DoubleParameter) m_currentParameter).setUpperBound(new DoubleRangeExtractor().getUpperBound(restrs));
    }
}
Also used : DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter) DoubleRangeExtractor(com.genericworkflownodes.util.ranges.DoubleRangeExtractor)

Example 3 with DoubleParameter

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

the class CTDConfigurationWriter method addDoubleParameterRestrictions.

private void addDoubleParameterRestrictions(Parameter<?> p, StringBuffer restriction) {
    DoubleParameter dp = (DoubleParameter) p;
    boolean lbSet = Double.NEGATIVE_INFINITY != dp.getLowerBound().doubleValue();
    boolean ubSet = Double.POSITIVE_INFINITY != dp.getUpperBound().doubleValue();
    if (lbSet) {
        restriction.append(String.format(Locale.ENGLISH, "%f", dp.getLowerBound()).replaceAll(REMOVE_TRAILING_0_RE, "").replaceAll(REMOVE_TRAILING_DOT_RE, ""));
    }
    if (ubSet || lbSet) {
        restriction.append(':');
    }
    if (ubSet) {
        restriction.append(String.format(Locale.ENGLISH, "%f", dp.getUpperBound()).replaceAll(REMOVE_TRAILING_0_RE, "").replaceAll(REMOVE_TRAILING_DOT_RE, ""));
    }
}
Also used : DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter)

Example 4 with DoubleParameter

use of com.genericworkflownodes.knime.parameter.DoubleParameter 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 5 with DoubleParameter

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

the class ParamCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    param = (Parameter<?>) value;
    if (value instanceof StringChoiceParameter) {
        StringChoiceParameter scp = (StringChoiceParameter) value;
        String[] values = new String[scp.getLabels().size()];
        int i = 0;
        for (String s : scp.getLabels()) {
            values[i++] = s;
        }
        choiceComboBox = new JComboBox(values);
        // we need to make sure that we catch all edit operations.
        choiceComboBox.addItemListener(new ChoiceParamItemListener<StringChoiceParameter>(scp));
        choiceComboBox.setSelectedItem(scp.getValue());
        return choiceComboBox;
    }
    if (value instanceof StringParameter || value instanceof DoubleParameter || value instanceof IntegerParameter) {
        field = new JTextField(value.toString());
        field.setInputVerifier(new ParameterVerifier(param));
        return field;
    }
    if (value instanceof BoolParameter) {
        String[] values = new String[] { "true", "false" };
        choiceComboBox = new JComboBox(values);
        choiceComboBox.addItemListener(new ChoiceParamItemListener<BoolParameter>((BoolParameter) param));
        // Make sure that the old value is selected in the beginning.
        choiceComboBox.setSelectedIndex(((BoolParameter) value).getValue() ? 0 : 1);
        return choiceComboBox;
    }
    if (value instanceof ListParameter) {
        listEditorComponent = new ListEditorComponent((ListParameter) param, this);
        return listEditorComponent;
    }
    return null;
}
Also used : IntegerParameter(com.genericworkflownodes.knime.parameter.IntegerParameter) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter) JComboBox(javax.swing.JComboBox) ListEditorComponent(com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.list_editor.ListEditorComponent) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) JTextField(javax.swing.JTextField) ParameterVerifier(com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.verifier.ParameterVerifier) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) ListParameter(com.genericworkflownodes.knime.parameter.ListParameter)

Aggregations

DoubleParameter (com.genericworkflownodes.knime.parameter.DoubleParameter)7 IntegerParameter (com.genericworkflownodes.knime.parameter.IntegerParameter)4 StringChoiceParameter (com.genericworkflownodes.knime.parameter.StringChoiceParameter)4 StringParameter (com.genericworkflownodes.knime.parameter.StringParameter)4 BoolParameter (com.genericworkflownodes.knime.parameter.BoolParameter)3 ParameterVerifier (com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.verifier.ParameterVerifier)2 ListParameter (com.genericworkflownodes.knime.parameter.ListParameter)2 JTextField (javax.swing.JTextField)2 GalaxyNodeConfigurationReader (com.genericworkflownodes.knime.config.impl.GalaxyNodeConfigurationReader)1 ListEditorComponent (com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.list_editor.ListEditorComponent)1 DoubleListParameter (com.genericworkflownodes.knime.parameter.DoubleListParameter)1 IntegerListParameter (com.genericworkflownodes.knime.parameter.IntegerListParameter)1 InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)1 DoubleRangeExtractor (com.genericworkflownodes.util.ranges.DoubleRangeExtractor)1 ArrayList (java.util.ArrayList)1 JComboBox (javax.swing.JComboBox)1 Node (org.dom4j.Node)1 Test (org.junit.Test)1