Search in sources :

Example 1 with IntegerListParameter

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

the class CTDHandlerTest method testParamHandler.

@Test
public void testParamHandler() throws ParserConfigurationException, SAXException, IOException {
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema ctdSchema = schemaFactory.newSchema(SchemaProvider.class.getResource("CTD.xsd"));
    SAXParserFactory spfac = SAXParserFactory.newInstance();
    spfac.setValidating(false);
    spfac.setSchema(ctdSchema);
    // Now use the parser factory to create a SAXParser object
    SAXParser sp = spfac.newSAXParser();
    CTDHandler handler = new CTDHandler(sp.getXMLReader());
    sp.parse(TestDataSource.class.getResourceAsStream("FileFilter.ctd"), handler);
    INodeConfiguration config = handler.getNodeConfiguration();
    StringParameter mz = (StringParameter) config.getParameter("FileFilter.1.mz");
    assertEquals("m/z range to extract (applies to ALL ms levels!)", mz.getDescription());
    assertEquals(":", mz.getValue());
    assertEquals("mz", mz.getKey());
    IntegerListParameter levels = (IntegerListParameter) config.getParameter("FileFilter.1.peak_options.level");
    assertEquals("MS levels to extract", levels.getDescription());
    assertEquals(3, levels.getValue().size());
    assertEquals(1, levels.getValue().get(0).intValue());
    assertEquals(2, levels.getValue().get(1).intValue());
    assertEquals(3, levels.getValue().get(2).intValue());
    assertEquals(false, levels.isAdvanced());
    StringChoiceParameter int_precision = (StringChoiceParameter) config.getParameter("FileFilter.1.peak_options.int_precision");
    assertEquals("32", int_precision.getValue());
    assertEquals(3, int_precision.getAllowedValues().size());
    BoolParameter no_progress = (BoolParameter) config.getParameter("FileFilter.1.no_progress");
    assertEquals(false, no_progress.getValue());
    assertEquals(true, no_progress.isAdvanced());
    assertEquals(3, config.getInputPorts().size());
    assertEquals("FileFilter.1.in", config.getInputPorts().get(0).getName());
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) Schema(javax.xml.validation.Schema) CTDHandler(com.genericworkflownodes.knime.config.reader.handler.CTDHandler) TestDataSource(com.genericworkflownodes.knime.test.data.TestDataSource) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) SchemaProvider(com.genericworkflownodes.knime.schemas.SchemaProvider) SAXParser(javax.xml.parsers.SAXParser) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 2 with IntegerListParameter

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

the class CTDConfigurationWriterTest method testWrite.

@Test
public void testWrite() throws Exception {
    CTDConfigurationReader reader = new CTDConfigurationReader();
    INodeConfiguration config = reader.read(TestDataSource.class.getResourceAsStream("FileFilter.ctd"));
    // write to test file
    File tmp = File.createTempFile("testing_", ".ini");
    tmp.deleteOnExit();
    BufferedWriter buffered_file_writer = new BufferedWriter(new FileWriter(tmp));
    CTDConfigurationWriter file_writer = new CTDConfigurationWriter(buffered_file_writer);
    file_writer.write(config);
    config = reader.read(new FileInputStream(tmp));
    StringParameter mz = (StringParameter) config.getParameter("FileFilter.1.mz");
    assertEquals("m/z range to extract (applies to ALL ms levels!)", mz.getDescription());
    assertEquals(":", mz.getValue());
    assertEquals("mz", mz.getKey());
    IntegerListParameter levels = (IntegerListParameter) config.getParameter("FileFilter.1.peak_options.level");
    assertNotNull(levels);
    assertEquals("MS levels to extract", levels.getDescription());
    assertEquals(3, levels.getValue().size());
    assertEquals(1, levels.getValue().get(0).intValue());
    assertEquals(2, levels.getValue().get(1).intValue());
    assertEquals(3, levels.getValue().get(2).intValue());
    assertEquals(false, levels.isAdvanced());
    assertEquals(Integer.valueOf(1), levels.getLowerBound());
    StringChoiceParameter int_precision = (StringChoiceParameter) config.getParameter("FileFilter.1.peak_options.int_precision");
    assertEquals("32", int_precision.getValue());
    assertEquals(3, int_precision.getAllowedValues().size());
    BoolParameter no_progress = (BoolParameter) config.getParameter("FileFilter.1.no_progress");
    assertEquals(false, no_progress.getValue());
    assertEquals(true, no_progress.isAdvanced());
    // Three inputs, one required, one optional with default, one optional without default
    assertEquals(2, config.getInputPorts().size());
    assertEquals("FileFilter.1.in", config.getInputPorts().get(0).getName());
}
Also used : CTDConfigurationReader(com.genericworkflownodes.knime.config.reader.CTDConfigurationReader) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) TestDataSource(com.genericworkflownodes.knime.test.data.TestDataSource) FileWriter(java.io.FileWriter) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) File(java.io.File) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 3 with IntegerListParameter

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

the class CTDConfigurationReaderTest method testReadFileFilter.

@Test
public void testReadFileFilter() throws Exception {
    CTDConfigurationReader reader = new CTDConfigurationReader();
    assertNotNull(reader);
    INodeConfiguration config = reader.read(TestDataSource.class.getResourceAsStream("FileFilter.ctd"));
    assertEquals("File Handling", config.getCategory());
    assertNotNull(config.getParameter("FileFilter.1.in"));
    assertTrue(config.getParameter("FileFilter.1.in") instanceof FileParameter);
    assertNotNull(config.getInputPortByName("FileFilter.1.in"));
    assertEquals("1.11.0", config.getVersion());
    FileParameter fp = (FileParameter) config.getParameter("FileFilter.1.in");
    assertEquals("temp", fp.getValue());
    // get list restrictions
    assertNotNull(config.getParameter("FileFilter.1.peak_options.level"));
    assertTrue(config.getParameter("FileFilter.1.peak_options.level") instanceof IntegerListParameter);
    IntegerListParameter ilp = (IntegerListParameter) config.getParameter("FileFilter.1.peak_options.level");
    assertEquals(Integer.valueOf(1), ilp.getLowerBound());
}
Also used : TestDataSource(com.genericworkflownodes.knime.test.data.TestDataSource) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) FileParameter(com.genericworkflownodes.knime.parameter.FileParameter) Test(org.junit.Test)

Example 4 with IntegerListParameter

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

the class ParamHandler method handleIntList.

/**
 * Convert the current element into a IntegerListParameter.
 *
 * @param paramName
 *            The name of the Parameter
 * @param attributes
 *            Attributes of the Parameter.
 */
private void handleIntList(String paramName, Attributes attributes) {
    m_currentParameter = new IntegerListParameter(paramName, new ArrayList<Integer>());
    // check for restrictions
    String restrs = attributes.getValue(ATTR_RESTRICTIONS);
    if (restrs != null) {
        ((IntegerListParameter) m_currentParameter).setLowerBound(new IntegerRangeExtractor().getLowerBound(restrs));
        ((IntegerListParameter) m_currentParameter).setUpperBound(new IntegerRangeExtractor().getUpperBound(restrs));
    }
}
Also used : IntegerRangeExtractor(com.genericworkflownodes.util.ranges.IntegerRangeExtractor) ArrayList(java.util.ArrayList) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter)

Example 5 with IntegerListParameter

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

the class ParameterVerifier method verify.

/*
     * (non-Javadoc)
     * 
     * @see javax.swing.InputVerifier#verify(javax.swing.JComponent)
     */
@Override
public boolean verify(JComponent input) {
    boolean returnVal = false;
    if (input instanceof JTextField) {
        String inputValue = ((JTextField) input).getText();
        if (m_parameter instanceof DoubleParameter) {
            DoubleParameter dp = (DoubleParameter) m_parameter;
            returnVal = verifyDouble(inputValue, dp.getLowerBound(), dp.getUpperBound());
        } else if (m_parameter instanceof DoubleListParameter) {
            DoubleListParameter dlp = (DoubleListParameter) m_parameter;
            returnVal = verifyDouble(inputValue, dlp.getLowerBound(), dlp.getUpperBound());
        } else if (m_parameter instanceof IntegerParameter) {
            IntegerParameter ip = (IntegerParameter) m_parameter;
            returnVal = verifyInteger(inputValue, ip.getLowerBound(), ip.getUpperBound());
        } else if (m_parameter instanceof IntegerListParameter) {
            IntegerListParameter ilp = (IntegerListParameter) m_parameter;
            returnVal = verifyInteger(inputValue, ilp.getLowerBound(), ilp.getUpperBound());
        } else {
            returnVal = true;
        }
        if (!returnVal) {
            // TODO we currently just show a message box in the ParamCellEditor (that uses the verify function).
            // input.setBackground(Color.PINK);
            LOGGER.debug("Tried to set Parameter to an invalid value. Please see the restrictrions of the parameter.");
        }
    }
    return returnVal;
}
Also used : IntegerParameter(com.genericworkflownodes.knime.parameter.IntegerParameter) DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) JTextField(javax.swing.JTextField) DoubleListParameter(com.genericworkflownodes.knime.parameter.DoubleListParameter)

Aggregations

IntegerListParameter (com.genericworkflownodes.knime.parameter.IntegerListParameter)7 INodeConfiguration (com.genericworkflownodes.knime.config.INodeConfiguration)3 TestDataSource (com.genericworkflownodes.knime.test.data.TestDataSource)3 Test (org.junit.Test)3 BoolParameter (com.genericworkflownodes.knime.parameter.BoolParameter)2 DoubleListParameter (com.genericworkflownodes.knime.parameter.DoubleListParameter)2 StringChoiceParameter (com.genericworkflownodes.knime.parameter.StringChoiceParameter)2 StringParameter (com.genericworkflownodes.knime.parameter.StringParameter)2 CTDConfigurationReader (com.genericworkflownodes.knime.config.reader.CTDConfigurationReader)1 CTDHandler (com.genericworkflownodes.knime.config.reader.handler.CTDHandler)1 DoubleParameter (com.genericworkflownodes.knime.parameter.DoubleParameter)1 FileParameter (com.genericworkflownodes.knime.parameter.FileParameter)1 IntegerParameter (com.genericworkflownodes.knime.parameter.IntegerParameter)1 StringListParameter (com.genericworkflownodes.knime.parameter.StringListParameter)1 SchemaProvider (com.genericworkflownodes.knime.schemas.SchemaProvider)1 IntegerRangeExtractor (com.genericworkflownodes.util.ranges.IntegerRangeExtractor)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1