use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class FlowVariableList method onSelectionInVariableList.
private void onSelectionInVariableList(final Object selected) {
if (selected != null && selected instanceof FlowVariable) {
if (null == m_fields) {
return;
}
FlowVariable v = (FlowVariable) selected;
String enter = m_fields.getFieldReadStatement(v);
clearSelection();
if (null != m_snippet) {
m_snippet.replaceSelection(enter);
m_snippet.requestFocus();
}
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class InFieldsTableModel method getAllowedJavaTypes.
/**
* {@inheritDoc}
*/
@Override
public Object[] getAllowedJavaTypes(final int row) {
Object input = getValueAt(row, Column.COLUMN);
if (input instanceof DataColumnSpec) {
DataColumnSpec colSpec = (DataColumnSpec) input;
final Collection<DataCellToJavaConverterFactory<?, ?>> factories = ConverterUtil.getFactoriesForSourceType(colSpec.getType()).stream().filter(factory -> JavaSnippet.getBuildPathFromCache(factory.getIdentifier()) != null).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).collect(Collectors.toList());
final Object[] array = factories.toArray(new Object[factories.size()]);
return array;
} else if (input instanceof FlowVariable) {
FlowVariable flowVar = (FlowVariable) input;
TypeConverter typeConversion = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
return typeConversion.canProvideJavaTypes();
} else {
return new Class[0];
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class InFieldsTableModel method validateJavaTypeColumn.
/**
* Validate java type in the given row.
* @param row the row to check
* @return error message if error occurs
*/
private String validateJavaTypeColumn(final int row) {
Object value = this.getValueAt(row, Column.JAVA_TYPE);
if (null == value) {
return "Please select a value";
}
Object input = this.getValueAt(row, Column.COLUMN);
if (value instanceof DataCellToJavaConverterFactory) {
if (input instanceof FlowVariable) {
return "DataCell converters do not work for flow variables.";
} else if (input instanceof DataColumnSpec) {
final DataType dataType = ((DataColumnSpec) input).getType();
if (!dataType.getValueClasses().contains(((DataCellToJavaConverterFactory<?, ?>) value).getSourceType())) {
return "Input DataCell is incompatible with this java type.";
}
}
// otherwise user has to fix column/flowvar first.
} else if (value instanceof String) {
// converter factory id
final String id = (String) value;
if (input instanceof DataColumnSpec) {
final DataColumnSpec colSpec = (DataColumnSpec) input;
final Optional<DataCellToJavaConverterFactory<?, ?>> factory = ConverterUtil.getDataCellToJavaConverterFactory(id);
if (!factory.isPresent()) {
return "Converter with id " + id + " could not be found.";
}
if (!colSpec.getType().getValueClasses().contains(factory.get().getSourceType())) {
// But just in case it does, this will make sure we know.
return "Selected factory does not support the input type.";
}
return null;
} else if (input instanceof FlowVariable) {
return "DataCell converters do not work for flow variables.";
}
} else if (value instanceof Class) {
Class<?> javaType = (Class<?>) value;
if (input instanceof DataColumnSpec) {
DataColumnSpec colSpec = (DataColumnSpec) input;
final Collection<?> factories = ConverterUtil.getFactoriesForSourceType(colSpec.getType());
return factories.isEmpty() ? "The java type \"" + javaType.getSimpleName() + "\" is not supported." : null;
} else if (input instanceof FlowVariable) {
FlowVariable flowVar = (FlowVariable) input;
TypeConverter typeConversion = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
return typeConversion.canProvideJavaType(javaType) ? null : "The java type \"" + javaType.getSimpleName() + "\" is not supported.";
}
} else {
return "Cannot find type or converter " + value.toString();
}
return null;
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class AddOutFieldDialog method takeOverSettings.
/**
* Save settings in field m_result.
*/
@SuppressWarnings("rawtypes")
private JavaField takeOverSettings() {
if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
OutCol outCol = new OutCol();
boolean isReplacing = m_replace.isSelected();
outCol.setReplaceExisting(isReplacing);
String colName = isReplacing ? ((DataColumnSpec) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
outCol.setKnimeName(colName);
Set<String> taken = new HashSet<>();
for (int i = 0; i < m_model.getRowCount(); i++) {
taken.add((String) m_model.getValueAt(i, Column.JAVA_FIELD));
}
// collection is now done by a separate checkbox
// DataType dataType = (DataType)m_knimeType.getSelectedItem();
// DataType elemType =
// dataType.isCollectionType() ? dataType
// .getCollectionElementType() : dataType;
// boolean isCollection = dataType.isCollectionType();
DataType dataType = (DataType) m_knimeType.getSelectedItem();
if (m_isArray.isSelected()) {
dataType = ListCell.getCollectionType(dataType);
}
final Optional<JavaToDataCellConverterFactory<?>> selectedFactory = ConverterUtil.getPreferredFactoryForDestinationType(dataType);
if (!selectedFactory.isPresent()) {
// Default to string converter, which always exists. Should not happen, though.
outCol.setConverterFactory(ConverterUtil.getPreferredFactoryForDestinationType(StringCell.TYPE).get());
} else {
outCol.setConverterFactory(selectedFactory.get());
}
final String javaName = FieldsTableUtil.createUniqueJavaIdentifier(colName, taken, "out_");
outCol.setJavaName(javaName);
return outCol;
} else {
// flow variable
OutVar outVar = new OutVar();
boolean isReplacing = m_replace.isSelected();
outVar.setReplaceExisting(isReplacing);
String colName = isReplacing ? ((FlowVariable) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
outVar.setKnimeName(colName);
Set<String> taken = new HashSet<>();
for (int i = 0; i < m_model.getRowCount(); i++) {
taken.add((String) m_model.getValueAt(i, Column.JAVA_FIELD));
}
String javaName = FieldsTableUtil.createUniqueJavaIdentifier(colName, taken, "out_");
FlowVariable.Type type = (FlowVariable.Type) m_knimeType.getSelectedItem();
TypeProvider typeProvider = TypeProvider.getDefault();
Class javaType = typeProvider.getTypeConverter(type).getPreferredJavaType();
outVar.setFlowVarType(type);
outVar.setJavaName(javaName);
outVar.setJavaType(javaType);
return outVar;
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class InFieldsTable 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());
}
}
defaultVarTarget = !m_flowVars.isEmpty() ? m_flowVars.values().iterator().next() : null;
for (FlowVariable flowVar : m_flowVars.values()) {
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 {
m_model.addRow();
rowAdded = true;
}
if (rowAdded) {
firePropertyChange(PROP_FIELD_ADDED, m_model.getRowCount() - 1, m_model.getRowCount());
}
}
};
}
Aggregations