diff options
author | Mickael Istria | 2017-08-08 14:33:41 +0000 |
---|---|---|
committer | Mickael Istria | 2017-08-08 23:00:38 +0000 |
commit | 1ba9040176a1bdaf3c47df85728ae4ab5b0d2a93 (patch) | |
tree | f15d6c6e94d1f07e3c163a9e8c94321f6ad75ce8 /org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericContentTypeRelatedExtension.java | |
parent | 896e9624a30afb9e3f75daa648707b808d26ae0b (diff) | |
download | eclipse.platform.text-1ba9040176a1bdaf3c47df85728ae4ab5b0d2a93.tar.gz eclipse.platform.text-1ba9040176a1bdaf3c47df85728ae4ab5b0d2a93.tar.xz eclipse.platform.text-1ba9040176a1bdaf3c47df85728ae4ab5b0d2a93.zip |
Bug 520685 - [Generic Editor] Sort ext. by most specialized content-typeI20170809-2000
Factorize extensions and registry polling (can be continued).
This allows most registries to return first the extension that applies
to the most specialized content-types.
Change-Id: Icfd5d0c2e72cd579e9fe8c034420d88c628f39a6
Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericContentTypeRelatedExtension.java')
-rw-r--r-- | org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericContentTypeRelatedExtension.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericContentTypeRelatedExtension.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericContentTypeRelatedExtension.java new file mode 100644 index 00000000000..da7dc2be16c --- /dev/null +++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericContentTypeRelatedExtension.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - Mickael Istria (Red Hat Inc.) + *******************************************************************************/ +package org.eclipse.ui.internal.genericeditor; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; + +/** + * This class wraps and proxies an instance of T provided through extensions + * and loads it lazily when it can contribute to the editor, then delegates all operations to + * actual instance. + * + * @param <T> the actual type to proxy, typically the one defined on the extension point. + */ +public class GenericContentTypeRelatedExtension<T> { + private static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ + private static final String CONTENT_TYPE_ATTRIBUTE = "contentType"; //$NON-NLS-1$ + + public final IConfigurationElement extension; + public final IContentType targetContentType; + + public GenericContentTypeRelatedExtension(IConfigurationElement element) throws Exception { + this.extension = element; + this.targetContentType = Platform.getContentTypeManager().getContentType(element.getAttribute(CONTENT_TYPE_ATTRIBUTE)); + } + + public T createDelegate() { + try { + return (T) extension.createExecutableExtension(CLASS_ATTRIBUTE); + } catch (CoreException e) { + GenericEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, e.getMessage(), e)); + } + return null; + } +} |