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
|
/*******************************************************************************
* 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.mylar.tasks.ui;
import org.eclipse.jface.dialogs.Dialog;
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.mylar.core.MylarStatusHandler;
import org.eclipse.mylar.internal.tasks.ui.wizards.CommonAddExistingTaskWizard;
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
import org.eclipse.mylar.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 {
/**
* @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();
public abstract boolean hasSearchPage();
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;
}
/**
* 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;
}
}
|