Search in sources :

Example 41 with IExtensionRegistry

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

the class PortTypeRegistry method scanExtensionPointForObjectSerializer.

private <T extends PortObject> Optional<PortObjectSerializer<T>> scanExtensionPointForObjectSerializer(final String objectClassName) {
    // 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())).filter(cfe -> cfe.getAttribute("objectClass").equals(objectClassName)).findFirst();
    if (o.isPresent()) {
        IConfigurationElement configElement = o.get();
        return createObjectSerializer(configElement);
    } else {
        return Optional.empty();
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) 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) PortObjectSpecSerializer(org.knime.core.node.port.PortObjectSpec.PortObjectSpecSerializer) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) PortObjectSerializer(org.knime.core.node.port.PortObject.PortObjectSerializer) 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) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 42 with IExtensionRegistry

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

the class DatabaseUtilityRegistry method loadUtilities.

/**
 */
private void loadUtilities() {
    final IExtensionRegistry registry = Platform.getExtensionRegistry();
    final IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    assert point != null : "Invalid extension point id: " + EXT_POINT_ID;
    for (IExtension ext : point.getExtensions()) {
        final IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement utilityElement : elements) {
            try {
                final DatabaseUtility utility = (DatabaseUtility) utilityElement.createExecutableExtension("class");
                addUtility(utility);
            } catch (CoreException ex) {
                NodeLogger.getLogger(DatabaseUtilityRegistry.class).error("Could not create registered database utility " + utilityElement.getAttribute("class") + " from plug-in " + utilityElement.getNamespaceIdentifier() + ": " + ex.getMessage(), ex);
            }
        }
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 43 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project eclipse.platform.swt by eclipse.

the class LauncherPlugin method getLaunchItemTree.

/**
 * Constructs a list of available programs from registered extensions.
 *
 * @return an ItemTreeNode representing the root of a tree of items (the root is not to be displayed)
 */
public static ItemTreeNode getLaunchItemTree() {
    ItemTreeNode categoryTree = new ItemTreeNode(new ItemDescriptor("<<Root>>", "<<Root>>", null, null, null, null, null, null));
    // get the platform's public plugin registry
    IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
    // retrieve all configuration elements registered at our launchItems extension-point
    IConfigurationElement[] configurationElements = extensionRegistry.getConfigurationElementsFor(LAUNCH_ITEMS_POINT_ID);
    if (configurationElements == null || configurationElements.length == 0) {
        logError(getResourceString("error.CouldNotFindRegisteredExtensions"), null);
        return categoryTree;
    }
    /* Collect all launch categories -- coalesce those with same ID */
    HashMap<String, ItemTreeNode> idMap = new HashMap<>();
    for (IConfigurationElement ce : configurationElements) {
        final String ceName = ce.getName();
        final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);
        if (idMap.containsKey(attribId))
            continue;
        if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
            final String attribName = getItemName(ce);
            ItemDescriptor theDescriptor = new ItemDescriptor(attribId, attribName, getItemDescription(ce), null, null, null, null, ce);
            idMap.put(attribId, new ItemTreeNode(theDescriptor));
        }
    }
    /* Generate launch category hierarchy */
    // used to prevent duplicates from being entered into the tree
    Set<String> tempIdSet = new HashSet<>();
    for (IConfigurationElement ce : configurationElements) {
        final String ceName = ce.getName();
        final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);
        if (tempIdSet.contains(attribId))
            continue;
        if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
            final ItemTreeNode theNode = idMap.get(attribId);
            addItemByCategory(ce, categoryTree, theNode, idMap);
            tempIdSet.add(attribId);
        }
    }
    /* Generate program tree */
    for (IConfigurationElement ce : configurationElements) {
        final String ceName = ce.getName();
        final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);
        if (idMap.containsKey(attribId))
            continue;
        if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
        // ignore
        } else if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_ITEM)) {
            final String enabled = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ENABLED, LAUNCH_ITEMS_XML_VALUE_TRUE);
            if (enabled.equalsIgnoreCase(LAUNCH_ITEMS_XML_VALUE_FALSE))
                continue;
            ItemDescriptor theDescriptor = createItemDescriptor(ce, attribId);
            if (theDescriptor != null) {
                final ItemTreeNode theNode = new ItemTreeNode(theDescriptor);
                addItemByCategory(ce, categoryTree, theNode, idMap);
                idMap.put(attribId, theNode);
            }
        }
    }
    return categoryTree;
}
Also used : HashMap(java.util.HashMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) HashSet(java.util.HashSet)

Example 44 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project linuxtools by eclipse.

the class LibHover method getLibHoverDocs.

public static synchronized void getLibHoverDocs() {
    if (docsFetched) {
        return;
    }
    libraries.clear();
    helpBooks.clear();
    helpBooksMap.clear();
    // Check if caching of library info is enabled and if so, get any
    // cached library hover info.
    IPreferenceStore ps = LibhoverPlugin.getDefault().getPreferenceStore();
    if (ps.getBoolean(PreferenceConstants.CACHE_EXT_LIBHOVER)) {
        // Look for cached libhover files in the plugin state location
        IPath stateLocation = LibhoverPlugin.getDefault().getStateLocation();
        IFileSystem fs = EFS.getLocalFileSystem();
        // $NON-NLS-1$
        IPath CLibraryLocation = stateLocation.append("C");
        // $NON-NLS-1$
        IPath CPPLibraryLocation = stateLocation.append("CPP");
        IFileStore cDir = fs.getStore(CLibraryLocation);
        if (cDir.fetchInfo().exists()) {
            // $NON-NLS-1$
            getCachedLibraries(cDir, "C");
        }
        IFileStore cppDir = fs.getStore(CPPLibraryLocation);
        if (cppDir.fetchInfo().exists()) {
            // $NON-NLS-1$
            getCachedLibraries(cppDir, "C++");
        }
    }
    IExtensionRegistry x = RegistryFactory.getRegistry();
    IConfigurationElement[] ces = x.getConfigurationElementsFor(LIBHOVER_DOC_EXTENSION);
    for (int i = 0; i < ces.length; ++i) {
        IConfigurationElement ce = ces[i];
        if (ce.getName().equals("library")) {
            // $NON-NLS-1$
            // see comment in initialize()
            // Use the FileLocator class to open the magic hover doc file
            // in the plugin's jar.
            // Either open the html file or file system file depending
            // on what has been specified.
            // $NON-NLS-1$
            String location = ce.getAttribute("location");
            // $NON-NLS-1$
            String name = ce.getAttribute("name");
            // $NON-NLS-1$
            String helpdocs = ce.getAttribute("docs");
            // $NON-NLS-1$
            String type = ce.getAttribute("type");
            String nameSpace = ce.getContributor().getName();
            // If library not already cached, create it
            ICHelpBook book = helpBooksMap.get(name);
            if (book == null) {
                HelpBook h = new HelpBook(name, type);
                helpBooks.add(h);
                helpBooksMap.put(name, h);
                LibHoverLibrary l = new LibHoverLibrary(name, location, helpdocs, nameSpace, // $NON-NLS-1$
                "C++".equals(type));
                libraries.put(h, l);
            } else {
                LibHoverLibrary l = libraries.get(book);
                if (l != null) {
                    l.setDocs(helpdocs);
                }
            }
            docsFetched = true;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) HelpBook(org.eclipse.linuxtools.cdt.libhover.HelpBook) ICHelpBook(org.eclipse.cdt.ui.ICHelpBook) IFileSystem(org.eclipse.core.filesystem.IFileSystem) IFileStore(org.eclipse.core.filesystem.IFileStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ICHelpBook(org.eclipse.cdt.ui.ICHelpBook) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 45 with IExtensionRegistry

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

the class NodeFactoryClassMapper method collectNodeFactoryMappers.

private static List<NodeFactoryClassMapper> collectNodeFactoryMappers() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    if (point == null) {
        LOGGER.error("Invalid extension point: " + EXT_POINT_ID);
        return Collections.emptyList();
    }
    List<NodeFactoryClassMapper> resultList = new ArrayList<NodeFactoryClassMapper>();
    for (IConfigurationElement elem : point.getConfigurationElements()) {
        String classMapperCLName = elem.getAttribute(EXT_POINT_ATTR_CLASS_NAME);
        String decl = elem.getDeclaringExtension().getUniqueIdentifier();
        if (classMapperCLName == null || classMapperCLName.isEmpty()) {
            LOGGER.error("The extension '" + decl + "' doesn't provide the required attribute '" + EXT_POINT_ATTR_CLASS_NAME + "' - ignoring it");
            continue;
        }
        NodeFactoryClassMapper instance = null;
        try {
            instance = (NodeFactoryClassMapper) elem.createExecutableExtension(EXT_POINT_ATTR_CLASS_NAME);
        } catch (Throwable t) {
            LOGGER.error("Problems during initialization of node factory class mapper (with id '" + classMapperCLName + "'.)", t);
            if (decl != null) {
                LOGGER.error("Extension " + decl + " ignored.");
            }
        }
        resultList.add(instance);
    }
    return Collections.unmodifiableList(resultList);
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) 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