Search in sources :

Example 11 with JavaToDataCellConverterFactory

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;
}
Also used : Component(java.awt.Component) JavaToDataCellConverterFactory(org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory) DataCellToJavaConverterFactory(org.knime.core.data.convert.java.DataCellToJavaConverterFactory)

Example 12 with JavaToDataCellConverterFactory

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;
    }
}
Also used : OutCol(org.knime.base.node.jsnippet.util.field.OutCol) TypeProvider(org.knime.base.node.jsnippet.type.TypeProvider) OutVar(org.knime.base.node.jsnippet.util.field.OutVar) FieldType(org.knime.base.node.jsnippet.util.field.JavaField.FieldType) DataType(org.knime.core.data.DataType) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet) JavaToDataCellConverterFactory(org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 13 with JavaToDataCellConverterFactory

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;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) OutCol(org.knime.base.node.jsnippet.util.field.OutCol) DataType(org.knime.core.data.DataType) OutColList(org.knime.base.node.jsnippet.util.JavaFieldList.OutColList) JavaToDataCellConverterFactory(org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory)

Aggregations

JavaToDataCellConverterFactory (org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory)13 DataType (org.knime.core.data.DataType)6 FieldType (org.knime.base.node.jsnippet.util.field.JavaField.FieldType)4 DataCellToJavaConverterFactory (org.knime.core.data.convert.java.DataCellToJavaConverterFactory)4 FlowVariable (org.knime.core.node.workflow.FlowVariable)4 Optional (java.util.Optional)3 Test (org.junit.Test)3 OutCol (org.knime.base.node.jsnippet.util.field.OutCol)3 DataCell (org.knime.core.data.DataCell)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 Type (org.knime.core.node.workflow.FlowVariable.Type)3 Component (java.awt.Component)2 ArrayList (java.util.ArrayList)2 TypeProvider (org.knime.base.node.jsnippet.type.TypeProvider)2 TypeConverter (org.knime.base.node.jsnippet.type.flowvar.TypeConverter)2 OutColList (org.knime.base.node.jsnippet.util.JavaFieldList.OutColList)2 OutVar (org.knime.base.node.jsnippet.util.field.OutVar)2 BinaryObjectDataCell (org.knime.core.data.blob.BinaryObjectDataCell)2 ListCell (org.knime.core.data.collection.ListCell)2 ArrayToCollectionConverterFactory (org.knime.core.data.convert.datacell.ArrayToCollectionConverterFactory)2