Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-06-27 11:25:00 -0400
committerSteffen Pingel2013-06-28 08:49:17 -0400
commit41bfa30a421f1051ef38c4946eb31ecd253b2226 (patch)
treedc3109bc38013136e7e95d4dfc6b497a27f713f0 /org.eclipse.mylyn.tasks.ui
parent7d54bbdcace41210385cab6463fae1f096231866 (diff)
downloadorg.eclipse.mylyn.tasks-41bfa30a421f1051ef38c4946eb31ecd253b2226.tar.gz
org.eclipse.mylyn.tasks-41bfa30a421f1051ef38c4946eb31ecd253b2226.tar.xz
org.eclipse.mylyn.tasks-41bfa30a421f1051ef38c4946eb31ecd253b2226.zip
408511: [api] add support for contributing UI and branding at runtime
Change-Id: I33c608dad60ee5d979e2ddd5c5cde4c386519610 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=408511
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/RepositoryConnectorUiExtensionReader.java181
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java66
2 files changed, 188 insertions, 59 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/RepositoryConnectorUiExtensionReader.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/RepositoryConnectorUiExtensionReader.java
new file mode 100644
index 000000000..46595385e
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/RepositoryConnectorUiExtensionReader.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.util;
+
+import java.io.InputStream;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.commons.ui.CommonImages;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.spi.RepositoryConnectorBranding;
+import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+public class RepositoryConnectorUiExtensionReader {
+
+ private static final String EXTENSION_REPOSITORIES = "org.eclipse.mylyn.tasks.ui.repositories"; //$NON-NLS-1$
+
+ public static final String ELMNT_REPOSITORY_UI = "connectorUi"; //$NON-NLS-1$
+
+ private static final String ATTR_BRANDING_ICON = "brandingIcon"; //$NON-NLS-1$
+
+ private static final String ATTR_OVERLAY_ICON = "overlayIcon"; //$NON-NLS-1$
+
+ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
+
+ private final IExtensionRegistry registry;
+
+ /**
+ * Plug-in ids of connector extensions that failed to load.
+ */
+ private final Set<String> disabledContributors;
+
+ public RepositoryConnectorUiExtensionReader(IExtensionRegistry registry, Set<String> disabledContributors) {
+ Assert.isNotNull(registry);
+ Assert.isNotNull(disabledContributors);
+ this.registry = registry;
+ this.disabledContributors = disabledContributors;
+ }
+
+ private boolean isDisabled(IConfigurationElement element) {
+ return disabledContributors.contains(element.getContributor().getName());
+ }
+
+ public void registerConnectorUis() {
+ registerFromExtensionPoint();
+ registerFromAdaptable();
+ }
+
+ private void registerFromAdaptable() {
+ for (AbstractRepositoryConnector connector : TasksUi.getRepositoryManager().getRepositoryConnectors()) {
+ if (TasksUiPlugin.getConnectorUi(connector.getConnectorKind()) == null) {
+ registerFromAdaptable(connector);
+ }
+ }
+ }
+
+ private void registerFromAdaptable(final AbstractRepositoryConnector connector) {
+ SafeRunner.run(new ISafeRunnable() {
+ @Override
+ public void run() throws Exception {
+ AbstractRepositoryConnectorUi connectorUi = (AbstractRepositoryConnectorUi) Platform.getAdapterManager()
+ .loadAdapter(connector, AbstractRepositoryConnectorUi.class.getName());
+ if (connectorUi != null) {
+ TasksUiPlugin.getDefault().addRepositoryConnectorUi(connectorUi);
+ }
+
+ RepositoryConnectorBranding branding = (RepositoryConnectorBranding) Platform.getAdapterManager()
+ .loadAdapter(connector, RepositoryConnectorBranding.class.getName());
+ if (branding != null) {
+ InputStream brandingImageData = branding.getBrandingImageData();
+ if (brandingImageData != null) {
+ TasksUiPlugin.getDefault().addBrandingIcon(connector.getConnectorKind(),
+ getImage(brandingImageData));
+ }
+ InputStream overlayImageData = branding.getOverlayImageData();
+ if (overlayImageData != null) {
+ TasksUiPlugin.getDefault().addOverlayIcon(connector.getConnectorKind(),
+ getImageDescriptor(overlayImageData));
+ }
+ }
+ }
+
+ private ImageDescriptor getImageDescriptor(InputStream in) {
+ return ImageDescriptor.createFromImageData(new ImageData(in));
+ }
+
+ private Image getImage(InputStream in) {
+ return CommonImages.getImage(getImageDescriptor(in));
+ }
+
+ @Override
+ public void handleException(Throwable e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, NLS.bind(
+ "Loading of connector ui for kind ''{0}'' failed.", connector.getConnectorKind()), e)); //$NON-NLS-1$
+ }
+ });
+ }
+
+ private void registerFromExtensionPoint() {
+ IExtensionPoint repositoriesExtensionPoint = registry.getExtensionPoint(EXTENSION_REPOSITORIES);
+ IExtension[] repositoryExtensions = repositoriesExtensionPoint.getExtensions();
+ for (IExtension repositoryExtension : repositoryExtensions) {
+ IConfigurationElement[] elements = repositoryExtension.getConfigurationElements();
+ for (IConfigurationElement element : elements) {
+ if (!isDisabled(element)) {
+ if (element.getName().equals(ELMNT_REPOSITORY_UI)) {
+ registerRepositoryConnectorUi(element);
+ }
+ }
+ }
+ }
+ }
+
+ private void registerRepositoryConnectorUi(IConfigurationElement element) {
+ try {
+ Object connectorUiObject = element.createExecutableExtension(ATTR_CLASS);
+ if (connectorUiObject instanceof AbstractRepositoryConnectorUi) {
+ AbstractRepositoryConnectorUi connectorUi = (AbstractRepositoryConnectorUi) connectorUiObject;
+ if (TasksUiPlugin.getConnector(connectorUi.getConnectorKind()) != null) {
+ TasksUiPlugin.getDefault().addRepositoryConnectorUi(connectorUi);
+
+ String iconPath = element.getAttribute(ATTR_BRANDING_ICON);
+ if (iconPath != null) {
+ ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
+ element.getContributor().getName(), iconPath);
+ if (descriptor != null) {
+ TasksUiPlugin.getDefault().addBrandingIcon(connectorUi.getConnectorKind(),
+ CommonImages.getImage(descriptor));
+ }
+ }
+ String overlayIconPath = element.getAttribute(ATTR_OVERLAY_ICON);
+ if (overlayIconPath != null) {
+ ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
+ element.getContributor().getName(), overlayIconPath);
+ if (descriptor != null) {
+ TasksUiPlugin.getDefault().addOverlayIcon(connectorUi.getConnectorKind(), descriptor);
+ }
+ }
+ } else {
+ StatusHandler.log(new Status(
+ IStatus.ERROR,
+ TasksUiPlugin.ID_PLUGIN,
+ NLS.bind(
+ "Ignoring connector ui for kind ''{0}'' without corresponding core contributed by ''{1}''.", connectorUi.getConnectorKind(), element.getContributor().getName()))); //$NON-NLS-1$
+ }
+ } else {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load connector ui " //$NON-NLS-1$
+ + connectorUiObject.getClass().getCanonicalName()));
+ }
+ } catch (Throwable e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load connector ui", e)); //$NON-NLS-1$
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java
index ff0245a31..ed07f17e1 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiExtensionReader.java
@@ -23,7 +23,6 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.mylyn.commons.core.StatusHandler;
-import org.eclipse.mylyn.commons.ui.CommonImages;
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.internal.tasks.core.activity.DefaultTaskActivityMonitor;
@@ -38,7 +37,7 @@ import org.eclipse.mylyn.tasks.core.AbstractDuplicateDetector;
import org.eclipse.mylyn.tasks.core.RepositoryTemplate;
import org.eclipse.mylyn.tasks.core.activity.AbstractTaskActivityMonitor;
import org.eclipse.mylyn.tasks.core.context.AbstractTaskContextStore;
-import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
+import org.eclipse.mylyn.tasks.core.spi.RepositoryConnectorDescriptor;
import org.eclipse.mylyn.tasks.ui.AbstractTaskRepositoryLinkProvider;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPageFactory;
@@ -87,10 +86,6 @@ public class TasksUiExtensionReader {
public static final String ELMNT_REPOSITORY_UI = "connectorUi"; //$NON-NLS-1$
- public static final String ATTR_BRANDING_ICON = "brandingIcon"; //$NON-NLS-1$
-
- public static final String ATTR_OVERLAY_ICON = "overlayIcon"; //$NON-NLS-1$
-
public static final String ELMNT_TYPE = "type"; //$NON-NLS-1$
public static final String ELMNT_QUERY_PAGE = "queryPage"; //$NON-NLS-1$
@@ -136,6 +131,8 @@ public class TasksUiExtensionReader {
*/
private static Set<String> disabledContributors = new HashSet<String>();
+ private static Set<RepositoryConnectorDescriptor> descriptors = new HashSet<RepositoryConnectorDescriptor>();
+
public static void initStartupExtensions(TaskListExternalizer taskListExternalizer,
TaskRepositoryManager repositoryManager) {
if (!coreExtensionsRead) {
@@ -146,6 +143,7 @@ public class TasksUiExtensionReader {
RepositoryConnectorExtensionReader reader = new RepositoryConnectorExtensionReader(taskListExternalizer,
repositoryManager);
reader.registerConnectors(repositoriesExtensionPoint);
+ descriptors.addAll(reader.getDescriptors());
disabledContributors.addAll(reader.getDisabledContributors());
IExtensionPoint templatesExtensionPoint = registry.getExtensionPoint(EXTENSION_TEMPLATES);
@@ -193,18 +191,9 @@ public class TasksUiExtensionReader {
public static void initWorkbenchUiExtensions() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint repositoriesExtensionPoint = registry.getExtensionPoint(EXTENSION_REPOSITORIES);
- IExtension[] repositoryExtensions = repositoriesExtensionPoint.getExtensions();
- for (IExtension repositoryExtension : repositoryExtensions) {
- IConfigurationElement[] elements = repositoryExtension.getConfigurationElements();
- for (IConfigurationElement element : elements) {
- if (!isDisabled(element)) {
- if (element.getName().equals(ELMNT_REPOSITORY_UI)) {
- readRepositoryConnectorUi(element);
- }
- }
- }
- }
+ RepositoryConnectorUiExtensionReader reader = new RepositoryConnectorUiExtensionReader(registry,
+ disabledContributors);
+ reader.registerConnectorUis();
IExtensionPoint linkProvidersExtensionPoint = registry.getExtensionPoint(EXTENSION_REPOSITORY_LINKS_PROVIDERS);
IExtension[] linkProvidersExtensions = linkProvidersExtensionPoint.getExtensions();
@@ -329,47 +318,6 @@ public class TasksUiExtensionReader {
}
}
- private static void readRepositoryConnectorUi(IConfigurationElement element) {
- try {
- Object connectorUiObject = element.createExecutableExtension(ATTR_CLASS);
- if (connectorUiObject instanceof AbstractRepositoryConnectorUi) {
- AbstractRepositoryConnectorUi connectorUi = (AbstractRepositoryConnectorUi) connectorUiObject;
- if (TasksUiPlugin.getConnector(connectorUi.getConnectorKind()) != null) {
- TasksUiPlugin.getDefault().addRepositoryConnectorUi(connectorUi);
-
- String iconPath = element.getAttribute(ATTR_BRANDING_ICON);
- if (iconPath != null) {
- ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
- element.getContributor().getName(), iconPath);
- if (descriptor != null) {
- TasksUiPlugin.getDefault().addBrandingIcon(connectorUi.getConnectorKind(),
- CommonImages.getImage(descriptor));
- }
- }
- String overlayIconPath = element.getAttribute(ATTR_OVERLAY_ICON);
- if (overlayIconPath != null) {
- ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
- element.getContributor().getName(), overlayIconPath);
- if (descriptor != null) {
- TasksUiPlugin.getDefault().addOverlayIcon(connectorUi.getConnectorKind(), descriptor);
- }
- }
- } else {
- StatusHandler.log(new Status(
- IStatus.ERROR,
- TasksUiPlugin.ID_PLUGIN,
- NLS.bind(
- "Ignoring connector ui for kind ''{0}'' without corresponding core contributed by ''{1}''.", connectorUi.getConnectorKind(), element.getContributor().getName()))); //$NON-NLS-1$
- }
- } else {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load connector ui " //$NON-NLS-1$
- + connectorUiObject.getClass().getCanonicalName()));
- }
- } catch (Throwable e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load connector ui", e)); //$NON-NLS-1$
- }
- }
-
private static void readRepositoryTemplate(IConfigurationElement element) {
boolean anonymous = false;
boolean addAuto = false;

Back to the top