use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class VariableLoopEndNodeModel method getCompatibleDataCell.
/**
* Creates and returns an instance of <code>DataCell</code>. The cell
* is of a compatible type according to the type of the given flow var
* and the value of the cell is equal to the value of the flow var.
*
* @param var The flow variable to create a data cell for (with compatible
* type and equal value).
* @return an instance of <code>DataCell</code> with compatible type to the
* given flow var and equal value.
* @throws InvalidSettingsException If given flow var is of any
* unsupported type.
*/
private static DataCell getCompatibleDataCell(final FlowVariable var) throws InvalidSettingsException {
DataCell cell;
FlowVariable.Type flowType = var.getType();
switch(flowType) {
case DOUBLE:
cell = new DoubleCell(var.getDoubleValue());
break;
case INTEGER:
cell = new IntCell(var.getIntValue());
break;
case STRING:
cell = new StringCell(var.getStringValue());
break;
default:
throw new InvalidSettingsException("Unsupported variable type: " + flowType);
}
return cell;
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class VariableLoopEndNodeModel method createDataTableSpec.
/**
* Creates and returns a new instance of <code>DataTableSpec</code>. The
* spec consists of one column for each specified and available flow
* variable. If any specified variable is not available an exception will
* be thrown.
* @return A new instance of <code>DataTableSpec</code>. The spec consists
* of one column for each specified and available flow variable.
* @throws InvalidSettingsException If any specified flow variable is not
* available.
*/
private DataTableSpec createDataTableSpec() throws InvalidSettingsException {
// get available flow vars and selected vars
Map<String, FlowVariable> availableFlowVars = getAvailableFlowVariables();
// for now take all variable names
String[] flowVarNames = m_selection.applyTo(availableFlowVars).getIncludes();
DataColumnSpec[] colSpecs = new DataColumnSpec[0];
// create for each specified flow variable a column spec, if available
if (flowVarNames != null && flowVarNames.length > 0) {
colSpecs = new DataColumnSpec[flowVarNames.length];
for (int i = 0; i < flowVarNames.length; i++) {
String varName = flowVarNames[i];
FlowVariable var = availableFlowVars.get(varName);
// if flow var is available create col spec for var type
if (var != null) {
colSpecs[i] = new DataColumnSpecCreator(varName, getCompatibleDataType(var.getType())).createSpec();
// if specified flow var is not available fail
} else {
throw new InvalidSettingsException("Specified flow variable " + varName + " is not available!");
}
}
}
return new DataTableSpec(colSpecs);
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class VirtualSubNodeInputNodeModel method pushFlowVariables.
/**
* @throws Exception
*/
private void pushFlowVariables() throws InvalidSettingsException {
String prefix = m_configuration.getFlowVariablePrefix() == null ? "" : m_configuration.getFlowVariablePrefix();
FlowVariableFilterConfiguration filterConfiguration = m_configuration.getFilterConfiguration();
Map<String, FlowVariable> availableVariables = getSubNodeContainerFlowObjectStack().getAvailableFlowVariables(Type.values());
FilterResult filtered = filterConfiguration.applyTo(availableVariables);
for (String include : filtered.getIncludes()) {
FlowVariable f = availableVariables.get(include);
switch(f.getScope()) {
case Global:
// ignore global flow vars
continue;
case Flow:
case Local:
default:
}
final String name = prefix + f.getName();
Node.invokePushFlowVariable(this, f.withNewName(name));
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class FlowVariableTableCellRenderer method getTableCellRendererComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof FlowVariable) {
FlowVariable v = (FlowVariable) value;
Icon icon;
setText(v.getName());
String curValue;
switch(v.getType()) {
case DOUBLE:
icon = FlowVariableListCellRenderer.FLOW_VAR_DOUBLE_ICON;
curValue = Double.toString(v.getDoubleValue());
break;
case INTEGER:
icon = FlowVariableListCellRenderer.FLOW_VAR_INT_ICON;
curValue = Integer.toString(v.getIntValue());
break;
case STRING:
icon = FlowVariableListCellRenderer.FLOW_VAR_STRING_ICON;
curValue = v.getStringValue();
break;
default:
icon = DataValue.UTILITY.getIcon();
curValue = v.toString();
}
setIcon(icon);
StringBuilder b = new StringBuilder(v.getName());
b.append(" (");
if (v.getName().startsWith("knime.")) {
// constant
b.append("constant: ");
} else {
b.append("current value: ");
}
b.append(curValue);
b.append(")");
setToolTipText(b.toString());
} else {
setIcon(null);
setToolTipText(null);
}
return c;
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class FlowVariableListCellRenderer method getListCellRendererComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
FlowVariable flowVariable = null;
if (value instanceof FlowVariable) {
flowVariable = (FlowVariable) value;
} else if (value instanceof FlowVariableCell) {
// Added for bug 4601 to display missing flow variables
FlowVariableCell flowVariableCell = (FlowVariableCell) value;
if (flowVariableCell.isValid()) {
// Display as normal flow variable
flowVariable = flowVariableCell.getFlowVariable();
} else {
// Display missing variable by known name and with missing icon and red border
setText(flowVariableCell.getName());
setIcon(FLOW_VAR_INVALID_ICON);
setToolTipText(null);
setBorder(BorderFactory.createLineBorder(Color.red));
}
} else {
// Value is neither flow variable nor flow variable cell, do nothing
setToolTipText(null);
}
// If flow variable was found either directly as value or inside flow variable cell
if (flowVariable != null) {
FlowVariable v = flowVariable;
Icon icon;
setText(v.getName());
String curValue;
switch(v.getType()) {
case DOUBLE:
icon = FLOW_VAR_DOUBLE_ICON;
curValue = Double.toString(v.getDoubleValue());
break;
case INTEGER:
icon = FLOW_VAR_INT_ICON;
curValue = Integer.toString(v.getIntValue());
break;
case STRING:
icon = FLOW_VAR_STRING_ICON;
curValue = v.getStringValue();
break;
default:
icon = DataValue.UTILITY.getIcon();
curValue = v.toString();
}
setIcon(icon);
StringBuilder b = new StringBuilder(v.getName());
b.append(" (");
if (v.getName().startsWith("knime.")) {
// constant
b.append("constant: ");
} else {
b.append("current value: ");
}
b.append(curValue);
b.append(")");
setToolTipText(b.toString());
}
return c;
}
Aggregations