Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2015-11-27 21:39:33 +0000
committerGerrit Code Review @ Eclipse.org2015-11-27 23:02:26 +0000
commit11fb814632a825d3ee291ff6fdd53dd0a3a627ad (patch)
tree5a662c440347d60f7ec178be0e0a1fa54daac9bb
parentb9b67b4a85c973105e45521c4aa66b51754a0e26 (diff)
downloadorg.eclipse.mylyn.tasks-11fb814632a825d3ee291ff6fdd53dd0a3a627ad.tar.gz
org.eclipse.mylyn.tasks-11fb814632a825d3ee291ff6fdd53dd0a3a627ad.tar.xz
org.eclipse.mylyn.tasks-11fb814632a825d3ee291ff6fdd53dd0a3a627ad.zip
move task lookup logic to core
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TasksCoreUtil.java83
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java71
2 files changed, 94 insertions, 60 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TasksCoreUtil.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TasksCoreUtil.java
new file mode 100644
index 000000000..776e2a234
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TasksCoreUtil.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.core.util;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IRepositoryManager;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Ordering;
+
+public class TasksCoreUtil {
+ /**
+ * Searches for a task whose URL matches
+ *
+ * @return first task with a matching URL.
+ */
+ public static AbstractTask getTaskByUrl(TaskList taskList, IRepositoryManager repositoryManager, String taskUrl) {
+ if (!Strings.isNullOrEmpty(taskUrl)) {
+ Collection<AbstractTask> tasks = taskList.getAllTasks();
+ List<AbstractTask> sortedTasks = sortTasksByRepositoryUrl(tasks);
+
+ AbstractRepositoryConnector connector = null;
+ TaskRepository repository = null;
+
+ for (AbstractTask task : sortedTasks) {
+ if (taskUrl.equals(task.getUrl())) {
+ return task;
+ } else {
+ String repositoryUrl = task.getRepositoryUrl();
+ if (repositoryUrl != null) {
+ if (repository == null || !repositoryUrl.equals(repository.getUrl())) {
+ connector = repositoryManager.getRepositoryConnector(task.getConnectorKind());
+ repository = repositoryManager.getRepository(task.getConnectorKind(),
+ task.getRepositoryUrl());
+ }
+
+ if (connector != null) {
+ URL url = connector.getBrowserUrl(repository, task);
+ if (url != null && taskUrl.equals(url.toString())) {
+ return task;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static List<AbstractTask> sortTasksByRepositoryUrl(Collection<AbstractTask> tasks) {
+ List<AbstractTask> sortedTasks = new Ordering<AbstractTask>() {
+
+ @Override
+ public int compare(AbstractTask left, AbstractTask right) {
+ if (left.getRepositoryUrl() == null) {
+ return 1;
+ }
+ if (right.getRepositoryUrl() == null) {
+ return -1;
+ }
+ return left.getRepositoryUrl().compareTo(right.getRepositoryUrl());
+ }
+
+ }.nullsLast().sortedCopy(tasks);
+ return sortedTasks;
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java
index 844e6769a..cbd2fd9bb 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java
@@ -18,7 +18,6 @@ import java.net.SocketTimeoutException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -83,6 +82,7 @@ import org.eclipse.mylyn.internal.tasks.core.UnsubmittedTaskContainer;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataState;
import org.eclipse.mylyn.internal.tasks.core.sync.SynchronizationScheduler;
import org.eclipse.mylyn.internal.tasks.core.sync.SynchronizationScheduler.Synchronizer;
+import org.eclipse.mylyn.internal.tasks.core.util.TasksCoreUtil;
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants;
import org.eclipse.mylyn.internal.tasks.ui.OpenRepositoryTaskJob;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
@@ -145,9 +145,6 @@ import org.eclipse.ui.statushandlers.IStatusAdapterConstants;
import org.eclipse.ui.statushandlers.StatusAdapter;
import org.eclipse.ui.statushandlers.StatusManager;
-import com.google.common.base.Strings;
-import com.google.common.collect.Ordering;
-
/**
* @author Steffen Pingel
*/
@@ -173,7 +170,7 @@ public class TasksUiInternal {
/**
* get the connector discovery wizard command. Calling code should check {@link Command#isEnabled()} on return.
- *
+ *
* @return the command, or null if it is not available.
*/
public static Command getConfiguredDiscoveryWizardCommand() {
@@ -487,7 +484,7 @@ public class TasksUiInternal {
/**
* Synchronize a single task. Note that if you have a collection of tasks to synchronize with this connector then
* you should call synchronize(Set<Set<AbstractTask> repositoryTasks, ...)
- *
+ *
* @param listener
* can be null
*/
@@ -636,7 +633,7 @@ public class TasksUiInternal {
/**
* Creates a new local task and schedules for today
- *
+ *
* @param summary
* if null DEFAULT_SUMMARY (New Task) used.
*/
@@ -823,7 +820,7 @@ public class TasksUiInternal {
* return null.
* <p>
* <b>Note: Applied from patch on bug 99472.</b>
- *
+ *
* @return Shell or <code>null</code>
* @deprecated Use {@link WorkbenchUtil#getShell()} instead
*/
@@ -1008,7 +1005,7 @@ public class TasksUiInternal {
/**
* Only override if task should be opened by a custom editor, default behavior is to open with a rich editor,
* falling back to the web browser if not available.
- *
+ *
* @return true if the task was successfully opened
*/
public static boolean openRepositoryTask(String connectorKind, String repositoryUrl, String id,
@@ -1019,7 +1016,7 @@ public class TasksUiInternal {
/**
* Only override if task should be opened by a custom editor, default behavior is to open with a rich editor,
* falling back to the web browser if not available.
- *
+ *
* @return true if the task was successfully opened
*/
public static boolean openRepositoryTask(String connectorKind, String repositoryUrl, String id,
@@ -1083,7 +1080,7 @@ public class TasksUiInternal {
/**
* Returns text masking the &amp;-character from decoration as an accelerator in SWT labels.
- *
+ *
* @deprecated Use {@link CommonUiUtil#toLabel(String)} instead
*/
@Deprecated
@@ -1194,57 +1191,11 @@ public class TasksUiInternal {
/**
* Searches for a task whose URL matches
- *
+ *
* @return first task with a matching URL.
*/
public static AbstractTask getTaskByUrl(String taskUrl) {
- if (!Strings.isNullOrEmpty(taskUrl)) {
- Collection<AbstractTask> tasks = TasksUiPlugin.getTaskList().getAllTasks();
- List<AbstractTask> sortedTasks = sortTasksByRepositoryUrl(tasks);
-
- AbstractRepositoryConnector connector = null;
- TaskRepository repository = null;
-
- for (AbstractTask task : sortedTasks) {
- if (taskUrl.equals(task.getUrl())) {
- return task;
- } else {
- String repositoryUrl = task.getRepositoryUrl();
- if (repositoryUrl != null) {
- if (repository == null || !repositoryUrl.equals(repository.getUrl())) {
- connector = TasksUi.getRepositoryManager().getRepositoryConnector(task.getConnectorKind());
- repository = getRepository(task);
- }
-
- if (connector != null) {
- URL url = connector.getBrowserUrl(repository, task);
- if (url != null && taskUrl.equals(url.toString())) {
- return task;
- }
- }
- }
- }
- }
- }
- return null;
- }
-
- private static List<AbstractTask> sortTasksByRepositoryUrl(Collection<AbstractTask> tasks) {
- List<AbstractTask> sortedTasks = new Ordering<AbstractTask>() {
-
- @Override
- public int compare(AbstractTask left, AbstractTask right) {
- if (left.getRepositoryUrl() == null) {
- return 1;
- }
- if (right.getRepositoryUrl() == null) {
- return -1;
- }
- return left.getRepositoryUrl().compareTo(right.getRepositoryUrl());
- }
-
- }.nullsLast().sortedCopy(tasks);
- return sortedTasks;
+ return TasksCoreUtil.getTaskByUrl(TasksUiPlugin.getTaskList(), TasksUi.getRepositoryManager(), taskUrl);
}
public static boolean isTaskUrl(String taskUrl) {
@@ -1260,7 +1211,7 @@ public class TasksUiInternal {
/**
* Cleans text for use as the text of an action to ensure that it is displayed properly.
- *
+ *
* @return the cleaned text
* @deprecated use {@link CommonUiUtil#toMenuLabel(String)} instead
*/

Back to the top