use of org.knime.core.data.ExtensibleUtilityFactory in project knime-core by knime.
the class PreferredRendererPreferencePage method createFieldEditors.
/**
* {@inheritDoc}
*/
@Override
protected void createFieldEditors() {
Map<String, List<ExtensibleUtilityFactory>> groupedUtilityFactories = new HashMap<String, List<ExtensibleUtilityFactory>>();
// TODO retrieve the utility factories from the data type extension point once we have it
for (ExtensibleUtilityFactory fac : ExtensibleUtilityFactory.getAllFactories()) {
List<ExtensibleUtilityFactory> groupList = groupedUtilityFactories.get(fac.getGroupName());
if (groupList == null) {
groupList = new ArrayList<ExtensibleUtilityFactory>(16);
groupedUtilityFactories.put(fac.getGroupName(), groupList);
}
groupList.add(fac);
}
List<String> groupNames = new ArrayList<String>(groupedUtilityFactories.keySet());
Collections.sort(groupNames);
for (String group : groupNames) {
final Section sectionExpander = new Section(getFieldEditorParent(), ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT);
sectionExpander.setText(group);
final Composite section = new Composite(sectionExpander, SWT.NONE);
sectionExpander.setClient(section);
sectionExpander.addExpansionListener(new ExpansionAdapter() {
@Override
public void expansionStateChanged(final ExpansionEvent e) {
Composite comp = section;
while (!(comp instanceof ScrolledComposite)) {
comp = comp.getParent();
}
// this is to fix a bug in Eclipse, no scrollbar is shown when this is true
((ScrolledComposite) comp).setExpandVertical(false);
comp = section;
while (!(comp instanceof ScrolledComposite)) {
comp.setSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
comp.layout();
comp = comp.getParent();
}
}
});
List<ExtensibleUtilityFactory> utilityFactories = groupedUtilityFactories.get(group);
Collections.sort(utilityFactories, utilityFactoryComparator);
for (ExtensibleUtilityFactory utilFac : utilityFactories) {
List<DataValueRendererFactory> rendererFactories = new ArrayList<DataValueRendererFactory>(utilFac.getAvailableRenderers());
Collections.sort(rendererFactories, rendererFactoryComparator);
String[][] comboEntries = new String[utilFac.getAvailableRenderers().size()][2];
int i = 0;
for (DataValueRendererFactory rendFac : rendererFactories) {
comboEntries[i++] = new String[] { rendFac.getDescription(), rendFac.getId() };
}
ComboFieldEditor c = new ComboFieldEditor(utilFac.getPreferenceKey(), utilFac.getName(), comboEntries, section);
c.setEnabled(comboEntries.length > 1, section);
addField(c);
m_fieldEditors.put(utilFac.getPreferenceKey(), c);
}
// add a dummy control which occupies the second column so that the next expander is in a new row
new Label(getFieldEditorParent(), SWT.NONE);
}
DefaultScope.INSTANCE.getNode(FrameworkUtil.getBundle(DataValueRendererFactory.class).getSymbolicName()).addPreferenceChangeListener(this);
}
use of org.knime.core.data.ExtensibleUtilityFactory 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.ExtensibleUtilityFactory 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.ExtensibleUtilityFactory 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());
}
}
}
}
}
use of org.knime.core.data.ExtensibleUtilityFactory in project knime-core by knime.
the class TypeFilterPanelImpl method addDataValues.
/**
* Add data values to the selection.
*
* @param values The data values to add
*/
void addDataValues(final Iterable<Class<? extends DataValue>> values) {
for (Class<? extends DataValue> value : values) {
if (isIncludedByFilter(value)) {
if (value != null && !m_selections.containsKey(value.getName())) {
UtilityFactory utilityFor = DataType.getUtilityFor(value);
if (utilityFor instanceof ExtensibleUtilityFactory) {
ExtensibleUtilityFactory eu = (ExtensibleUtilityFactory) utilityFor;
String label = eu.getName();
String key = value.getName();
JCheckBox newCheckbox = addCheckBox(label, false);
m_selections.put(key, newCheckbox);
newCheckbox.setEnabled(isEnabled());
}
}
}
}
}
Aggregations