Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2012-02-15 12:23:32 -0500
committerSteffen Pingel2012-02-15 12:23:32 -0500
commit0bcb41110f882073ae9a96bb5a1ded863df48a01 (patch)
treebb17efa0e0f7aff146ffcb4c665195c30a186a9b /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal
parent1ffa3ec748a3ae36d799a55787aac0ddbffbbf10 (diff)
downloadorg.eclipse.mylyn.tasks-0bcb41110f882073ae9a96bb5a1ded863df48a01.tar.gz
org.eclipse.mylyn.tasks-0bcb41110f882073ae9a96bb5a1ded863df48a01.tar.xz
org.eclipse.mylyn.tasks-0bcb41110f882073ae9a96bb5a1ded863df48a01.zip
NEW - bug 333930: [api] provide ability to get notified of changes to
task data and submits https://bugs.eclipse.org/bugs/show_bug.cgi?id=333930
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskJobFactory.java42
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/sync/SubmitTaskJob.java52
2 files changed, 92 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskJobFactory.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskJobFactory.java
index 38b5ab0ea..d87d52b2a 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskJobFactory.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskJobFactory.java
@@ -11,6 +11,10 @@
package org.eclipse.mylyn.internal.tasks.core;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
@@ -21,6 +25,7 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.mylyn.commons.core.ExtensionPointReader;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataManager;
import org.eclipse.mylyn.internal.tasks.core.sync.SubmitTaskAttachmentJob;
@@ -32,6 +37,7 @@ import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryManager;
import org.eclipse.mylyn.tasks.core.IRepositoryModel;
import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskJobListener;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
@@ -44,6 +50,12 @@ import org.eclipse.mylyn.tasks.core.sync.TaskJob;
* @author Steffen Pingel
*/
public class TaskJobFactory implements ITaskJobFactory {
+ private static final String ALL_CONNECTORS = "org.eclipse.mylyn.tasks.core.all.connectors"; //$NON-NLS-1$
+
+ /**
+ * listeners provided by extension point
+ */
+ private static Map<String, List<TaskJobListener>> taskJobListeners;
private final TaskList taskList;
@@ -53,6 +65,33 @@ public class TaskJobFactory implements ITaskJobFactory {
private final IRepositoryModel tasksModel;
+ protected static synchronized List<TaskJobListener> getTaskJobListeners(AbstractRepositoryConnector connector) {
+ if (taskJobListeners == null) {
+ taskJobListeners = new HashMap<String, List<TaskJobListener>>();
+ List<TaskJobListener> listeners = loadTaskJobListeners(""); //$NON-NLS-1$
+ taskJobListeners.put(ALL_CONNECTORS, listeners);
+ }
+ if (taskJobListeners.get(connector.getConnectorKind()) == null) {
+ List<TaskJobListener> listeners = loadTaskJobListeners(connector.getConnectorKind());
+ taskJobListeners.put(connector.getConnectorKind(), listeners);
+ }
+ List<TaskJobListener> listeners = new ArrayList<TaskJobListener>();
+ listeners.addAll(taskJobListeners.get(ALL_CONNECTORS));
+ listeners.addAll(taskJobListeners.get(connector.getConnectorKind()));
+ return listeners;
+ }
+
+ protected static List<TaskJobListener> loadTaskJobListeners(String connectorKind) {
+ ExtensionPointReader<TaskJobListener> reader = new ExtensionPointReader<TaskJobListener>(
+ ITasksCoreConstants.ID_PLUGIN,
+ "taskJobListeners", "listener", TaskJobListener.class, "connectorKind", connectorKind); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ IStatus status = reader.read();
+ if (!status.isOK()) {
+ StatusHandler.log(status);
+ }
+ return reader.getItems();
+ }
+
public TaskJobFactory(TaskList taskList, TaskDataManager taskDataManager, IRepositoryManager repositoryManager,
IRepositoryModel tasksModel) {
this.taskList = taskList;
@@ -102,7 +141,8 @@ public class TaskJobFactory implements ITaskJobFactory {
public SubmitJob createSubmitTaskJob(AbstractRepositoryConnector connector, TaskRepository taskRepository,
final ITask task, TaskData taskData, Set<TaskAttribute> oldAttributes) {
- SubmitJob job = new SubmitTaskJob(taskDataManager, connector, taskRepository, task, taskData, oldAttributes);
+ SubmitJob job = new SubmitTaskJob(taskDataManager, connector, taskRepository, task, taskData, oldAttributes,
+ getTaskJobListeners(connector));
job.setPriority(Job.INTERACTIVE);
try {
taskList.run(new ITaskListRunnable() {
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/sync/SubmitTaskJob.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/sync/SubmitTaskJob.java
index 54d708838..102fca9a1 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/sync/SubmitTaskJob.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/sync/SubmitTaskJob.java
@@ -11,12 +11,16 @@
package org.eclipse.mylyn.internal.tasks.core.sync;
+import java.util.Collections;
+import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.net.Policy;
@@ -28,6 +32,8 @@ import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
+import org.eclipse.mylyn.tasks.core.TaskJobEvent;
+import org.eclipse.mylyn.tasks.core.TaskJobListener;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
@@ -49,21 +55,34 @@ public class SubmitTaskJob extends SubmitJob {
private ITask task;
+ private final ITask originalTask;
+
private final Set<TaskAttribute> oldAttributes;
private final TaskDataManager taskDataManager;
private RepositoryResponse response;
+ private final List<TaskJobListener> taskJobListeners;
+
public SubmitTaskJob(TaskDataManager taskDataManager, AbstractRepositoryConnector connector,
TaskRepository taskRepository, ITask task, TaskData taskData, Set<TaskAttribute> oldAttributes) {
+ this(taskDataManager, connector, taskRepository, task, taskData, oldAttributes,
+ Collections.<TaskJobListener> emptyList());
+ }
+
+ public SubmitTaskJob(TaskDataManager taskDataManager, AbstractRepositoryConnector connector,
+ TaskRepository taskRepository, ITask task, TaskData taskData, Set<TaskAttribute> oldAttributes,
+ List<TaskJobListener> taskJobListeners) {
super("Submitting Task"); //$NON-NLS-1$
this.taskDataManager = taskDataManager;
this.connector = connector;
this.taskRepository = taskRepository;
this.task = task;
+ this.originalTask = task;
this.taskData = taskData;
this.oldAttributes = oldAttributes;
+ this.taskJobListeners = taskJobListeners;
setRule(new MutexSchedulingRule());
}
@@ -75,7 +94,7 @@ public class SubmitTaskJob extends SubmitJob {
try {
monitor.beginTask(Messages.SubmitTaskJob_Submitting_task,
2 * (1 + getSubmitJobListeners().length) * 100);
-
+ fireTaskAboutToSubmit();
// post task data
AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
monitor.subTask(Messages.SubmitTaskJob_Sending_data);
@@ -96,6 +115,7 @@ public class SubmitTaskJob extends SubmitJob {
task = createTask(monitor, updatedTaskData);
taskDataManager.putSubmittedTaskData(task, updatedTaskData, monitor);
fireTaskSynchronized(monitor);
+ fireTaskSubmissionComplete();
} catch (CoreException e) {
errorStatus = e.getStatus();
} catch (OperationCanceledException e) {
@@ -115,6 +135,36 @@ public class SubmitTaskJob extends SubmitJob {
}
}
+ protected void fireTaskAboutToSubmit() {
+ for (final TaskJobListener listener : taskJobListeners) {
+ SafeRunner.run(new ISafeRunnable() {
+ public void run() throws Exception {
+ listener.aboutToSubmit(new TaskJobEvent(originalTask, task));
+ }
+
+ public void handleException(Throwable e) {
+ StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Error thrown by TaskJobListener", e)); //$NON-NLS-1$
+ }
+ });
+ }
+ }
+
+ protected void fireTaskSubmissionComplete() {
+ for (final TaskJobListener listener : taskJobListeners) {
+ SafeRunner.run(new ISafeRunnable() {
+ public void run() throws Exception {
+ listener.taskSubmitted(new TaskJobEvent(originalTask, task));
+ }
+
+ public void handleException(Throwable e) {
+ StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
+ "Error thrown by TaskJobListener", e)); //$NON-NLS-1$
+ }
+ });
+ }
+ }
+
private ITask createTask(IProgressMonitor monitor, TaskData updatedTaskData) throws CoreException {
if (taskData.isNew()) {
task = new TaskTask(connector.getConnectorKind(), taskRepository.getRepositoryUrl(),

Back to the top