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());
}
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());
}
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());
}
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));
}
}
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;
}
Aggregations