1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*******************************************************************************
* Copyright (c) 2004 - 2006 University Of British Columbia 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:
* University Of British Columbia - initial API and implementation
*******************************************************************************/
package org.eclipse.mylar.tasks.ui;
import org.eclipse.core.runtime.CoreException;
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.jface.dialogs.MessageDialog;
import org.eclipse.mylar.core.MylarStatusHandler;
import org.eclipse.mylar.internal.tasks.ui.TaskListPreferenceConstants;
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.ITaskDataHandler;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.ui.editors.AbstractTaskEditorInput;
import org.eclipse.mylar.tasks.ui.editors.RepositoryTaskEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
/**
* @author Mik Kersten
* @author Steffen Pingel
*/
public class OpenRepositoryTaskJob extends Job {
private String serverUrl;
private IWorkbenchPage page;
private String repositoryKind;
private String taskId;
private String taskUrl;
public OpenRepositoryTaskJob(String repositoryKind, String serverUrl, String taskId, String taskUrl,
IWorkbenchPage page) {
super("Opening repository task " + taskId);
this.repositoryKind = repositoryKind;
this.taskId = taskId;
this.serverUrl = serverUrl;
this.taskUrl = taskUrl;
this.page = page;
}
@Override
public IStatus run(IProgressMonitor monitor) {
monitor.beginTask("Opening Remote Task", 10);
TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(repositoryKind, serverUrl);
if (repository == null) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog
.openError(null, "Repository Not Found", "Could not find repository configuration for "
+ serverUrl + ". \nPlease set up repository via "
+ TasksUiPlugin.LABEL_VIEW_REPOSITORIES + ".");
TasksUiUtil.openBrowser(taskUrl);
}
});
return Status.OK_STATUS;
}
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
repositoryKind);
try {
ITaskDataHandler offlineHandler = connector.getTaskDataHandler();
if (offlineHandler != null) {
// the following code was copied from SynchronizeTaskJob
RepositoryTaskData downloadedTaskData = null;
downloadedTaskData = offlineHandler.getTaskData(repository, taskId);
if (downloadedTaskData != null) {
TasksUiPlugin.getDefault().getTaskDataManager().push(downloadedTaskData);
}
openEditor(repository, AbstractRepositoryTask.getHandle(repository.getUrl(), taskId),
downloadedTaskData);
} else {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
TasksUiUtil.openBrowser(taskUrl);
}
});
}
} catch (final CoreException e) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
MylarStatusHandler.displayStatus("Unable to open task.", e.getStatus());
}
});
} finally {
monitor.done();
}
return new Status(IStatus.OK, TasksUiPlugin.PLUGIN_ID, IStatus.OK, "", null);
}
private void openEditor(final TaskRepository repository, final String handle, final RepositoryTaskData taskData) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
if (taskData == null) {
TasksUiUtil.openBrowser(taskUrl);
} else {
// AbstractTaskEditorInput editorInput = new
// RepositoryTaskEditorInput(taskUrl, repository, taskData,
// null);
AbstractTaskEditorInput editorInput = new RepositoryTaskEditorInput(repository, handle, taskUrl);
TasksUiUtil.openEditor(editorInput, TaskListPreferenceConstants.TASK_EDITOR_ID, page);
}
}
});
}
}
|