Search in sources :

Example 1 with UtilityFactory

use of org.knime.core.data.DataValue.UtilityFactory in project knime-core by knime.

the class ExtensibleUtilityFactoryTest method testRegisteredRenderers.

/**
 * Tests basic functionality of the extension point.
 */
@Test
public void testRegisteredRenderers() {
    ExtensibleUtilityFactory utilityFactory = TestDataValue.UTILITY;
    assertThat("Wrong utility factory retrieved via data type", DataType.getUtilityFor(TestDataValue.class), is((UtilityFactory) utilityFactory));
    Collection<DataValueRendererFactory> availableRenderers = utilityFactory.getAvailableRenderers();
    assertThat("Wrong number of available renderers", availableRenderers.size(), is(2));
    assertTrue("TestValueRenderer not found in available renderers", availableRenderers.contains(new TestValueRenderer.Factory()));
    assertTrue("StringValueRenderer not found in available renderers", availableRenderers.contains(new StringValueRenderer.Factory()));
    assertThat("Wrong default renderer", new TestValueRenderer.Factory(), is(utilityFactory.getDefaultRenderer()));
    assertThat("Unexpected preference key", ExtensibleUtilityFactory.getPreferenceKey(TestDataValue.class), is(utilityFactory.getPreferenceKey()));
}
Also used : ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) Test(org.junit.Test)

Example 2 with UtilityFactory

use of org.knime.core.data.DataValue.UtilityFactory in project knime-core by knime.

the class ExtensibleUtilityFactoryTest method testPreferredRenderer.

/**
 * Checks if the preferred renderer is correctly read from the preferences.
 */
@Test
public void testPreferredRenderer() {
    ExtensibleUtilityFactory utilityFactory = TestDataValue.UTILITY;
    IEclipsePreferences corePrefs = InstanceScope.INSTANCE.getNode(FrameworkUtil.getBundle(DataValueRendererFactory.class).getSymbolicName());
    DataValueRendererFactory rendererFactory = new TestValueRenderer.Factory();
    corePrefs.put(ExtensibleUtilityFactory.getPreferenceKey(TestDataValue.class), rendererFactory.getId());
    assertThat("Unexpected preferred renderer", utilityFactory.getPreferredRenderer(), is(rendererFactory));
    rendererFactory = new StringValueRenderer.Factory();
    corePrefs.put(ExtensibleUtilityFactory.getPreferenceKey(TestDataValue.class), rendererFactory.getId());
    assertThat("Unexpected preferred renderer after preference change", utilityFactory.getPreferredRenderer(), is(rendererFactory));
    DataValueRendererFactory invalidRendererFactory = new MultiLineStringValueRenderer.Factory();
    corePrefs.put(ExtensibleUtilityFactory.getPreferenceKey(TestDataValue.class), invalidRendererFactory.getId());
    assertThat("Unexpected preferred renderer after trying to set invalid preferred renderer", utilityFactory.getPreferredRenderer(), is(IsNull.nullValue()));
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) Test(org.junit.Test)

Example 3 with UtilityFactory

use of org.knime.core.data.DataValue.UtilityFactory in project knime-core by knime.

the class DataType method getIcon.

/**
 * Gets and returns an icon from the {@link UtilityFactory} representing
 * this type. This is used in table headers and lists, for instance.
 *
 * @return an icon for this type
 */
public Icon getIcon() {
    for (Class<? extends DataValue> cl : m_valueClasses) {
        UtilityFactory fac = getUtilityFor(cl);
        Icon icon = fac.getIcon();
        if (icon != null) {
            return icon;
        }
    }
    assert false : "Couldn't find proper icon.";
    return DataValue.UTILITY.getIcon();
}
Also used : UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) Icon(javax.swing.Icon)

Example 4 with UtilityFactory

use of org.knime.core.data.DataValue.UtilityFactory in project knime-core by knime.

the class DataType method getComparator.

/**
 * A comparator for {@link org.knime.core.data.DataCell} objects of this
 * type. Will return the native comparator (if provided), or the first
 * comparator of the value classes found. If no comparator is available the
 * comparator of the <code>String</code> representation will be returned.
 * @return a comparator for cells of this type
 */
public DataValueComparator getComparator() {
    for (Class<? extends DataValue> cl : m_valueClasses) {
        UtilityFactory fac = getUtilityFor(cl);
        DataValueComparator comparator = fac.getComparator();
        if (comparator != null) {
            return comparator;
        }
    }
    return FALLBACK_COMP;
}
Also used : UtilityFactory(org.knime.core.data.DataValue.UtilityFactory)

Example 5 with UtilityFactory

use of org.knime.core.data.DataValue.UtilityFactory in project knime-core by knime.

the class TypeFilterPanelImpl method addDataColumns.

/**
 * Add columns to selection.
 *
 * @param columns The columns contained in the current data table.
 */
void addDataColumns(final Iterable<DataColumnSpec> columns) {
    for (DataColumnSpec column : columns) {
        if (m_filter == null || m_filter.include(column)) {
            Class<? extends DataValue> prefValueClass = column.getType().getPreferredValueClass();
            if (!m_selections.containsKey(prefValueClass.getName())) {
                UtilityFactory utilityFor = DataType.getUtilityFor(prefValueClass);
                if (utilityFor instanceof ExtensibleUtilityFactory) {
                    ExtensibleUtilityFactory eu = (ExtensibleUtilityFactory) utilityFor;
                    String label = eu.getName();
                    String key = prefValueClass.getName();
                    JCheckBox newCheckbox = addCheckBox(label, false);
                    m_selections.put(key, newCheckbox);
                    newCheckbox.setEnabled(isEnabled());
                }
            }
        }
    }
}
Also used : UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) JCheckBox(javax.swing.JCheckBox) DataColumnSpec(org.knime.core.data.DataColumnSpec) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory)

Aggregations

UtilityFactory (org.knime.core.data.DataValue.UtilityFactory)11 ExtensibleUtilityFactory (org.knime.core.data.ExtensibleUtilityFactory)5 Test (org.junit.Test)3 Icon (javax.swing.Icon)2 JCheckBox (javax.swing.JCheckBox)2 CollectionDataValue (org.knime.core.data.collection.CollectionDataValue)2 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataValue (org.knime.core.data.DataValue)1 DataValueRendererFactory (org.knime.core.data.renderer.DataValueRendererFactory)1 DataValueRendererFamily (org.knime.core.data.renderer.DataValueRendererFamily)1 DefaultDataValueRenderer (org.knime.core.data.renderer.DefaultDataValueRenderer)1 DefaultDataValueRendererFamily (org.knime.core.data.renderer.DefaultDataValueRendererFamily)1 SetOfRendererFamilies (org.knime.core.data.renderer.SetOfRendererFamilies)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1