use of org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField in project knime-core by knime.
the class AddOutFieldDialog method takeOverSettings.
/**
* Save settings in field m_result.
*/
@SuppressWarnings("rawtypes")
private AbstractField takeOverSettings() {
if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
OutColumnField outCol = new OutColumnField();
boolean isReplacing = m_replace.isSelected();
outCol.setReplaceExisting(isReplacing);
String colName = isReplacing ? ((DataColumnSpec) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
outCol.setKnimeName(colName);
DataType elemType = (DataType) m_knimeType.getSelectedItem();
boolean isCollection = m_isArray.isSelected();
DataType dataType = isCollection ? ListCell.getCollectionType(elemType) : elemType;
TypeProvider typeProvider = TypeProvider.getDefault();
if (!typeProvider.getColumnTypes().contains(elemType)) {
elemType = new StringCell("").getType();
isCollection = false;
}
outCol.setKnimeType(dataType);
return outCol;
} else {
// flow variable
OutFlowVariableField outVar = m_defineDefaultValue ? new DefaultOutFlowVariableField() : new OutFlowVariableField();
boolean isReplacing = m_replace.isSelected();
outVar.setReplaceExisting(isReplacing);
String colName = isReplacing ? ((FlowVariable) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
outVar.setKnimeName(colName);
FlowVariable.Type type = (FlowVariable.Type) m_knimeType.getSelectedItem();
outVar.setKnimeType(type);
if (m_defineDefaultValue) {
DefaultOutFlowVariableField dFVar = (DefaultOutFlowVariableField) outVar;
switch(type) {
case INTEGER:
dFVar.setDefaultValue(Integer.parseInt(m_defaultValue.getText()));
break;
case DOUBLE:
dFVar.setDefaultValue(Double.parseDouble(m_defaultValue.getText()));
break;
default:
dFVar.setDefaultValue(m_defaultValue.getText());
}
}
return outVar;
}
}
use of org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField in project knime-core by knime.
the class OutFieldsTable method getOutVarFields.
/**
* Get the field definitions representing output flow variables.
*
* @return fields representing output flow variables
*/
public OutFlowVariableList getOutVarFields() {
OutFlowVariableList outVars = new OutFlowVariableList(m_defineDefaultValues);
for (int r = 0; r < m_model.getRowCount(); r++) {
if (!m_model.validateValues(r)) {
// there are errors in this row
continue;
}
Object fieldTypeValue = getFieldType(r);
if (null == fieldTypeValue) {
continue;
}
boolean isFlowVar = fieldTypeValue.equals(FieldType.FlowVariable);
if (isFlowVar) {
OutFlowVariableField outVar = m_defineDefaultValues ? new DefaultOutFlowVariableField() : new OutFlowVariableField();
outVar.setReplaceExisting((Boolean) m_model.getValueAt(r, Column.REPLACE_EXISTING));
Object colColValue = m_model.getValueAt(r, Column.COLUMN);
if (colColValue instanceof FlowVariable) {
FlowVariable flowVar = (FlowVariable) colColValue;
outVar.setKnimeName(flowVar.getName());
} else if (colColValue instanceof String) {
outVar.setKnimeName(colColValue.toString());
} else {
continue;
}
Object dataTypeValue = m_model.getValueAt(r, Column.DATA_TYPE);
if (dataTypeValue instanceof Type) {
Type type = (Type) dataTypeValue;
outVar.setKnimeType(type);
} else {
continue;
}
if (m_defineDefaultValues) {
DefaultOutFlowVariableField dOVar = (DefaultOutFlowVariableField) outVar;
Object defaultValue = m_model.getValueAt(r, Column.DEFAULT_VALUE);
switch((Type) dataTypeValue) {
case INTEGER:
int defInt = defaultValue instanceof String ? Integer.parseInt((String) defaultValue) : (Integer) defaultValue;
dOVar.setDefaultValue(defInt);
break;
case DOUBLE:
double defDouble = defaultValue instanceof String ? Double.parseDouble((String) defaultValue) : (Double) defaultValue;
dOVar.setDefaultValue(defDouble);
break;
default:
dOVar.setDefaultValue((String) defaultValue);
}
}
outVars.add(outVar);
}
}
return outVars;
}
use of org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField in project knime-core by knime.
the class OutFieldsTable method addRow.
/**
* Adds a row using the values of the given output variable.
*
* @param outVar the output variable definition
* @return true when the row was added successfully
*/
public boolean addRow(final OutFlowVariableField outVar) {
int r = m_model.getRowCount();
m_model.addRow();
m_model.setValueAt(outVar.getReplaceExisting(), r, Column.REPLACE_EXISTING);
if (!m_flowVarsOnly) {
m_model.setValueAt(FieldType.FlowVariable, r, Column.FIELD_TYPE);
}
String name = outVar.getKnimeName();
FlowVariable flowVar = m_flowVars.get(name);
Object value = null != flowVar ? flowVar : name;
m_model.setValueAt(value, r, Column.COLUMN);
m_model.setValueAt(outVar.getKnimeType(), r, Column.DATA_TYPE);
if (!m_flowVarsOnly) {
m_model.setValueAt(false, r, Column.IS_COLLECTION);
}
if (m_defineDefaultValues && outVar instanceof DefaultOutFlowVariableField) {
DefaultOutFlowVariableField doV = (DefaultOutFlowVariableField) outVar;
m_model.setValueAt(doV.getDefaultValue(), r, Column.DEFAULT_VALUE);
}
return true;
}
Aggregations