use of com.genericworkflownodes.knime.parameter.BoolParameter 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.BoolParameter 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.BoolParameter in project GenericKnimeNodes by genericworkflownodes.
the class ParamHandler method handleStringType.
/**
* Convert the current element into a StringParameter.
*
* @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 handleStringType(String paramName, String paramValue, Attributes attributes) {
if (isPort(attributes)) {
createPort(paramName, attributes, false);
} else {
// check if we have a boolean
String restrictions = attributes.getValue(ATTR_RESTRICTIONS);
if (isBooleanParameter(restrictions)) {
m_currentParameter = new BoolParameter(paramName, paramValue);
} else {
if (restrictions != null && restrictions.length() > 0) {
m_currentParameter = new StringChoiceParameter(paramName, restrictions.split(","));
((StringChoiceParameter) m_currentParameter).setValue(paramValue);
} else {
m_currentParameter = new StringParameter(paramName, paramValue);
}
}
}
}
use of com.genericworkflownodes.knime.parameter.BoolParameter 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;
}
use of com.genericworkflownodes.knime.parameter.BoolParameter 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;
}
Aggregations