use of org.knime.base.node.jsnippet.type.TypeProvider in project knime-core by knime.
the class AddOutFieldDialog method initKnimeTypeComboBox.
/**
* Initialize the selection list for the knime type.
*/
private void initKnimeTypeComboBox() {
m_knimeType.removeAllItems();
if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
for (final DataType type : ConverterUtil.getAllDestinationDataTypes()) {
m_knimeType.addItem(type);
}
m_knimeType.setRenderer(new DataTypeListCellRenderer());
} else {
TypeProvider typeProvider = TypeProvider.getDefault();
for (FlowVariable.Type type : typeProvider.getTypes()) {
m_knimeType.addItem(type);
}
m_knimeType.setRenderer(new TypeListCellRender());
}
// string is the default value
m_knimeType.setSelectedItem(StringCell.TYPE);
}
use of org.knime.base.node.jsnippet.type.TypeProvider 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;
}
}
Aggregations