Search in sources :

Example 1 with HelpContent

use of org.eclipse.mylyn.internal.wikitext.ui.editor.help.HelpContent in project mylyn.docs by eclipse.

the class WikiTextUiPlugin method getCheatSheets.

public SortedMap<String, HelpContent> getCheatSheets() {
    if (cheatSheets == null) {
        SortedMap<String, HelpContent> cheatSheets = new TreeMap<>();
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getPluginId(), EXTENSION_POINT_CHEAT_SHEET);
        if (extensionPoint != null) {
            IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
            for (IConfigurationElement element : configurationElements) {
                String declaringPluginId = element.getDeclaringExtension().getContributor().getName();
                Bundle bundle = Platform.getBundle(declaringPluginId);
                // $NON-NLS-1$
                String markupLanguage = element.getAttribute("markupLanguage");
                // $NON-NLS-1$
                String contentLanguage = element.getAttribute("contentLanguage");
                // $NON-NLS-1$
                String resource = element.getAttribute("resource");
                try {
                    if (markupLanguage == null) {
                        throw new Exception(Messages.WikiTextUiPlugin_markupLanguageRequired);
                    } else if (!WikiText.getMarkupLanguageNames().contains(markupLanguage)) {
                        throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_invalidMarkupLanguage, new Object[] { markupLanguage }));
                    }
                    if (resource == null || resource.length() == 0) {
                        throw new Exception(Messages.WikiTextUiPlugin_resourceRequired);
                    }
                    HelpContent cheatSheet = new CheatSheetContent(bundle, resource, contentLanguage, markupLanguage);
                    HelpContent previous = cheatSheets.put(cheatSheet.getMarkupLanguageName(), cheatSheet);
                    if (previous != null) {
                        cheatSheets.put(previous.getMarkupLanguageName(), previous);
                        throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_markupLanguageContentAlreadyDeclared, new Object[] { previous.getMarkupLanguageName(), previous.getProvider().getSymbolicName() }));
                    }
                } catch (Exception e) {
                    log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_invalidExtension, new Object[] { declaringPluginId, EXTENSION_POINT_CHEAT_SHEET, e.getMessage() }), e);
                }
            }
        }
        this.cheatSheets = Collections.unmodifiableSortedMap(cheatSheets);
    }
    return cheatSheets;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) HelpContent(org.eclipse.mylyn.internal.wikitext.ui.editor.help.HelpContent) Bundle(org.osgi.framework.Bundle) TreeMap(java.util.TreeMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) CheatSheetContent(org.eclipse.mylyn.internal.wikitext.ui.editor.help.CheatSheetContent)

Aggregations

TreeMap (java.util.TreeMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 CheatSheetContent (org.eclipse.mylyn.internal.wikitext.ui.editor.help.CheatSheetContent)1 HelpContent (org.eclipse.mylyn.internal.wikitext.ui.editor.help.HelpContent)1 Bundle (org.osgi.framework.Bundle)1