Search in sources :

Example 1 with DataValueRendererFactory

use of org.knime.core.data.renderer.DataValueRendererFactory 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 DataValueRendererFactory

use of org.knime.core.data.renderer.DataValueRendererFactory in project knime-core by knime.

the class ExtensibleUtilityFactory method setDefaultRenderer.

/**
 * Sets the default renderer using the ID of its factory. The default renderer must never be <code>null</code> and
 * it must exist.
 *
 * @param rendererId the factory's ID name
 * @since 2.9
 */
public final void setDefaultRenderer(final String rendererId) {
    readRenderersFromExtensionPoint();
    if (rendererId == null) {
        throw new IllegalArgumentException("Default renderer ID must not be null");
    } else {
        DataValueRendererFactory matchedFactory = m_renderers.get(rendererId);
        if (matchedFactory != null) {
            CORE_DEFAULT_PREFS.put(getPreferenceKey(), rendererId);
            m_logger.debug("Setting " + rendererId + " as default renderer for " + m_valueClass.getName());
        } else {
            throw new IllegalArgumentException("Default renderer with ID '" + rendererId + "' does not exist");
        }
    }
}
Also used : DataValueRendererFactory(org.knime.core.data.renderer.DataValueRendererFactory)

Example 3 with DataValueRendererFactory

use of org.knime.core.data.renderer.DataValueRendererFactory in project knime-core by knime.

the class ExtensibleUtilityFactory method readRenderersFromExtensionPoint.

private void readRenderersFromExtensionPoint() {
    if (m_renderers != null) {
        return;
    }
    synchronized (m_logger) {
        if (m_renderers != null) {
            return;
        }
        Map<String, DataValueRendererFactory> renderers = new HashMap<String, DataValueRendererFactory>();
        IExtensionRegistry registry = Platform.getExtensionRegistry();
        IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
        assert point != null : "Invalid extension point id: " + EXT_POINT_ID;
        String defaultRendererId = null;
        for (IExtension ext : point.getExtensions()) {
            IConfigurationElement[] elements = ext.getConfigurationElements();
            for (IConfigurationElement valueClassElement : elements) {
                String valueClassName = valueClassElement.getAttribute("valueClass");
                if (!m_valueClass.getName().equals(valueClassName)) {
                    continue;
                }
                for (IConfigurationElement rendererClassElement : valueClassElement.getChildren()) {
                    boolean suggestAsDefault = Boolean.parseBoolean(rendererClassElement.getAttribute("suggestAsDefault"));
                    try {
                        DataValueRendererFactory rendererFactory = (DataValueRendererFactory) rendererClassElement.createExecutableExtension("rendererFactoryClass");
                        renderers.put(rendererFactory.getId(), rendererFactory);
                        if (suggestAsDefault || (defaultRendererId == null)) {
                            defaultRendererId = rendererFactory.getId();
                            CORE_DEFAULT_PREFS.put(getPreferenceKey(), defaultRendererId);
                        }
                    } catch (CoreException ex) {
                        m_logger.error("Could not load registered renderer factory " + rendererClassElement.getAttribute("rendererFactoryClass") + " for " + valueClassName + " from plug-in " + valueClassElement.getNamespaceIdentifier() + ": " + ex.getMessage(), ex);
                    }
                }
            }
        }
        m_renderers = renderers;
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) IExtension(org.eclipse.core.runtime.IExtension) DataValueRendererFactory(org.knime.core.data.renderer.DataValueRendererFactory) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 4 with DataValueRendererFactory

use of org.knime.core.data.renderer.DataValueRendererFactory in project knime-core by knime.

the class ExtensibleUtilityFactory method setPreferredRenderer.

/**
 * Sets the preferred renderer using the ID of its factory. Please think twice before using this method since the
 * preferred renderer should usually only be changed by the user via the preference page.
 *
 * @param rendererId the factory's ID name or <code>null</code> if the preferred renderer should be unset
 */
public final void setPreferredRenderer(final String rendererId) {
    readRenderersFromExtensionPoint();
    if (rendererId == null) {
        CORE_PREFS.remove(getPreferenceKey());
    } else {
        DataValueRendererFactory matchedFactory = m_renderers.get(rendererId);
        if (matchedFactory != null) {
            CORE_PREFS.put(getPreferenceKey(), rendererId);
            m_logger.debug("Setting " + rendererId + " as preferred renderer for " + m_valueClass.getName());
        } else {
            m_logger.warn("Preferred renderer " + rendererId + " for " + m_valueClass.getName() + " was not found");
        }
    }
}
Also used : DataValueRendererFactory(org.knime.core.data.renderer.DataValueRendererFactory)

Example 5 with DataValueRendererFactory

use of org.knime.core.data.renderer.DataValueRendererFactory in project knime-core by knime.

the class ExtensibleUtilityFactory method getRendererFamily.

/**
 * {@inheritDoc}
 */
@Override
protected final DataValueRendererFamily getRendererFamily(final DataColumnSpec spec) {
    readRenderersFromExtensionPoint();
    DataValueRenderer[] renderers = new DataValueRenderer[m_renderers.size()];
    int i = 0;
    readPreferredRendererFromPreferences();
    DataValueRendererFactory prefRenderer = getPreferredRenderer();
    DataValueRendererFactory defaultRenderer = getDefaultRenderer();
    if (prefRenderer != null) {
        renderers[i++] = prefRenderer.createRenderer(spec);
    } else if (defaultRenderer != null) {
        renderers[i++] = defaultRenderer.createRenderer(spec);
    }
    for (DataValueRendererFactory fac : m_renderers.values()) {
        if (fac.equals(prefRenderer) || ((prefRenderer == null) && fac.equals(defaultRenderer))) {
            continue;
        }
        renderers[i++] = fac.createRenderer(spec);
    }
    return new DefaultDataValueRendererFamily(renderers);
}
Also used : DataValueRendererFactory(org.knime.core.data.renderer.DataValueRendererFactory) DataValueRenderer(org.knime.core.data.renderer.DataValueRenderer) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) DefaultDataValueRendererFamily(org.knime.core.data.renderer.DefaultDataValueRendererFamily)

Aggregations

DataValueRendererFactory (org.knime.core.data.renderer.DataValueRendererFactory)8 HashMap (java.util.HashMap)2 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 ComboFieldEditor (org.eclipse.jface.preference.ComboFieldEditor)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 Composite (org.eclipse.swt.widgets.Composite)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 UtilityFactory (org.knime.core.data.DataValue.UtilityFactory)1