Skip to main content
summaryrefslogtreecommitdiffstats
blob: a00d0ac0c30d40e9f99152d82881d56b2ee1e12b (plain) (blame)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*******************************************************************************
 * Copyright (c) 2004 - 2006 Mylar committers 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
 *******************************************************************************/

package org.eclipse.mylyn.tasks.ui;

import java.util.Collections;
import java.util.List;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.mylyn.core.MylarStatusHandler;
import org.eclipse.mylyn.internal.tasks.core.WebTask;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.internal.tasks.ui.wizards.CommonAddExistingTaskWizard;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskListElement;
import org.eclipse.mylyn.tasks.core.RepositoryTaskData;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.tasks.core.Task.PriorityLevel;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

/**
 * TODO: refactor wizards into extension points
 * 
 * @author Mik Kersten
 * @author Eugene Kuleshov
 */
public abstract class AbstractRepositoryConnectorUi {

	private static final String LABEL_TASK_DEFAULT = "Task";

	private boolean customNotificationHandling = false;

	/**
	 * @return the unique type of the repository, e.g. "bugzilla"
	 */
	public abstract String getRepositoryType();

	public abstract AbstractRepositorySettingsPage getSettingsPage();

	/**
	 * @param repository
	 * @param queryToEdit
	 *            can be null
	 */
	public abstract IWizard getQueryWizard(TaskRepository repository, AbstractRepositoryQuery queryToEdit);

	public abstract IWizard getNewTaskWizard(TaskRepository taskRepository);

	public abstract boolean hasRichEditor();

	/**
	 * Override to return a custom task editor ID. If overriding this method the
	 * connector becomes responsible for showing the additional pages handled by
	 * the default task editor. As of Mylar 2.0M2 these are the Planning and
	 * Context pages.
	 */
	public String getTaskEditorId(AbstractRepositoryTask repositoryTask) {
		return TaskEditor.ID_EDITOR;
	}

	public abstract boolean hasSearchPage();

	public List<ITaskListElement> getLegendItems() {
		return Collections.emptyList();
	}
	
	/**
	 * @param repositoryTask
	 *            can be null
	 */
	public String getTaskKindLabel(AbstractRepositoryTask repositoryTask) {
		return LABEL_TASK_DEFAULT;
	}
	
	/**
	 * @param taskData
	 *            can be null
	 */
	public String getTaskKindLabel(RepositoryTaskData taskData) {
		return LABEL_TASK_DEFAULT;
	}
	
	/**
	 * Connector-specific task icons.  
	 * Not recommended to override unless providing custom icons and kind overlays.
	 * 
	 * For connectors that have a decorator that they want to reuse, the connector can 
	 * maintain a reference to the label provider and get the descriptor from the images it returns.
	 */
	public ImageDescriptor getTaskListElementIcon(ITaskListElement element) {
		if (element instanceof AbstractRepositoryQuery) {
			return TasksUiImages.QUERY;
		} else if (element instanceof ITask) {
			return TasksUiImages.TASK;
		} else {
			return null;
		}
	}

	/**
	 * Task kind overlay, recommended to override with connector-specific overlay.
	 */
	public ImageDescriptor getTaskKindOverlay(AbstractRepositoryTask task) {
		if (!hasRichEditor() || task instanceof WebTask) {
			return TasksUiImages.OVERLAY_WEB;
		}
		return null;
	}
	
	/**
	 * Connector-specific priority icons.  Not recommended to override since priority
	 * icons are used elsewhere in the Task List UI (e.g. filter selection in view menu).
	 */
	public ImageDescriptor getTaskPriorityOverlay(AbstractRepositoryTask task) {
		return TasksUiImages.getImageDescriptorForPriority(PriorityLevel.fromString(task.getPriority()));
	}

	public void openEditQueryDialog(AbstractRepositoryQuery query) {
		try {
			TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(query.getRepositoryKind(),
					query.getRepositoryUrl());
			if (repository == null)
				return;

			IWizard wizard = this.getQueryWizard(repository, query);

			Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
			if (wizard != null && shell != null && !shell.isDisposed()) {
				WizardDialog dialog = new WizardDialog(shell, wizard);
				dialog.create();
				dialog.setTitle("Edit Repository Query");
				dialog.setBlockOnOpen(true);
				if (dialog.open() == Dialog.CANCEL) {
					dialog.close();
					return;
				}
			}
		} catch (Exception e) {
			MylarStatusHandler.fail(e, e.getMessage(), true);
		}
	}

	public IWizard getAddExistingTaskWizard(TaskRepository repository) {
		return new CommonAddExistingTaskWizard(repository);
	}

	public WizardPage getSearchPage(TaskRepository repository, IStructuredSelection selection) {
		return null;
	}
	
	/**
	 * Override to return a URL that provides the user with an 
	 * account creation page for the repository
	 * @param taskRepository TODO
	 */
	public String getAccountCreationUrl(TaskRepository taskRepository) {
		return null;
	}

	/**
	 * Override to return a URL that provides the user with an 
	 * account management page for the repository
	 * @param taskRepository TODO
	 */
	public String getAccountManagementUrl(TaskRepository taskRepository) {
		return null;
	}
	
	/**
	 * 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 boolean openRepositoryTask(String repositoryUrl, String id) {
		TaskRepositoryManager repositoryManager = TasksUiPlugin.getRepositoryManager();
		AbstractRepositoryConnector connector = repositoryManager.getRepositoryConnector(getRepositoryType());
		String taskUrl = connector.getTaskWebUrl(repositoryUrl, id);
		if (taskUrl == null) {
			return false;
		}

		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window == null) {
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
			if (windows != null && windows.length > 0) {
				window = windows[0];
			}
		}
		if (window == null) {
			return false;
		}
		IWorkbenchPage page = window.getActivePage();

		OpenRepositoryTaskJob job = new OpenRepositoryTaskJob(getRepositoryType(), repositoryUrl, id, taskUrl, page);
		job.schedule();

		return true;
	}
	
	public IHyperlink[] findHyperlinks(TaskRepository repository, String text, int lineOffset, int regionOffset) {
		return null;
	}

	public void setCustomNotificationHandling(boolean customNotifications) {
		this.customNotificationHandling = customNotifications;
	}

	public boolean hasCustomNotificationHandling() {
		return customNotificationHandling;
	}

	public boolean handlesDueDates(AbstractRepositoryTask task) {
		return false;
	}

	public String getKindLabel(String kindLabel) {
		return null;
	}
}

Back to the top