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());
}
}
defaultColTarget = null;
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());
}
}
defaultVarTarget = null;
for (FlowVariable flowVar : m_flowVars.values()) {
// created.
if (OutFieldsTableModel.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 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;
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class AppendVariableToTableSettings method loadSettingsFrom.
/**
* Load settings.
*
* @param settings to load
* @param scopeVariableMap map of keys to scope variables
*/
public void loadSettingsFrom(final NodeSettingsRO settings, final Map<String, FlowVariable> scopeVariableMap) {
m_variablesOfInterest.clear();
m_includeAll = settings.getBoolean("all", false);
NodeSettingsRO sub = null;
try {
sub = settings.getNodeSettings("variables");
} catch (InvalidSettingsException e) {
// no op
}
if (sub != null) {
final Set<String> keySet = sub.keySet();
for (String key : keySet) {
NodeSettingsRO sub2;
try {
sub2 = sub.getNodeSettings(key);
} catch (InvalidSettingsException e) {
continue;
}
String name = sub2.getString("name", null);
String typeS = sub2.getString("type", null);
if (name == null || typeS == null) {
continue;
}
FlowVariable.Type type;
try {
type = FlowVariable.Type.valueOf(typeS);
} catch (IllegalArgumentException iae) {
continue;
}
m_variablesOfInterest.add(new Pair<String, FlowVariable.Type>(name, type));
}
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class VariableToTableSettings method loadSettingsFrom.
/**
* Load settings.
*
* @param settings to load
* @param scopeVariableMap nap of keys to scope variables
*/
public void loadSettingsFrom(final NodeSettingsRO settings, final Map<String, FlowVariable> scopeVariableMap) {
m_variablesOfInterest.clear();
m_includeAll = settings.getBoolean("all", false);
NodeSettingsRO sub = null;
try {
sub = settings.getNodeSettings("variables");
} catch (InvalidSettingsException e) {
// no op
}
if (sub != null) {
final Set<String> keySet = sub.keySet();
for (String key : keySet) {
NodeSettingsRO sub2;
try {
sub2 = sub.getNodeSettings(key);
} catch (InvalidSettingsException e) {
continue;
}
String name = sub2.getString("name", null);
String typeS = sub2.getString("type", null);
if (name == null || typeS == null) {
continue;
}
FlowVariable.Type type;
try {
type = FlowVariable.Type.valueOf(typeS);
} catch (IllegalArgumentException iae) {
continue;
}
m_variablesOfInterest.add(new Pair<String, FlowVariable.Type>(name, type));
}
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class AppendVariableToTableNodeModel method getAllVariables.
private List<Pair<String, FlowVariable.Type>> getAllVariables() {
Map<String, FlowVariable> currentVars = getAvailableFlowVariables();
List<Pair<String, FlowVariable.Type>> variables;
variables = new ArrayList<Pair<String, FlowVariable.Type>>();
for (FlowVariable v : currentVars.values()) {
variables.add(new Pair<String, FlowVariable.Type>(v.getName(), v.getType()));
}
return variables;
}
Aggregations