Search in sources :

Example 1 with ExtensibleUtilityFactory

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);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) Section(org.eclipse.ui.forms.widgets.Section) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ArrayList(java.util.ArrayList) List(java.util.List) DataValueRendererFactory(org.knime.core.data.renderer.DataValueRendererFactory) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent)

Example 2 with ExtensibleUtilityFactory

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()));
}
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 3 with ExtensibleUtilityFactory

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()));
}
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 4 with ExtensibleUtilityFactory

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

Example 5 with ExtensibleUtilityFactory

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());
                }
            }
        }
    }
}
Also used : UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) JCheckBox(javax.swing.JCheckBox) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory)

Aggregations

ExtensibleUtilityFactory (org.knime.core.data.ExtensibleUtilityFactory)7 UtilityFactory (org.knime.core.data.DataValue.UtilityFactory)5 Test (org.junit.Test)3 JCheckBox (javax.swing.JCheckBox)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 ComboFieldEditor (org.eclipse.jface.preference.ComboFieldEditor)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 Font (org.eclipse.swt.graphics.Font)1 Composite (org.eclipse.swt.widgets.Composite)1 Display (org.eclipse.swt.widgets.Display)1 Label (org.eclipse.swt.widgets.Label)1 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)1 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)1 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)1 Section (org.eclipse.ui.forms.widgets.Section)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1