Search in sources :

Example 46 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class DataTypeRegistry method scanExtensionPointForSerializer.

private <T extends DataCell> Optional<DataCellSerializer<T>> scanExtensionPointForSerializer(final String cellClassName) {
    // not found => scan extension point
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    Optional<IConfigurationElement> o = Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).flatMap(cfe -> Stream.of(cfe.getChildren("serializer"))).filter(cfe -> cfe.getAttribute("cellClass").equals(cellClassName)).findFirst();
    if (o.isPresent()) {
        IConfigurationElement configElement = o.get();
        return createSerializer(configElement);
    } else {
        return Optional.empty();
    }
}
Also used : Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SerializerMethodLoader(org.knime.core.internal.SerializerMethodLoader) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) EclipseUtil(org.knime.core.util.EclipseUtil) ArrayList(java.util.ArrayList) ExecutionContext(org.knime.core.node.ExecutionContext) List(java.util.List) Stream(java.util.stream.Stream) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) GlobalClassCreator(org.knime.core.eclipseUtil.GlobalClassCreator) Collections(java.util.Collections) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 47 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class DataTypeRegistry method scanExtensionPointForAllSerializers.

private void scanExtensionPointForAllSerializers() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).flatMap(cfe -> Stream.of(cfe.getChildren("serializer"))).filter(cfe -> !m_cellClassMap.containsKey(cfe.getAttribute("cellClass"))).forEach(cfe -> createSerializer(cfe));
}
Also used : Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SerializerMethodLoader(org.knime.core.internal.SerializerMethodLoader) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) EclipseUtil(org.knime.core.util.EclipseUtil) ArrayList(java.util.ArrayList) ExecutionContext(org.knime.core.node.ExecutionContext) List(java.util.List) Stream(java.util.stream.Stream) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) GlobalClassCreator(org.knime.core.eclipseUtil.GlobalClassCreator) Collections(java.util.Collections) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 48 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class ExtensibleUtilityFactory method loadAllFactories.

/*
     * Load all extensible utility factories by traversing the renderer extension point. Not all factories may be
     * loaded if nobody has access the data type yet.
     * TODO This should be changed once we have an extension point for data types
     */
@SuppressWarnings("unchecked")
private static void loadAllFactories() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    assert point != null : "Invalid extension point id: " + EXT_POINT_ID;
    for (IExtension ext : point.getExtensions()) {
        IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement valueClassElement : elements) {
            String valueClassName = valueClassElement.getAttribute("valueClass");
            try {
                DataType.getUtilityFor((Class<? extends DataValue>) Class.forName(valueClassName));
            } catch (ClassNotFoundException ex) {
                NodeLogger.getLogger(ExtensibleUtilityFactory.class).coding("Could not find implementation for " + valueClassName, ex);
            }
        }
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 49 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class OpenInteractiveWebViewAction method getConfiguredWizardNodeView.

@SuppressWarnings({ "rawtypes", "unchecked" })
static AbstractWizardNodeView getConfiguredWizardNodeView(final ViewableModel model) {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor("org.knime.core.WizardNodeView");
    Class<?> viewClass = null;
    String classString = JSCorePlugin.getDefault().getPreferenceStore().getString(JSCorePlugin.P_VIEW_BROWSER);
    if (StringUtils.isNotEmpty(classString)) {
        // try loading selected view
        viewClass = getViewClassByReflection(classString, configurationElements);
        if (viewClass == null) {
            LOGGER.error("JS view set in preferences (" + classString + ") can't be loaded. Switching to default.");
        }
    }
    if (viewClass == null) {
        // try loading defaults
        viewClass = getViewClassByReflection(CHROMIUM_BROWSER, configurationElements);
        if (viewClass == null) {
            viewClass = getViewClassByReflection(CHROME_BROWSER, configurationElements);
            try {
                Method isChromePresentM = viewClass.getMethod("isChromePresent");
                boolean isChromePresent = (boolean) isChromePresentM.invoke(null);
                if (!isChromePresent) {
                    // no Chrome found on system, defaulting to SWT browser
                    viewClass = null;
                }
            } catch (Exception e) {
            /* do nothing */
            }
        }
    }
    if (viewClass != null) {
        try {
            Method isEnabledM = viewClass.getMethod("isEnabled");
            boolean isEnabled = (boolean) isEnabledM.invoke(null);
            if (!isEnabled) {
                LOGGER.error("JS view (" + classString + ") is not available. Falling back to internal SWT browser.");
                viewClass = null;
            }
        } catch (Exception e) {
        /*do nothing */
        }
    }
    if (viewClass != null) {
        try {
            Constructor<?> constructor = viewClass.getConstructor(ViewableModel.class);
            return (AbstractWizardNodeView) constructor.newInstance(model);
        } catch (Exception e) {
            LOGGER.error("JS view can not be initialized. Falling back to internal SWT browser.");
        }
    }
    return new WizardNodeView(model);
}
Also used : AbstractWizardNodeView(org.knime.core.node.wizard.AbstractWizardNodeView) Method(java.lang.reflect.Method) AbstractWizardNodeView(org.knime.core.node.wizard.AbstractWizardNodeView) WizardNodeView(org.knime.workbench.editor2.WizardNodeView) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 50 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class RepositoryManager method getExtensions.

/**
 * Returns the extensions for a given extension point.
 *
 * @param pointID The extension point ID
 *
 * @return The extensions
 */
private static IExtension[] getExtensions(final String pointID) {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(pointID);
    if (point == null) {
        throw new IllegalStateException("Invalid extension point : " + pointID);
    }
    return point.getExtensions();
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)55 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)50 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)33 CoreException (org.eclipse.core.runtime.CoreException)25 IExtension (org.eclipse.core.runtime.IExtension)20 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)11 Platform (org.eclipse.core.runtime.Platform)9 Map (java.util.Map)8 Optional (java.util.Optional)8 Stream (java.util.stream.Stream)8 NodeLogger (org.knime.core.node.NodeLogger)8 Collection (java.util.Collection)7 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 DataTableSpec (org.knime.core.data.DataTableSpec)5 GlobalClassCreator (org.knime.core.eclipseUtil.GlobalClassCreator)5 SerializerMethodLoader (org.knime.core.internal.SerializerMethodLoader)5 File (java.io.File)4 Collections (java.util.Collections)4