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()));
}
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()));
}
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();
}
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;
}
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());
}
}
}
}
}
Aggregations