Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJomar Santos2016-09-24 10:42:31 -0400
committerGerrit Code Review @ Eclipse.org2016-10-12 12:38:23 -0400
commit10640e65c7a404b02c5c041ae6592926b151a6be (patch)
tree867e68a8b980a785c321a466a416588814870ea3
parentcc702de4c7cf3f0ef719b504459983253ac08f8f (diff)
downloadorg.eclipse.mylyn.tasks-10640e65c7a404b02c5c041ae6592926b151a6be.tar.gz
org.eclipse.mylyn.tasks-10640e65c7a404b02c5c041ae6592926b151a6be.tar.xz
org.eclipse.mylyn.tasks-10640e65c7a404b02c5c041ae6592926b151a6be.zip
502035: Created job for synchronization of relevant tasks
Change-Id: If6f7bd2e06a9487b40d613ffe2d119b15433dd1f Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=502035 Signed-off-by: Jomar Santos <jomaroliversantos@gmail.com>
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/SynchronizeRelevantTasksJob.java153
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties1
3 files changed, 156 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java
index b3d31bcd6..f8badedbf 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java
@@ -69,6 +69,8 @@ public class Messages extends NLS {
public static String ScheduleTaskMenuContributor_Schedule_for;
+ public static String SynchronizeRelevantTasksJob_SynchronizingRelevantTasks;
+
public static String TaskAttachmentEditorViewer_Do_not_warn_me_again;
public static String TaskAttachmentEditorViewer_Open_Attachment;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/SynchronizeRelevantTasksJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/SynchronizeRelevantTasksJob.java
new file mode 100644
index 000000000..bbb3c07d4
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/SynchronizeRelevantTasksJob.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.mylyn.internal.tasks.core.ITaskJobFactory;
+import org.eclipse.mylyn.internal.tasks.core.LocalTask;
+import org.eclipse.mylyn.internal.tasks.core.TaskActivityManager;
+import org.eclipse.mylyn.internal.tasks.core.TaskActivityUtil;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IRepositoryManager;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.sync.SynchronizationJob;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+
+public class SynchronizeRelevantTasksJob extends Job {
+
+ private final TaskActivityManager taskActivityManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ private final ITaskJobFactory taskJobFactory;
+
+ private static final int MAX_NUM_TASKS = 10;
+
+ public SynchronizeRelevantTasksJob(TaskActivityManager taskActivityManager, IRepositoryManager repositoryManager,
+ ITaskJobFactory taskJobFactory) {
+ super(Messages.SynchronizeRelevantTasksJob_SynchronizingRelevantTasks);
+ this.taskActivityManager = taskActivityManager;
+ this.repositoryManager = repositoryManager;
+ this.taskJobFactory = taskJobFactory;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ HashSet<ITask> relevantTasks = new HashSet<ITask>();
+
+ addOpenEditorTasks(relevantTasks);
+ addActiveTask(relevantTasks);
+ addTodaysTasks(relevantTasks);
+
+ ListMultimap<TaskRepository, ITask> repositoryMap = mapTasksToRepository(relevantTasks);
+ scheduleSynchronizationJobs(repositoryMap);
+
+ return Status.OK_STATUS;
+ }
+
+ private void scheduleSynchronizationJobs(ListMultimap<TaskRepository, ITask> repositoryMap) {
+ List<Job> jobs = new ArrayList<>();
+ for (TaskRepository taskRepository : repositoryMap.keySet()) {
+ List<ITask> repositoryTasks = repositoryMap.get(taskRepository);
+ AbstractRepositoryConnector connector = TasksUi.getRepositoryConnector(taskRepository.getConnectorKind());
+ SynchronizationJob synchronizationJob = taskJobFactory.createSynchronizeTasksJob(connector, taskRepository,
+ new HashSet<>(repositoryTasks));
+ synchronizationJob.setUser(false);
+ synchronizationJob.setSystem(true);
+ synchronizationJob.schedule();
+ jobs.add(synchronizationJob);
+ }
+
+ for (Job job : jobs) {
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ }
+
+ private void addOpenEditorTasks(HashSet<ITask> relevantTasks) {
+ IWorkbenchWindow[] workbenchWindows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ HashSet<ITask> openTasks = new HashSet<>();
+ for (IWorkbenchWindow workbenchWindow : workbenchWindows) {
+ IWorkbenchPage[] workbenchPages = workbenchWindow.getPages();
+ for (IWorkbenchPage workbenchPage : workbenchPages) {
+ IEditorReference[] editorReferences = workbenchPage.getEditorReferences();
+ for (IEditorReference editorReference : editorReferences) {
+ IEditorPart editorPart = editorReference.getEditor(false);
+ if (editorPart instanceof TaskEditor) {
+ TaskEditorInput taskEditorInput = ((TaskEditor) editorPart).getTaskEditorInput();
+ if (taskEditorInput.exists()) {
+ ITask task = taskEditorInput.getTask();
+ openTasks.add(task);
+ }
+ }
+ }
+ }
+ }
+ if (openTasks.size() < MAX_NUM_TASKS) {
+ relevantTasks.addAll(openTasks);
+ }
+ }
+
+ private void addActiveTask(HashSet<ITask> relevantTasks) {
+ ITask activeTask = taskActivityManager.getActiveTask();
+ if (activeTask != null) {
+ relevantTasks.add(activeTask);
+ }
+ }
+
+ private void addTodaysTasks(HashSet<ITask> relevantTasks) {
+ Set<ITask> dueTasks = taskActivityManager.getScheduledTasks(TaskActivityUtil.getCurrentWeek().getToday());
+ for (ITask dueTask : dueTasks) {
+ if (dueTask.isCompleted()) {
+ dueTasks.remove(dueTask);
+ }
+ }
+ if (dueTasks.size() < MAX_NUM_TASKS) {
+ relevantTasks.addAll(dueTasks);
+ }
+ }
+
+ private ListMultimap<TaskRepository, ITask> mapTasksToRepository(HashSet<ITask> relevantTasks) {
+ ListMultimap<TaskRepository, ITask> repositoryMap = ArrayListMultimap.create();
+ for (ITask task : relevantTasks) {
+ if (!(task instanceof LocalTask)) {
+ String connectorKind = task.getConnectorKind();
+ String repositoryUrl = task.getRepositoryUrl();
+ TaskRepository taskRepository = repositoryManager.getRepository(connectorKind, repositoryUrl);
+ repositoryMap.put(taskRepository, task);
+ }
+ }
+ return repositoryMap;
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties
index 3a3fe1109..a2ae022e6 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties
@@ -40,6 +40,7 @@ ScheduleTaskMenuContributor_Choose_Date_=Choose Date...
ScheduleTaskMenuContributor_Future=Future
ScheduleTaskMenuContributor_Not_Scheduled=Not Scheduled
ScheduleTaskMenuContributor_Schedule_for=Schedule for
+SynchronizeRelevantTasksJob_SynchronizingRelevantTasks=Synchronizing Relevant Tasks
TaskHistoryDropDown_Activate_Task_=Activate Task...
TaskHistoryDropDown_Deactivate_Task=Deactivate Task

Back to the top