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