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
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Mylyn project 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.wizards;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.mylyn.monitor.core.StatusHandler;
import org.eclipse.mylyn.tasks.core.AbstractAttributeFactory;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.AbstractTaskDataHandler;
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
import org.eclipse.mylyn.tasks.core.RepositoryTaskData;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.NewTaskEditorInput;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
/**
* Extend for customizing how new tasks editors are created.
*
* @author Steffen Pingel
* @since 2.0
*/
public class NewTaskWizard extends Wizard implements INewWizard {
private TaskRepository taskRepository;
public NewTaskWizard(TaskRepository taskRepository) {
this.taskRepository = taskRepository;
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
}
@Override
public void addPages() {
}
@Override
public boolean canFinish() {
return true;
}
@Override
public boolean performFinish() {
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
taskRepository.getConnectorKind());
final AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
if (taskDataHandler == null) {
StatusHandler.displayStatus("Error creating new task", new RepositoryStatus(IStatus.ERROR,
TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_REPOSITORY,
"The selected repository does not support creating new tasks."));
return false;
}
AbstractAttributeFactory attributeFactory = taskDataHandler.getAttributeFactory(taskRepository.getUrl(),
taskRepository.getConnectorKind(), AbstractTask.DEFAULT_TASK_KIND);
final RepositoryTaskData taskData = new RepositoryTaskData(attributeFactory, taskRepository.getConnectorKind(),
taskRepository.getUrl(), TasksUiPlugin.getDefault().getNextNewRepositoryTaskId());
taskData.setNew(true);
try {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
if (!taskDataHandler.initializeTaskData(taskRepository, taskData, monitor)) {
throw new CoreException(new RepositoryStatus(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
RepositoryStatus.ERROR_REPOSITORY,
"The selected repository does not support creating new tasks."));
}
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
getContainer().run(true, true, runnable);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof CoreException) {
StatusHandler.displayStatus("Error creating new task", ((CoreException) e.getCause()).getStatus());
} else {
StatusHandler.fail(e.getCause(), "Error creating new task", true);
}
return false;
} catch (InterruptedException e) {
return false;
}
NewTaskEditorInput editorInput = new NewTaskEditorInput(taskRepository, taskData);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
TasksUiUtil.openEditor(editorInput, TaskEditor.ID_EDITOR, page);
return true;
}
}
|