use of org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory in project knime-core by knime.
the class ConverterFactoryDataTypeListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
// The super method will reset the icon if we call this method
// last. So we let super do its job first and then we take care
// that everything is properly set.
final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
assert c == this;
if (value instanceof JavaToDataCellConverterFactory<?>) {
final JavaToDataCellConverterFactory<?> factory = (JavaToDataCellConverterFactory<?>) value;
setText(factory.getName());
setIcon(factory.getDestinationType().getIcon());
} else if (value instanceof DataCellToJavaConverterFactory) {
final DataCellToJavaConverterFactory<?, ?> factory = (DataCellToJavaConverterFactory<?, ?>) value;
setText(factory.getName());
}
setToolTipText(getText());
return this;
}
use of org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory 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.data.convert.datacell.JavaToDataCellConverterFactory in project knime-core by knime.
the class OutFieldsTable method getOutColFields.
/**
* Get the field definitions representing output columns.
*
* @return fields representing output columns.
*/
public OutColList getOutColFields() {
OutColList outCols = new OutColList();
for (int r = 0; r < m_model.getRowCount(); r++) {
if (!m_model.validateValues(r)) {
// there are errors in this row
continue;
}
Object fieldTypeValue = getFieldType(r);
if (null == fieldTypeValue) {
continue;
}
boolean isColumn = fieldTypeValue.equals(FieldType.Column);
if (isColumn) {
OutCol outCol = new OutCol();
outCol.setReplaceExisting((Boolean) m_model.getValueAt(r, Column.REPLACE_EXISTING));
Object colColValue = m_model.getValueAt(r, Column.COLUMN);
if (colColValue instanceof DataColumnSpec) {
DataColumnSpec colSpec = (DataColumnSpec) colColValue;
outCol.setKnimeName(colSpec.getName());
} else if (colColValue instanceof String) {
outCol.setKnimeName(colColValue.toString());
} else {
continue;
}
final Object dataTypeValue = m_model.getValueAt(r, Column.DATA_TYPE);
if (!(dataTypeValue instanceof DataType)) {
continue;
}
outCol.setJavaName((String) m_model.getValueAt(r, Column.JAVA_FIELD));
Object javaTypeObject = m_model.getValueAt(r, Column.JAVA_TYPE);
if (javaTypeObject instanceof JavaToDataCellConverterFactory) {
outCol.setConverterFactory((JavaToDataCellConverterFactory) javaTypeObject);
} else {
continue;
}
outCols.add(outCol);
}
}
return outCols;
}
Aggregations