summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Doninger2011-08-22 20:23:30 (EDT)
committer Steffen Pingel2011-08-22 20:23:30 (EDT)
commit322adb87a8732b447c0c271762fe3b861c19c269 (patch)
tree1d6419ef6053e54a1c022ce5dfada1bf2692dc31
parentcc66518916118a0146170ef002e25612710e62d0 (diff)
downloadorg.eclipse.mylyn.tasks-322adb87a8732b447c0c271762fe3b861c19c269.zip
org.eclipse.mylyn.tasks-322adb87a8732b447c0c271762fe3b861c19c269.tar.gz
org.eclipse.mylyn.tasks-322adb87a8732b447c0c271762fe3b861c19c269.tar.bz2
ASSIGNED - bug 349924: [patch][api] provide extension point for task
activation listeners https://bugs.eclipse.org/bugs/show_bug.cgi?id=349924
-rw-r--r--org.eclipse.mylyn.tasks.core/plugin.xml1
-rw-r--r--org.eclipse.mylyn.tasks.core/schema/taskActivationListeners.exsd109
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java2
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java45
-rw-r--r--org.eclipse.mylyn.tasks.tests/plugin.xml7
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/MockTaskActivationListenerExtension.java68
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java9
7 files changed, 241 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.core/plugin.xml b/org.eclipse.mylyn.tasks.core/plugin.xml
index 0aeab1a..c0d4cff 100644
--- a/org.eclipse.mylyn.tasks.core/plugin.xml
+++ b/org.eclipse.mylyn.tasks.core/plugin.xml
@@ -13,6 +13,7 @@
<plugin>
<extension-point id="templates" name="templates" schema="schema/templates.exsd"/>
<extension-point id="synchronizationParticipants" name="Synchronization Participants" schema="schema/synchronizationParticipants.exsd"/>
+ <extension-point id="taskActivationListeners" name="Task Activation Listeners" schema="schema/taskActivationListeners.exsd"/>
<extension-point id="activityMonitor" name="Task Activity Monitor" schema="schema/activityMonitor.exsd"/>
<extension-point id="contextStore" name="Task Context Store" schema="schema/contextStore.exsd"/>
</plugin>
diff --git a/org.eclipse.mylyn.tasks.core/schema/taskActivationListeners.exsd b/org.eclipse.mylyn.tasks.core/schema/taskActivationListeners.exsd
new file mode 100644
index 0000000..16d6a97
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/schema/taskActivationListeners.exsd
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.mylyn.tasks.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.mylyn.tasks.core" id="taskActivationListeners" name="Task Activation Listeners"/>
+ </appInfo>
+ <documentation>
+ This extension point can be used to register a task activation listener. The listener class must implement the interface org.eclipse.mylyn.tasks.core.ITaskActivationListener
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="listener" minOccurs="0" maxOccurs="unbounded"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="listener">
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="listenerClass" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.mylyn.tasks.core.ITaskActivationListener"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ Since Mylyn Tasks 3.7
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java
index 3ff03b8..8185bdc 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java
@@ -67,6 +67,8 @@ public interface ITasksCoreConstants {
public static final String PROPERTY_USE_SECURE_STORAGE = "org.eclipse.mylyn.tasklist.repositories.configuration.securestorage"; //$NON-NLS-1$
+ public static final String TASK_ACTIVATION_LISTENER_EP_ID = ID_PLUGIN + ".taskActivationListeners"; //$NON-NLS-1$
+
/**
* Jobs that have the same instances of this rule set are mutually exclusive.
*/
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java
index a03c249..7a97a92 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskActivityManager.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * Manuel Doninger - fixes for bug 349924
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.core;
@@ -26,7 +27,13 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+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.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.internal.tasks.core.TaskContainerDelta.Kind;
@@ -73,6 +80,8 @@ public class TaskActivityManager implements ITaskActivityManager {
private int startDay = Calendar.MONDAY;
+ private boolean listenersInitialized = false;
+
private final ITaskListChangeListener TASKLIST_CHANGE_LISTENER = new ITaskListChangeListener() {
public void containersChanged(Set<TaskContainerDelta> containers) {
@@ -94,6 +103,38 @@ public class TaskActivityManager implements ITaskActivityManager {
clear();
}
+ private void initTaskListeners() {
+ if (!listenersInitialized) {
+ try {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+
+ IExtensionPoint listenerExtensionPoint = registry.getExtensionPoint(ITasksCoreConstants.TASK_ACTIVATION_LISTENER_EP_ID);
+ IExtension[] listenerExtensions = listenerExtensionPoint.getExtensions();
+
+ for (IExtension extension : listenerExtensions) {
+ IConfigurationElement[] configurationElements = extension.getConfigurationElements();
+ for (IConfigurationElement config : configurationElements) {
+ if ("listener".equals(config.getName())) { //$NON-NLS-1$
+ Object object;
+ object = config.createExecutableExtension("listenerClass");//$NON-NLS-1$
+ if (object instanceof ITaskActivationListener) {
+ addActivationListener((ITaskActivationListener) object);
+ } else {
+ StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Registering of task activation listener failed: \"" + object + "\"")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ }
+ }
+ } catch (CoreException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Registering of task activation listener failed: \"" + e.getMessage() + "\"")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ listenersInitialized = true;
+ }
+ }
+
/**
* Get the user specified first day of the week (Calendar.SUNDAY | Calendar.MONDAY)
*
@@ -407,6 +448,8 @@ public class TaskActivityManager implements ITaskActivityManager {
taskList.addTaskIfAbsent(task);
+ initTaskListeners();
+
// notify that a task is about to be activated
for (ITaskActivationListener listener : new ArrayList<ITaskActivationListener>(activationListeners)) {
try {
@@ -443,6 +486,8 @@ public class TaskActivityManager implements ITaskActivityManager {
if (task.isActive() && task == activeTask) {
// notify that a task is about to be deactivated
+ initTaskListeners();
+
for (ITaskActivationListener listener : new ArrayList<ITaskActivationListener>(activationListeners)) {
try {
listener.preTaskDeactivated(task);
diff --git a/org.eclipse.mylyn.tasks.tests/plugin.xml b/org.eclipse.mylyn.tasks.tests/plugin.xml
index 05e2d80..28c47f0 100644
--- a/org.eclipse.mylyn.tasks.tests/plugin.xml
+++ b/org.eclipse.mylyn.tasks.tests/plugin.xml
@@ -86,6 +86,13 @@
attributeId="version"
connectorKind="trac">
</suppressIncoming>
+ </extension>
+ <extension
+ point="org.eclipse.mylyn.tasks.core.taskActivationListeners">
+ <listener
+ id="org.eclipse.mylyn.tasks.tests.listenerTest"
+ listenerClass="org.eclipse.mylyn.tasks.tests.MockTaskActivationListenerExtension">
+ </listener>
</extension>
</plugin>
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/MockTaskActivationListenerExtension.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/MockTaskActivationListenerExtension.java
new file mode 100644
index 0000000..854b32a
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/MockTaskActivationListenerExtension.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Manuel Doninger 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:
+ * Manuel Doninger - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests;
+
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskActivationAdapter;
+
+/**
+ * A task activation listener that is registered through an extension point.
+ *
+ * @author Manuel Doninger
+ */
+public class MockTaskActivationListenerExtension extends TaskActivationAdapter {
+
+ public static MockTaskActivationListenerExtension INSTANCE;
+
+ public boolean hasActivated = false;
+
+ public boolean hasPreActivated = false;
+
+ public boolean hasDeactivated = false;
+
+ public boolean hasPreDeactivated = false;
+
+ public MockTaskActivationListenerExtension() {
+ super();
+ INSTANCE = this;
+ }
+
+ public void reset() {
+ hasActivated = false;
+ hasPreActivated = false;
+
+ hasDeactivated = false;
+ hasPreDeactivated = false;
+
+ }
+
+ @Override
+ public void preTaskActivated(ITask task) {
+ hasPreActivated = true;
+ }
+
+ @Override
+ public void preTaskDeactivated(ITask task) {
+ hasPreDeactivated = true;
+ }
+
+ @Override
+ public void taskActivated(ITask task) {
+ hasActivated = true;
+ }
+
+ @Override
+ public void taskDeactivated(ITask task) {
+ hasDeactivated = true;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
index de82fcf..3ec02ff 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
@@ -137,7 +137,12 @@ public class TaskActivityManagerTest extends TestCase {
assertTrue(listener.hasActivated);
assertFalse(listener.hasPreDeactivated);
assertFalse(listener.hasDeactivated);
+ assertTrue(MockTaskActivationListenerExtension.INSTANCE.hasPreActivated);
+ assertTrue(MockTaskActivationListenerExtension.INSTANCE.hasActivated);
+ assertFalse(MockTaskActivationListenerExtension.INSTANCE.hasPreDeactivated);
+ assertFalse(MockTaskActivationListenerExtension.INSTANCE.hasDeactivated);
+ MockTaskActivationListenerExtension.INSTANCE.reset();
listener.reset();
} finally {
taskActivityManager.deactivateTask(task);
@@ -146,6 +151,10 @@ public class TaskActivityManagerTest extends TestCase {
assertFalse(listener.hasActivated);
assertTrue(listener.hasPreDeactivated);
assertTrue(listener.hasDeactivated);
+ assertFalse(MockTaskActivationListenerExtension.INSTANCE.hasPreActivated);
+ assertFalse(MockTaskActivationListenerExtension.INSTANCE.hasActivated);
+ assertTrue(MockTaskActivationListenerExtension.INSTANCE.hasPreDeactivated);
+ assertTrue(MockTaskActivationListenerExtension.INSTANCE.hasDeactivated);
} finally {
taskActivityManager.removeActivationListener(listener);
}