summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-06-27 11:25:00 (EDT)
committer Steffen Pingel2013-06-28 08:49:17 (EDT)
commit41bfa30a421f1051ef38c4946eb31ecd253b2226 (patch)
treedc3109bc38013136e7e95d4dfc6b497a27f713f0
parent7d54bbdcace41210385cab6463fae1f096231866 (diff)
downloadorg.eclipse.mylyn.tasks-41bfa30a421f1051ef38c4946eb31ecd253b2226.zip
org.eclipse.mylyn.tasks-41bfa30a421f1051ef38c4946eb31ecd253b2226.tar.gz
org.eclipse.mylyn.tasks-41bfa30a421f1051ef38c4946eb31ecd253b2226.tar.bz2
408511: [api] add support for contributing UI and branding at runtimerefs/changes/07/14107/3
Change-Id: I33c608dad60ee5d979e2ddd5c5cde4c386519610 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=408511
-rw-r--r--org.eclipse.mylyn.tasks.core/schema/repositoryConnectorContributor.exsd33
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java7
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorBranding.java106
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorDescriptor.java1
-rw-r--r--org.eclipse.mylyn.tasks.tests/plugin.xml13
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java27
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java74
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/icons/mock-overlay.gifbin0 -> 169 bytes
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/icons/mock-repository.gifbin0 -> 224 bytes
-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
11 files changed, 433 insertions, 75 deletions
diff --git a/org.eclipse.mylyn.tasks.core/schema/repositoryConnectorContributor.exsd b/org.eclipse.mylyn.tasks.core/schema/repositoryConnectorContributor.exsd
index 1009f3f..6c83886 100644
--- a/org.eclipse.mylyn.tasks.core/schema/repositoryConnectorContributor.exsd
+++ b/org.eclipse.mylyn.tasks.core/schema/repositoryConnectorContributor.exsd
@@ -17,9 +17,9 @@
</appInfo>
</annotation>
<complexType>
- <choice>
+ <sequence>
<element ref="contributor"/>
- </choice>
+ </sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
@@ -49,13 +49,13 @@
<element name="contributor">
<complexType>
- <attribute name="class" type="string">
+ <attribute name="class" type="string" use="required">
<annotation>
<documentation>
The class that contributes connector descriptors.
</documentation>
<appInfo>
- <meta.attribute kind="java" basedOn="org.eclipse.mylyn.tasks.core.RepositoryConnectorDescriptor:"/>
+ <meta.attribute kind="java" basedOn="org.eclipse.mylyn.tasks.core.spi.RepositoryConnectorContributor:"/>
</appInfo>
</annotation>
</attribute>
@@ -76,27 +76,28 @@
<meta.section type="examples"/>
</appInfo>
<documentation>
- [Enter extension point usage example here.]
+ &lt;extension
+ point=&quot;org.eclipse.mylyn.tasks.core.repositoryConnectorContributor&quot;&gt;
+ &lt;contributor
+ class=&quot;MyRepositoryConnectorContributor&quot;&gt;
+ &lt;/contributor&gt;
+ &lt;/extension&gt;
</documentation>
</annotation>
- <annotation>
- <appInfo>
- <meta.section type="apiinfo"/>
- </appInfo>
- <documentation>
- [Enter API information here.]
- </documentation>
- </annotation>
+
<annotation>
<appInfo>
- <meta.section type="implementation"/>
+ <meta.section type="copyright"/>
</appInfo>
<documentation>
- [Enter information about supplied implementation of this extension point.]
+ 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
</documentation>
</annotation>
-
</schema>
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java
index 2137fbf..3523a50 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/RepositoryConnectorExtensionReader.java
@@ -208,6 +208,8 @@ public class RepositoryConnectorExtensionReader {
private final List<ConnectorFactory> factories = new ArrayList<ConnectorFactory>();
+ private final List<RepositoryConnectorDescriptor> descriptors = new ArrayList<RepositoryConnectorDescriptor>();
+
private MultiStatus result;
public RepositoryConnectorExtensionReader(TaskListExternalizer taskListExternalizer,
@@ -267,6 +269,7 @@ public class RepositoryConnectorExtensionReader {
factories.add(new ConnectorFactory(descriptor, element.getContributor().getName()));
}
}
+ RepositoryConnectorExtensionReader.this.descriptors.addAll(descriptors);
}
@Override
@@ -380,6 +383,10 @@ public class RepositoryConnectorExtensionReader {
list.add(descriptor);
}
+ public List<RepositoryConnectorDescriptor> getDescriptors() {
+ return new ArrayList<RepositoryConnectorDescriptor>(descriptors);
+ }
+
public Set<String> getDisabledContributors() {
return new HashSet<String>(disabledContributors);
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorBranding.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorBranding.java
new file mode 100644
index 0000000..64f659a
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorBranding.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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.tasks.core.spi;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+
+/**
+ * Specifies branding for a connector that is registered as runtime using {@link RepositoryConnectorContributor}. The
+ * branding extension is obtained by adapting an {@link AbstractRepositoryConnector} instance to
+ * {@link RepositoryConnectorBranding}.
+ * <p>
+ * To contribute branding clients need to register an {@link IAdapterFactory} for the type
+ * {@link AbstractRepositoryConnector}.
+ * </p>
+ * Example <code>plugin.xml</code>:
+ * <p>
+ *
+ * <pre>
+ * &lt;extension
+ * point="org.eclipse.core.runtime.adapters"&gt;
+ * &lt;factory
+ * adaptableType="org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector"
+ * class="MyRepositoryConnectorAdapter"&gt;
+ * &lt;adapter
+ * type="org.eclipse.mylyn.tasks.core.spi.RepositoryConnectorBranding"&gt;
+ * &lt;/adapter&gt;
+ * &lt;/factory&gt;
+ * &lt;/extension&gt;
+ * </pre>
+ *
+ * </p>
+ * <p>
+ * <code>MyRepositoryConnector</code> needs to return an instance of {@link RepositoryConnectorBranding} for the
+ * appropriate connector instance:
+ *
+ * <pre>
+ * public class MyRepositoryConnectorAdapter implements IAdapterFactory {
+ *
+ * &#064;Override
+ * public Object getAdapter(Object adaptableObject, Class adapterType) {
+ * if (adaptableObject instanceof MyRepositoryConnector) {
+ * if (adapterType == RepositoryConnectorBranding.class) {
+ * return new RepositoryConnectorBranding() {
+ * &#064;Override
+ * public InputStream getOverlayImageData() throws IOException {
+ * return getResource(this, &quot;repository-overlay.gif&quot;);
+ * }
+ *
+ * &#064;Override
+ * public InputStream getBrandingImageData() throws IOException {
+ * return CommonTestUtil.getResource(this, &quot;repository.gif&quot;);
+ * }
+ * };
+ * }
+ * }
+ * return null;
+ * }
+ * }
+ * </pre>
+ *
+ * </p>
+ *
+ * @since 3.10
+ * @see RepositoryConnectorContributor
+ * @see RepositoryConnectorDescriptor
+ */
+public abstract class RepositoryConnectorBranding {
+
+ /**
+ * Returns an input stream with the image data for a 16x16 branding icon. This is typically shown in the UI when
+ * selecting connectors. Supported file formats are GIF and PNG.
+ *
+ * @return input stream for image data
+ * @throws IOException
+ * thrown if opening of the stream fails
+ */
+ @NonNull
+ public abstract InputStream getBrandingImageData() throws IOException;
+
+ /**
+ * Returns an input stream with the image data for a 7x8 overlay branding icon. This is typically a very small
+ * version of the branding icon that is used for overlays over repository icons. Supported file formats are GIF and
+ * PNG.
+ *
+ * @return input stream for image data
+ * @throws IOException
+ * thrown if opening of the stream fails
+ */
+ @NonNull
+ public abstract InputStream getOverlayImageData() throws IOException;
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorDescriptor.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorDescriptor.java
index a0151d1..c1c5326 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorDescriptor.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/spi/RepositoryConnectorDescriptor.java
@@ -21,6 +21,7 @@ import org.eclipse.mylyn.tasks.core.AbstractTaskListMigrator;
* A descriptor for an {@link AbstractRepositoryConnector} instance.
*
* @since 3.10
+ * @see RepositoryConnectorBranding
*/
public abstract class RepositoryConnectorDescriptor {
diff --git a/org.eclipse.mylyn.tasks.tests/plugin.xml b/org.eclipse.mylyn.tasks.tests/plugin.xml
index 25485eb..a2c0b0b 100644
--- a/org.eclipse.mylyn.tasks.tests/plugin.xml
+++ b/org.eclipse.mylyn.tasks.tests/plugin.xml
@@ -213,5 +213,18 @@
class="org.eclipse.mylyn.tasks.tests.support.MockRepositoryConnectorContributor">
</contributor>
</extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector"
+ class="org.eclipse.mylyn.tasks.tests.support.MockRepositoryConnectorAdapter">
+ <adapter
+ type="org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi">
+ </adapter>
+ <adapter
+ type="org.eclipse.mylyn.tasks.core.spi.RepositoryConnectorBranding">
+ </adapter>
+ </factory>
+ </extension>
</plugin>
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java
index 80a9234..4c6e19b 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java
@@ -13,9 +13,14 @@ package org.eclipse.mylyn.tasks.tests.core;
import junit.framework.TestCase;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.support.MockRepositoryConnectorAdapter.DynamicMockRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.tests.support.MockRepositoryConnectorDescriptor.DynamicMockRepositoryConnector;
+import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.ui.TasksUi;
+import org.eclipse.swt.graphics.Image;
import org.junit.Test;
public class RepositoryConnectorContributorTest extends TestCase {
@@ -28,4 +33,26 @@ public class RepositoryConnectorContributorTest extends TestCase {
assertEquals(DynamicMockRepositoryConnector.CONNECTOR_KIND, connector.getConnectorKind());
}
+ @Test
+ public void testConnectorUiContributed() {
+ AbstractRepositoryConnectorUi connector = TasksUi.getRepositoryConnectorUi(DynamicMockRepositoryConnector.CONNECTOR_KIND);
+ assertNotNull("Expected connector UI contributed by MockRepositoryConnectorAdapter", connector);
+ assertEquals(DynamicMockRepositoryConnectorUi.class, connector.getClass());
+ assertEquals(DynamicMockRepositoryConnector.CONNECTOR_KIND, connector.getConnectorKind());
+ }
+
+ @Test
+ public void testMockBrandingIcon() {
+ Image brandingImage = TasksUiPlugin.getDefault().getBrandingIcon(DynamicMockRepositoryConnector.CONNECTOR_KIND);
+ assertNotNull("Expected branding image contributed by MockRepositoryConnectorAdapter", brandingImage);
+ }
+
+ @Test
+ public void testMockOverlayIcon() {
+ ImageDescriptor overlay = TasksUiPlugin.getDefault().getOverlayIcon(
+ DynamicMockRepositoryConnector.CONNECTOR_KIND);
+ assertNotNull("Expected overlay image contributed by MockRepositoryConnectorAdapter", overlay);
+ assertEquals(8, overlay.getImageData().height);
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java
new file mode 100644
index 0000000..0956f15
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.tasks.tests.support;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.spi.RepositoryConnectorBranding;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnectorUi;
+import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
+
+public class MockRepositoryConnectorAdapter implements IAdapterFactory {
+
+ public final static class DynamicMockRepositoryConnectorUi extends MockRepositoryConnectorUi {
+
+ private final AbstractRepositoryConnector connector;
+
+ DynamicMockRepositoryConnectorUi(AbstractRepositoryConnector connector) {
+ this.connector = connector;
+ }
+
+ @Override
+ public String getConnectorKind() {
+ return connector.getConnectorKind();
+ }
+
+ }
+
+ private static final Class<?>[] ADAPTER_LIST = new Class<?>[] { AbstractRepositoryConnector.class };
+
+ @Override
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes")
+ Class adapterType) {
+ if (adaptableObject instanceof MockRepositoryConnector) {
+ final AbstractRepositoryConnector connector = (AbstractRepositoryConnector) adaptableObject;
+ if (adapterType == AbstractRepositoryConnectorUi.class) {
+ return new DynamicMockRepositoryConnectorUi(connector);
+ } else if (adapterType == RepositoryConnectorBranding.class) {
+ return new RepositoryConnectorBranding() {
+ @Override
+ public InputStream getOverlayImageData() throws IOException {
+ return CommonTestUtil.getResource(this, "testdata/icons/mock-overlay.gif");
+ }
+
+ @Override
+ public InputStream getBrandingImageData() throws IOException {
+ return CommonTestUtil.getResource(this, "testdata/icons/mock-repository.gif");
+ }
+ };
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Class[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-overlay.gif b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-overlay.gif
new file mode 100644
index 0000000..5494ff7
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-overlay.gif
Binary files differ
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-repository.gif b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-repository.gif
new file mode 100644
index 0000000..1dcbaaf
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-repository.gif
Binary files differ
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 0000000..4659538
--- /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 ff0245a..ed07f17 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;