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 OutVar 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.getFlowVarType(), r, Column.DATA_TYPE);
if (!m_flowVarsOnly) {
m_model.setValueAt(false, r, Column.IS_COLLECTION);
}
m_model.setValueAt(outVar.getJavaName(), r, Column.JAVA_FIELD);
m_model.setValueAt(outVar.getJavaType(), r, Column.JAVA_TYPE);
return true;
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class FlowVariableRepository method getValueOfType.
/**
* Get value of a flow variable. The type of the returned object is equal
* to the given className.
* @param name the name of the flow variable
* @param className the type of the returned object
* @return the value of the flow variable
*/
@SuppressWarnings("rawtypes")
public Object getValueOfType(final String name, final Class className) {
FlowVariable flowVar = getFlowVariable(name);
if (null == flowVar) {
throw new FlowVariableException("The flow variable with name \"" + name + "\" does not exist.");
}
TypeConverter converter = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
return converter.getValue(flowVar, className);
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class FlowVariableRepository method isOfType.
/**
* Returns true when getValueOfType(String, Class) does not throw
* an TypeException when called with the given flow variable and the given
* class name.
* @param name the name of the flow variable
* @param className the type
* @return true when flow variable is of type.
*/
@SuppressWarnings("rawtypes")
public boolean isOfType(final String name, final Class className) {
FlowVariable flowVar = getFlowVariable(name);
if (null == flowVar) {
throw new FlowVariableException("The flow variable with name \"" + name + "\" does not exist.");
}
TypeConverter converter = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
return converter.canProvideJavaType(className);
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class StringManipulationNodeDialog method createStringManipulationPanel.
/**
* @return the controls for the string manipulation node
* @since 3.3
*/
public Component createStringManipulationPanel() {
m_snippetPanel = new JSnippetPanel(StringManipulatorProvider.getDefault(), createCompletionProvider(), !m_isOnlyVariables);
m_newNameField = new JTextField(10);
String radioButtonName;
String radioButtonToolTip;
radioButtonName = "Append " + WordUtils.capitalize(m_columnOrVariable) + ": ";
radioButtonToolTip = "Appends a new " + m_columnOrVariable + " to the input with a given name.";
m_appendRadio = new JRadioButton(radioButtonName);
m_appendRadio.setToolTipText(radioButtonToolTip);
radioButtonName = "Replace " + WordUtils.capitalize(m_columnOrVariable) + ": ";
if (m_isOnlyVariables) {
radioButtonToolTip = "Replaces the " + m_columnOrVariable + " if the type stays the same.";
} else {
radioButtonToolTip = "Replaces the " + m_columnOrVariable + " and changes the " + m_columnOrVariable + " type accordingly.";
}
m_replaceRadio = new JRadioButton(radioButtonName);
m_replaceRadio.setToolTipText(radioButtonToolTip);
if (m_isOnlyVariables) {
// show all variables
m_replaceVariableCombo = new JComboBox<FlowVariable>(new DefaultComboBoxModel<FlowVariable>());
m_replaceVariableCombo.setRenderer(new FlowVariableListCellRenderer());
} else {
// show all columns
m_replaceColumnCombo = new ColumnSelectionPanel((Border) null, DataValue.class);
m_replaceColumnCombo.setRequired(false);
}
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(m_appendRadio);
buttonGroup.add(m_replaceRadio);
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (m_isOnlyVariables) {
m_replaceVariableCombo.setEnabled(m_replaceRadio.isSelected());
} else {
m_replaceColumnCombo.setEnabled(m_replaceRadio.isSelected());
}
m_newNameField.setEnabled(m_appendRadio.isSelected());
}
};
m_appendRadio.addActionListener(actionListener);
m_replaceRadio.addActionListener(actionListener);
m_compileOnCloseChecker = new JCheckBox("Syntax check on close");
m_compileOnCloseChecker.setToolTipText("Checks the syntax of the expression on close.");
m_insertMissingAsNullChecker = new JCheckBox("Insert Missing As Null");
m_insertMissingAsNullChecker.setToolTipText("If unselected, missing values in the input will produce a missing cell result");
return createPanel();
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class StringManipulationNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
DataTableSpec spec;
if (m_isOnlyVariables) {
spec = new DataTableSpec();
} else {
spec = (DataTableSpec) specs[0];
}
StringManipulationSettings s = new StringManipulationSettings();
s.loadSettingsInDialog(settings, spec);
String exp = s.getExpression();
String defaultNewName = "new " + m_columnOrVariable;
String newName = s.getColName();
boolean isReplace = s.isReplace();
boolean isTestCompilation = s.isTestCompilationOnDialogClose();
boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
m_newNameField.setText("");
final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
if (m_isOnlyVariables) {
DefaultComboBoxModel<FlowVariable> cmbModel = (DefaultComboBoxModel<FlowVariable>) m_replaceVariableCombo.getModel();
cmbModel.removeAllElements();
for (FlowVariable v : availableFlowVariables.values()) {
switch(v.getScope()) {
case Flow:
cmbModel.addElement(v);
break;
default:
}
}
if (availableFlowVariables.containsValue(newName)) {
m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
}
} else {
// will select newColName only if it is in the spec list
try {
m_replaceColumnCombo.update(spec, newName);
} catch (NotConfigurableException e1) {
NodeLogger.getLogger(getClass()).coding("Combo box throws exception although content is not required", e1);
}
}
m_currentSpec = spec;
// whether there are variables or columns available
// -- which of two depends on the customizer
boolean fieldsAvailable;
if (m_isOnlyVariables) {
fieldsAvailable = m_replaceVariableCombo.getItemCount() > 0;
} else {
fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
}
m_replaceRadio.setEnabled(fieldsAvailable);
if (isReplace && fieldsAvailable) {
m_replaceRadio.doClick();
} else {
m_appendRadio.doClick();
String newNameString = (newName != null ? newName : defaultNewName);
m_newNameField.setText(newNameString);
}
m_snippetPanel.update(exp, spec, availableFlowVariables);
m_compileOnCloseChecker.setSelected(isTestCompilation);
m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
Aggregations