Search in sources :

Example 41 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project mylyn.docs by eclipse.

the class WikiTextExtensionPointReader method initializeValidationRules.

private void initializeValidationRules() {
    initializeMarkupLanguages();
    synchronized (this) {
        if (validationRulesByLanguageName == null) {
            Map<String, ValidationRules> validationRulesByLanguageName = new HashMap<>();
            IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getExtensionPointNamespace(), EXTENSION_VALIDATION_RULES);
            if (extensionPoint != null) {
                IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
                for (IConfigurationElement element : configurationElements) {
                    try {
                        // $NON-NLS-1$
                        String markupLanguage = element.getAttribute("markupLanguage");
                        if (markupLanguage == null || markupLanguage.length() == 0) {
                            // $NON-NLS-1$
                            throw new Exception(Messages.getString("WikiTextExtensionPointReader.4"));
                        }
                        if (!languageByName.containsKey(markupLanguage)) {
                            throw new Exception(MessageFormat.format(Messages.getString("WikiTextExtensionPointReader.5"), // $NON-NLS-1$
                            languageByName));
                        }
                        Object extension;
                        try {
                            // $NON-NLS-1$
                            extension = element.createExecutableExtension("class");
                        } catch (CoreException e) {
                            getLog().log(e.getStatus());
                            continue;
                        }
                        if (!(extension instanceof ValidationRule)) {
                            throw new Exception(MessageFormat.format(Messages.getString("WikiTextExtensionPointReader.7"), // $NON-NLS-1$
                            extension.getClass().getName()));
                        }
                        ValidationRules rules = validationRulesByLanguageName.get(markupLanguage);
                        if (rules == null) {
                            rules = new ValidationRules();
                            validationRulesByLanguageName.put(markupLanguage, rules);
                        }
                        rules.addValidationRule((ValidationRule) extension);
                    } catch (Exception e) {
                        log(IStatus.ERROR, // $NON-NLS-1$
                        MessageFormat.format(// $NON-NLS-1$
                        Messages.getString("WikiTextExtensionPointReader.8"), element.getDeclaringExtension().getContributor().getName(), EXTENSION_VALIDATION_RULES, e.getMessage()), e);
                    }
                }
            }
            // now that we have the basic validation rules, check for language extensions and connect the hierarchy
            // first ensure that all language names have templates defined
            Set<String> languageNames = getMarkupLanguageNames();
            for (String languageName : languageNames) {
                ValidationRules rules = validationRulesByLanguageName.get(languageName);
                if (rules == null) {
                    rules = new ValidationRules();
                    validationRulesByLanguageName.put(languageName, rules);
                }
            }
            // next connect the hierarchy
            for (String languageName : languageNames) {
                MarkupLanguage markupLanguage = getMarkupLanguage(languageName);
                if (markupLanguage != null && markupLanguage.getExtendsLanguage() != null) {
                    ValidationRules languageRules = validationRulesByLanguageName.get(languageName);
                    ValidationRules parentLanguageRules = validationRulesByLanguageName.get(markupLanguage.getExtendsLanguage());
                    languageRules.setParent(parentLanguageRules);
                }
            }
            this.validationRulesByLanguageName = validationRulesByLanguageName;
        }
    }
}
Also used : HashMap(java.util.HashMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) ValidationRule(org.eclipse.mylyn.wikitext.validation.ValidationRule) ValidationRules(org.eclipse.mylyn.wikitext.validation.ValidationRules) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

Example 42 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project dsl-devkit by dsldevkit.

the class ValidExtensionPointManager method getExtensions.

/**
 * Returns proxies for all registered extensions; does not cause the extension plug-ins to be loaded.
 * The proxies contain -- and can therefore be queried for -- all the XML attribute values that the
 * extensions provide in their <i>plugin.xml</i> file. Throws IllegalArgumentException
 * if extension point is unknown
 *
 * @return array of proxies
 */
public static ValidExtension[] getExtensions() {
    IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_NAME);
    if (point == null) {
        throw new IllegalArgumentException(MessageFormat.format(UNKNOWN_EXTENSION_POINT, PLUGIN_ID, EXTENSION_POINT_NAME));
    }
    IExtension[] extensions = point.getExtensions();
    List<ValidExtension> found = new ArrayList<ValidExtension>();
    for (IExtension e : extensions) {
        ValidExtension obj = ValidExtension.parseExtension(e);
        if (obj != null) {
            found.add(obj);
        }
    }
    return found.toArray(new ValidExtension[found.size()]);
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) ArrayList(java.util.ArrayList)

Example 43 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project tdq-studio-se by Talend.

the class PartListener method getConfigurationElement.

protected static IConfigurationElement getConfigurationElement() {
    IExtensionPoint pt = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_NAME);
    IExtension[] extensions = pt.getExtensions();
    for (IExtension extension : extensions) {
        for (IConfigurationElement configurationElement : extension.getConfigurationElements()) {
            return configurationElement;
        }
    }
    return null;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 44 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project tdq-studio-se by Talend.

the class CatalogNode method addExtensionNodes.

private void addExtensionNodes() {
    String databaseProductName = getSession().getRoot().getDatabaseProductName().toLowerCase().trim();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint("net.sourceforge.sqlexplorer", "node");
    IExtension[] extensions = point.getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        IExtension e = extensions[i];
        IConfigurationElement[] ces = e.getConfigurationElements();
        for (int j = 0; j < ces.length; j++) {
            try {
                // include only nodes that are attachted to the schema
                // node..
                String parent = ces[j].getAttribute("parent-node");
                if (parent.indexOf("catalog") == -1) {
                    continue;
                }
                boolean isValidProduct = false;
                String[] validProducts = ces[j].getAttribute("database-product-name").split(",");
                // include only nodes valid for this database
                for (int k = 0; k < validProducts.length; k++) {
                    String product = validProducts[k].toLowerCase().trim();
                    if (product.length() == 0) {
                        continue;
                    }
                    if (product.equals("*")) {
                        isValidProduct = true;
                        break;
                    }
                    String regex = TextUtil.replaceChar(product, '*', ".*");
                    if (databaseProductName.matches(regex)) {
                        isValidProduct = true;
                        break;
                    }
                }
                if (!isValidProduct) {
                    continue;
                }
                String imagePath = ces[j].getAttribute("icon");
                String id = ces[j].getAttribute("id");
                String type = ces[j].getAttribute("table-type").trim();
                AbstractNode childNode = (AbstractNode) ces[j].createExecutableExtension("class");
                childNode.setParent(this);
                childNode.setSession(_session);
                childNode.setType(type);
                String fragmentId = id.substring(0, id.indexOf('.', 28));
                if (imagePath != null && imagePath.trim().length() != 0) {
                    childNode.setImage(ImageUtil.getFragmentImage(fragmentId, imagePath));
                }
                _childNames.add(childNode.getLabelText());
                if (!isExcludedByFilter(childNode.getLabelText())) {
                    addChildNode(childNode);
                }
            } catch (Throwable ex) {
                SQLExplorerPlugin.error("Could not create child node", ex);
            }
        }
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 45 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project tdq-studio-se by Talend.

the class CatalogNode method findExtensionNode.

/**
 * Location extenstion nodes for a given tableType
 *
 * @param tableType for which to find extension node
 * @return INode or null if no extensions found
 */
private INode findExtensionNode(String tableType) {
    String databaseProductName = getSession().getRoot().getDatabaseProductName().toLowerCase().trim();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint("net.sourceforge.sqlexplorer", "node");
    IExtension[] extensions = point.getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        IExtension e = extensions[i];
        IConfigurationElement[] ces = e.getConfigurationElements();
        for (int j = 0; j < ces.length; j++) {
            try {
                // include only nodes that are attachted to the schema
                // node..
                String parent = ces[j].getAttribute("parent-node");
                if (parent.indexOf("catalog") == -1) {
                    continue;
                }
                boolean isValidProduct = false;
                String[] validProducts = ces[j].getAttribute("database-product-name").split(",");
                // include only nodes valid for this database
                for (int k = 0; k < validProducts.length; k++) {
                    String product = validProducts[k].toLowerCase().trim();
                    if (product.length() == 0) {
                        continue;
                    }
                    if (product.equals("*")) {
                        isValidProduct = true;
                        break;
                    }
                    String regex = TextUtil.replaceChar(product, '*', ".*");
                    if (databaseProductName.matches(regex)) {
                        isValidProduct = true;
                        break;
                    }
                }
                if (!isValidProduct) {
                    continue;
                }
                // check if it is the correct type
                String type = ces[j].getAttribute("table-type").trim();
                if (!type.equalsIgnoreCase(tableType)) {
                    continue;
                }
                AbstractNode childNode = (AbstractNode) ces[j].createExecutableExtension("class");
                childNode.setParent(this);
                childNode.setSession(_session);
                return childNode;
            } catch (Throwable ex) {
                SQLExplorerPlugin.error("Could not create child node", ex);
            }
        }
    }
    return null;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)187 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)160 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)107 IExtension (org.eclipse.core.runtime.IExtension)92 CoreException (org.eclipse.core.runtime.CoreException)70 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)17 Platform (org.eclipse.core.runtime.Platform)17 Stream (java.util.stream.Stream)16 List (java.util.List)15 NodeLogger (org.knime.core.node.NodeLogger)15 Map (java.util.Map)14 Optional (java.util.Optional)14 Collection (java.util.Collection)9 Bundle (org.osgi.framework.Bundle)9 Collectors (java.util.stream.Collectors)8 IOException (java.io.IOException)6 Collections (java.util.Collections)6 LinkedList (java.util.LinkedList)6 Objects (java.util.Objects)6