use of com.genericworkflownodes.knime.parameter.IntegerParameter in project GenericKnimeNodes by genericworkflownodes.
the class ParamHandler method handleIntType.
/**
* Convert the current element into a IntegerParameter.
*
* @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 handleIntType(final String paramName, final String paramValue, Attributes attributes) {
m_currentParameter = new IntegerParameter(paramName, paramValue);
// check for restrictions
String restrictions = attributes.getValue(ATTR_RESTRICTIONS);
if (restrictions != null) {
((IntegerParameter) m_currentParameter).setLowerBound(new IntegerRangeExtractor().getLowerBound(restrictions));
((IntegerParameter) m_currentParameter).setUpperBound(new IntegerRangeExtractor().getUpperBound(restrictions));
}
}
use of com.genericworkflownodes.knime.parameter.IntegerParameter in project GenericKnimeNodes by genericworkflownodes.
the class CTDConfigurationWriter method addIntegerParameterRestrictions.
private void addIntegerParameterRestrictions(Parameter<?> p, StringBuffer restriction) {
IntegerParameter ip = (IntegerParameter) p;
boolean lbSet = Integer.MIN_VALUE != ip.getLowerBound().doubleValue();
boolean ubSet = Integer.MAX_VALUE != ip.getUpperBound().doubleValue();
if (lbSet) {
restriction.append(String.format("%d", ip.getLowerBound()));
}
if (ubSet || lbSet) {
restriction.append(':');
}
if (ubSet) {
restriction.append(String.format("%d", ip.getUpperBound()));
}
}
use of com.genericworkflownodes.knime.parameter.IntegerParameter 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.IntegerParameter 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.IntegerParameter 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