Search in sources :

Example 1 with DataCellFactory

use of org.knime.core.data.DataCellFactory in project knime-core by knime.

the class JavaToDataCellConverterRegistry method parseAnnotations.

private void parseAnnotations() {
    final Collection<DataType> availableDataTypes = DataTypeRegistry.getInstance().availableDataTypes();
    for (final DataType dataType : availableDataTypes) {
        final Optional<DataCellFactory> cellFactory = dataType.getCellFactory(null);
        if (cellFactory.isPresent()) {
            final Class<? extends DataCellFactory> cellFactoryClass = cellFactory.get().getClass();
            for (final Pair<Method, DataCellFactoryMethod> pair : ClassUtil.getMethodsWithAnnotation(cellFactoryClass, DataCellFactoryMethod.class)) {
                final Method method = pair.getFirst();
                try {
                    final JavaToDataCellConverterFactory<?> factory = new FactoryMethodToDataCellConverterFactory<>(cellFactoryClass, method, ClassUtil.ensureObjectType(method.getParameterTypes()[0]), dataType, pair.getSecond().name());
                    // Check name of factory
                    if (!validateFactoryName(factory)) {
                        LOGGER.warn("JavaToDataCellFactory name \"" + factory.getName() + "\" of factory with id \"" + factory.getIdentifier() + "\" does not follow naming convention (see DataCellFactoryMethod#name()).");
                        LOGGER.warn("Factory will not be registered.");
                        continue;
                    }
                    register(factory);
                    LOGGER.debug("Registered JavaToDataCellConverterFactory from DataCellFactoryMethod annotation for: " + method.getParameterTypes()[0].getName() + " to " + dataType.getName());
                } catch (IncompleteAnnotationException e) {
                    LOGGER.coding("Incomplete DataCellFactoryMethod annotation for " + cellFactoryClass.getName() + "." + method.getName() + ". Will not register.", e);
                } catch (NoSuchMethodException | SecurityException ex) {
                    LOGGER.error("Could not access default constructor or constructor with parameter 'ExecutionContext' of " + "class '" + cellFactoryClass.getName() + "'. Converter will not be registered.", ex);
                }
            }
        }
    }
}
Also used : DataCellFactoryMethod(org.knime.core.data.convert.DataCellFactoryMethod) DataCellFactory(org.knime.core.data.DataCellFactory) DataCellFactoryMethod(org.knime.core.data.convert.DataCellFactoryMethod) Method(java.lang.reflect.Method) DataType(org.knime.core.data.DataType) IncompleteAnnotationException(java.lang.annotation.IncompleteAnnotationException)

Example 2 with DataCellFactory

use of org.knime.core.data.DataCellFactory in project knime-core by knime.

the class NewColumnDialog method typeChanged.

private void typeChanged() {
    DataType type = (DataType) m_typeChooser.getSelectedItem();
    m_formatParameterChooser.removeAllItems();
    m_formatParameterLabel.setEnabled(false);
    m_formatParameterChooser.setEnabled(false);
    m_formatParameterLabel.setToolTipText(null);
    m_formatParameterChooser.setToolTipText(null);
    if (type != null) {
        DataCellFactory f = type.getCellFactory(null).orElse(null);
        if (f instanceof ConfigurableDataCellFactory) {
            ConfigurableDataCellFactory cfac = (ConfigurableDataCellFactory) f;
            for (String s : cfac.getPredefinedParameters()) {
                m_formatParameterChooser.addItem(s);
            }
            if (m_allColumns.size() > m_colIdx) {
                m_formatParameterChooser.setSelectedItem(m_allColumns.get(m_colIdx).getFormatParameter().orElse(null));
            } else {
                m_formatParameterChooser.setSelectedItem(null);
            }
            m_formatParameterLabel.setEnabled(true);
            m_formatParameterChooser.setEnabled(true);
            m_formatParameterLabel.setToolTipText(cfac.getParameterDescription());
            m_formatParameterChooser.setToolTipText(cfac.getParameterDescription());
        }
    }
    pack();
}
Also used : ConfigurableDataCellFactory(org.knime.core.data.ConfigurableDataCellFactory) DataCellFactory(org.knime.core.data.DataCellFactory) ConfigurableDataCellFactory(org.knime.core.data.ConfigurableDataCellFactory) DataType(org.knime.core.data.DataType) FromSimpleString(org.knime.core.data.DataCellFactory.FromSimpleString)

Example 3 with DataCellFactory

use of org.knime.core.data.DataCellFactory in project knime-core by knime.

the class ColPropertyDialog method configureParameterField.

private void configureParameterField() {
    m_optionalParameterField.removeAllItems();
    m_optionalParameterLabel.setEnabled(false);
    m_optionalParameterField.setEnabled(false);
    m_optionalParameterLabel.setToolTipText(null);
    m_optionalParameterField.setToolTipText(null);
    if (!m_skipColumn.isSelected()) {
        DataType selectedType = (DataType) m_typeChooser.getSelectedItem();
        if (selectedType != null) {
            DataCellFactory fac = selectedType.getCellFactory(null).orElseGet(null);
            if (fac instanceof ConfigurableDataCellFactory) {
                ConfigurableDataCellFactory cfac = (ConfigurableDataCellFactory) fac;
                m_optionalParameterLabel.setEnabled(true);
                m_optionalParameterField.setEnabled(true);
                for (String s : cfac.getPredefinedParameters()) {
                    m_optionalParameterField.addItem(s);
                }
                m_optionalParameterField.setSelectedItem(m_allColProps.get(m_colIdx).getFormatParameter().orElse(null));
                m_optionalParameterLabel.setToolTipText(cfac.getParameterDescription());
                m_optionalParameterField.setToolTipText(cfac.getParameterDescription());
                pack();
            }
        }
    }
}
Also used : ConfigurableDataCellFactory(org.knime.core.data.ConfigurableDataCellFactory) DataCellFactory(org.knime.core.data.DataCellFactory) ConfigurableDataCellFactory(org.knime.core.data.ConfigurableDataCellFactory) DataType(org.knime.core.data.DataType) FromSimpleString(org.knime.core.data.DataCellFactory.FromSimpleString)

Aggregations

DataCellFactory (org.knime.core.data.DataCellFactory)3 DataType (org.knime.core.data.DataType)3 ConfigurableDataCellFactory (org.knime.core.data.ConfigurableDataCellFactory)2 FromSimpleString (org.knime.core.data.DataCellFactory.FromSimpleString)2 IncompleteAnnotationException (java.lang.annotation.IncompleteAnnotationException)1 Method (java.lang.reflect.Method)1 DataCellFactoryMethod (org.knime.core.data.convert.DataCellFactoryMethod)1