use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class JSnippetFieldsController method getFieldReadStatement.
/**
* Get a statement to inserted in the document of a java snippet to read
* the given flow variable.
* @param v the flow variable to be read
* @return the statement
*/
@SuppressWarnings("rawtypes")
public String getFieldReadStatement(final FlowVariable v) {
FieldsTableModel model = (FieldsTableModel) m_inFieldsTable.getTable().getModel();
int index = -1;
for (int r = 0; r < model.getRowCount(); r++) {
Object value = model.getValueAt(r, Column.COLUMN);
if (value instanceof FlowVariable) {
FlowVariable foo = (FlowVariable) value;
if (foo.getName().equals(v.getName())) {
index = r;
break;
}
}
}
if (index >= 0) {
// return java field name
return (String) model.getValueAt(index, Column.JAVA_FIELD);
} else {
// try to add a row for the flow variable
boolean success = m_inFieldsTable.addRow(v);
if (success) {
TableModel tableModel = m_inFieldsTable.getTable().getModel();
m_inFieldsTable.firePropertyChange(InFieldsTable.PROP_FIELD_ADDED, tableModel.getRowCount() - 1, tableModel.getRowCount());
// return java field name
return (String) model.getValueAt(model.getRowCount() - 1, Column.JAVA_FIELD);
} else {
// return generic code
String name = v.getName();
FlowVariable.Type type = v.getType();
Class javaType = TypeProvider.getDefault().getTypeConverter(type).getPreferredJavaType();
return "getFlowVariable(\"" + name + "\", " + Type.getIdentifierFor(javaType) + ")";
}
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class OutFieldsTable method createAddButtonListener.
/**
* {@inheritDoc}
*/
@Override
protected ActionListener createAddButtonListener() {
return new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
DataColumnSpec defaultColTarget = null;
if (null != m_spec) {
Set<String> cols = new HashSet<>();
for (int r = 0; r < m_model.getRowCount(); r++) {
Object value = m_model.getValueAt(r, Column.COLUMN);
if (value instanceof DataColumnSpec) {
cols.add(((DataColumnSpec) value).getName());
}
}
for (DataColumnSpec colSpec : m_spec) {
if (null == defaultColTarget) {
defaultColTarget = colSpec;
}
if (!cols.contains(colSpec.getName())) {
// Add a row and fill it
boolean rowAdded = addRow(colSpec);
if (rowAdded) {
firePropertyChange(PROP_FIELD_ADDED, m_model.getRowCount() - 1, m_model.getRowCount());
}
return;
}
}
}
FlowVariable defaultVarTarget = null;
if (null != m_flowVars) {
Set<String> flowVars = new HashSet<>();
for (int r = 0; r < m_model.getRowCount(); r++) {
Object value = m_model.getValueAt(r, Column.COLUMN);
if (value instanceof FlowVariable) {
flowVars.add(((FlowVariable) value).getName());
}
}
for (FlowVariable flowVar : m_flowVars.values()) {
// created.
if (FieldsTableUtil.verifyNameOfFlowVariable(flowVar.getName())) {
if (null == defaultVarTarget) {
defaultVarTarget = flowVar;
}
if (!flowVars.contains(flowVar.getName())) {
// Add a row and fill it
boolean rowAdded = addRow(flowVar);
if (rowAdded) {
firePropertyChange(PROP_FIELD_ADDED, m_model.getRowCount() - 1, m_model.getRowCount());
}
return;
}
}
}
}
boolean rowAdded = false;
if (null != defaultColTarget) {
rowAdded = addRow(defaultColTarget);
} else if (null != defaultVarTarget) {
rowAdded = addRow(defaultVarTarget);
} else {
rowAdded = addRow("var", Type.STRING);
}
if (rowAdded) {
firePropertyChange(PROP_FIELD_ADDED, m_model.getRowCount() - 1, m_model.getRowCount());
}
}
};
}
use of org.knime.core.node.workflow.FlowVariable 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;
}
Aggregations