use of com.genericworkflownodes.knime.parameter.ListParameter in project GenericKnimeNodes by genericworkflownodes.
the class PlainNodeConfigurationWriter method write.
public void write(String filename) throws IOException {
FileWriter out = new FileWriter(new File(filename));
for (String key : nodeConfig.getParameterKeys()) {
Parameter<?> p = nodeConfig.getParameter(key);
StringBuffer sb = new StringBuffer();
if (p instanceof ListParameter) {
ListParameter lp = (ListParameter) p;
for (String value : lp.getStrings()) {
sb.append(String.format("\"%s\"\t", value));
}
} else {
sb.append(String.format("\"%s\"\t", p.getStringRep()));
}
out.write(key + ":" + sb.toString() + LINESEP);
}
out.close();
}
use of com.genericworkflownodes.knime.parameter.ListParameter 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.ListParameter 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.ListParameter in project GenericKnimeNodes by genericworkflownodes.
the class CLICommandGenerator method handleListParameter.
private void handleListParameter(final List<List<? extends CommandLineElement>> extractedParameterValues, final ListParameter listParameter) {
final int nValues = listParameter.getStrings().size();
final String key = ((Parameter<?>) listParameter).getKey();
final List<CommandLineElement> tmpList = new LinkedList<CommandLineElement>();
// there's only one element in the list
if (nValues > 1) {
int sequence = 0;
for (final String value : listParameter.getStrings()) {
final CommandLineElement commandLineElement;
if (listParameter instanceof IFileParameter) {
commandLineElement = new CommandLineFile(new FileParameter(key, value));
} else {
commandLineElement = new CommandLineParameter(new StringParameter(key, value));
}
commandLineElement.setSequenceNumber(sequence++);
tmpList.add(commandLineElement);
}
} else {
// only one value in the list, no need to use sequence numbers
final String value = listParameter.getStrings().get(0);
if (listParameter instanceof IFileParameter) {
tmpList.add(new CommandLineFile(new FileParameter(key, value)));
} else {
tmpList.add(new CommandLineParameter(new StringParameter(key, value)));
}
}
extractedParameterValues.add(tmpList);
}
use of com.genericworkflownodes.knime.parameter.ListParameter in project GenericKnimeNodes by genericworkflownodes.
the class DockerCommandGenerator method extractParamterValues.
private List<List<? extends CommandLineElement>> extractParamterValues(CLIElement cliElement, List<CommandLineElement> dockerCommands, Map<String, String> hostDockerMap) throws IOException {
List<List<? extends CommandLineElement>> extractedParameterValues = new ArrayList<List<? extends CommandLineElement>>();
for (CLIMapping cliMapping : cliElement.getMapping()) {
if (nodeConfig.getParameterKeys().contains(cliMapping.getReferenceName())) {
Parameter<?> p = nodeConfig.getParameter(cliMapping.getReferenceName());
if (!p.isNull()) {
if (p instanceof ListParameter) {
ListParameter lp = (ListParameter) p;
if (lp.getStrings().size() > 0) {
final List<CommandLineElement> tmp = new ArrayList<CommandLineElement>();
for (final String s : lp.getStrings()) {
tmp.add(new CommandLineFixedString(s));
}
extractedParameterValues.add(tmp);
}
} else if (p instanceof FileParameter) {
extractedParameterValues.add(handleFileParameter(((FileParameter) p).getValue(), dockerCommands, hostDockerMap));
} else if (p instanceof FileListParameter) {
List<String> fl = ((FileListParameter) p).getValue();
if (fl.size() > 0) {
for (String hostFile : fl) {
extractedParameterValues.add(handleFileParameter(hostFile, dockerCommands, hostDockerMap));
}
}
} else {
List<CommandLineElement> l = new ArrayList<CommandLineElement>();
l.add(new CommandLineParameter(p));
extractedParameterValues.add(l);
}
}
}
}
return extractedParameterValues;
}
Aggregations