use of com.genericworkflownodes.knime.parameter.StringChoiceParameter 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.StringChoiceParameter 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;
}
use of com.genericworkflownodes.knime.parameter.StringChoiceParameter in project GenericKnimeNodes by genericworkflownodes.
the class GalaxyNodeConfigurationReader method processParameter.
private void processParameter(Node n) throws Exception {
Parameter<?> ret = null;
String type = n.valueOf("@type");
if (type.equals("")) {
throw new Exception("type information for parameter not set");
}
String key = n.valueOf("@name");
String val = n.valueOf("@value");
System.out.println("processing param " + key + " type:" + type + " value: " + val);
if (type.equals("integer")) {
ret = new IntegerParameter(key, val);
}
if (type.equals("float")) {
ret = new DoubleParameter(key, val);
}
if (type.equals("boolean")) {
ret = new BoolParameter(key, val);
}
if (type.equals("text")) {
ret = new StringParameter(key, val);
}
if (type.equals("select")) {
List<Node> options = DOMHelper.selectNodes(n, "option");
List<String> opts = new ArrayList<String>();
List<String> labs = new ArrayList<String>();
for (Node option : options) {
String optval = option.valueOf("@value");
String label = option.valueOf("text()");
opts.add(optval);
labs.add(label);
}
ret = new StringChoiceParameter(key, opts, labs);
((StringChoiceParameter) ret).setValue(val);
ret.setIsOptional(false);
}
String descr = n.valueOf("label/text()");
if (ret != null) {
ret.setKey(key);
ret.setDescription(descr);
}
config.addParameter(key, ret);
}
Aggregations