use of org.knime.core.node.workflow.FlowVariable.Type in project knime-core by knime.
the class JavaSnippetNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
m_snippet.setSettings(m_settings);
FlowVariableRepository flowVarRepo = new FlowVariableRepository(getAvailableInputFlowVariables());
BufferedDataTable output = m_snippet.execute(inData[0], flowVarRepo, exec);
for (FlowVariable var : flowVarRepo.getModified()) {
Type type = var.getType();
if (type.equals(Type.INTEGER)) {
pushFlowVariableInt(var.getName(), var.getIntValue());
} else if (type.equals(Type.DOUBLE)) {
pushFlowVariableDouble(var.getName(), var.getDoubleValue());
} else {
// case: type.equals(Type.STRING)
pushFlowVariableString(var.getName(), var.getStringValue());
}
}
return new BufferedDataTable[] { output };
}
use of org.knime.core.node.workflow.FlowVariable.Type 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 OutVarList getOutVarFields() {
OutVarList outVars = new OutVarList();
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) {
OutVar outVar = new OutVar();
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.setFlowVarType(type);
} else {
continue;
}
outVar.setJavaName((String) m_model.getValueAt(r, Column.JAVA_FIELD));
Object javaTypeObject = m_model.getValueAt(r, Column.JAVA_TYPE);
if (javaTypeObject instanceof Class) {
outVar.setJavaType((Class) javaTypeObject);
} else {
continue;
}
outVars.add(outVar);
}
}
return outVars;
}
use of org.knime.core.node.workflow.FlowVariable.Type 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.workflow.FlowVariable.Type in project knime-core by knime.
the class FlowObjectStack method getVariableDefinition.
private static final Pair<String, Type> getVariableDefinition(final String propKey) {
String varName;
Type varType;
if (propKey.startsWith("knime.constant.double.")) {
varName = propKey.substring("knime.constant.double.".length());
varType = Type.DOUBLE;
} else if (propKey.startsWith("knime.constant.integer.")) {
varName = propKey.substring("knime.constant.integer.".length());
varType = Type.INTEGER;
} else if (propKey.startsWith("knime.constant.string.")) {
varName = propKey.substring("knime.constant.string.".length());
varType = Type.STRING;
} else {
return null;
}
if (varName.length() == 0) {
LOGGER.warn("Ignoring constant defintion \"" + propKey + "\": " + "missing suffix, e.g. \"" + propKey + "somename\"");
return null;
}
return new Pair<String, Type>(varName, varType);
}
use of org.knime.core.node.workflow.FlowVariable.Type in project knime-core by knime.
the class FlowObjectStackView method update.
/**
* Updates the view to display the given stack.
* @param stack Whose values are to be displayed.
*/
public void update(final FlowObjectStack stack) {
final FontMetrics fontMetrics = m_table.getFontMetrics(m_table.getFont());
List<Object[]> values;
// relative width of each column - make important columns wider
int[] colRelativeWidth = new int[4];
for (int i = 0; i < colRelativeWidth.length; i++) {
colRelativeWidth[i] = SwingUtilities.computeStringWidth(fontMetrics, COLUMN_NAMES[i]);
}
if (stack != null) {
values = new ArrayList<Object[]>();
int loopCount = 0;
int counter = 0;
Set<Pair<String, Type>> duplicateElementsSet = new HashSet<Pair<String, Type>>();
for (FlowObject s : stack) {
Object[] obj = new Object[4];
obj[0] = Integer.valueOf(counter);
obj[1] = s.getOwner();
if (s instanceof FlowVariable) {
FlowVariable v = (FlowVariable) s;
final Pair<String, Type> key = new Pair<String, Type>(v.getName(), v.getType());
if (!duplicateElementsSet.add(key)) {
continue;
}
obj[2] = s;
obj[3] = v.getValueAsString();
} else if (s instanceof FlowLoopContext) {
duplicateElementsSet.clear();
if (!((FlowLoopContext) s).isInactiveScope()) {
obj[2] = "Loop (" + (loopCount++) + ")";
obj[3] = null;
} else {
obj[2] = "Inactive Loop Mark";
obj[3] = null;
}
} else if (s instanceof InnerFlowLoopExecuteMarker) {
obj[2] = "Loop-Execute";
obj[3] = null;
} else if (s instanceof FlowScopeContext) {
obj[2] = s.toString() + (((FlowScopeContext) s).isInactiveScope() ? " (inactive)" : "");
obj[3] = null;
} else {
obj[2] = "unknown:" + s.toString();
obj[3] = null;
}
values.add(obj);
for (int i = 0; i < colRelativeWidth.length; i++) {
String representation;
if (obj[i] instanceof FlowVariable) {
representation = "ICON" + ((FlowVariable) obj[i]).getName();
} else {
representation = Objects.toString(obj[i], "");
}
colRelativeWidth[i] = Math.max(colRelativeWidth[i], SwingUtilities.computeStringWidth(fontMetrics, representation));
}
}
} else {
values = Collections.emptyList();
}
final DefaultTableModel model = (DefaultTableModel) m_table.getModel();
model.setDataVector(values.toArray(new Object[values.size()][]), COLUMN_NAMES);
final TableColumnModel columnModel = m_table.getColumnModel();
for (int i = 0; i < colRelativeWidth.length; i++) {
columnModel.getColumn(i).setPreferredWidth(colRelativeWidth[i]);
}
m_table.setCellSelectionEnabled(true);
}
Aggregations