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
|
/*******************************************************************************
* 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.internal.tasks.bugs;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.mylyn.commons.core.AbstractErrorReporter;
import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractAttributeFactory;
import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractLegacyRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractTaskDataHandler;
import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryTaskData;
import org.eclipse.mylyn.internal.tasks.core.deprecated.TaskSelection;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.deprecated.NewTaskEditorInput;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
/**
* @author Steffen Pingel
*/
public class TaskErrorReporter extends AbstractErrorReporter {
private PluginRepositoryMappingManager manager;
TaskErrorReporter() {
manager = new PluginRepositoryMappingManager();
}
public boolean isEnabled() {
return manager.hasMappings();
}
@Override
public int getPriority(IStatus status) {
Assert.isNotNull(status);
String pluginId = status.getPlugin();
for (int i = 0; i <= pluginId.length(); i++) {
if (manager.getMapping(pluginId.substring(0, i)) != null) {
return PRIORITY_DEFAULT;
}
}
return PRIORITY_NONE;
}
@Override
public void handle(IStatus status) {
Assert.isNotNull(status);
String pluginId = status.getPlugin();
Map<String, String> attributes = manager.getAllAttributes(pluginId);
openNewTaskEditor(status, attributes);
}
private void openNewTaskEditor(IStatus status, Map<String, String> attributes) {
AttributeTaskMapper mapper = new AttributeTaskMapper(attributes);
TaskRepository taskRepository = mapper.getTaskRepository();
try {
if (taskRepository != null) {
RepositoryTaskData taskData = createTaskData(taskRepository, mapper);
if (taskData != null) {
taskData.setSummary(status.getMessage());
TaskContributorManager manager = new TaskContributorManager();
manager.updateAttributes(taskData, status);
String editorId = manager.getEditorId(status);
NewTaskEditorInput editorInput = new NewTaskEditorInput(taskRepository, taskData);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
TasksUiUtil.openEditor(editorInput, editorId, page);
return;
}
}
TaskSelection taskSelection = mapper.createTaskSelection();
updateAttributes(taskSelection.getTaskData(), status);
// fall back to opening wizard
TasksUiUtil.openNewTaskEditor(null, taskSelection, taskRepository);
} catch (OperationCanceledException e) {
// ignore
}
}
private RepositoryTaskData createTaskData(final TaskRepository taskRepository, AttributeTaskMapper mapper) {
AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(
taskRepository.getConnectorKind());
if (!(connector instanceof AbstractLegacyRepositoryConnector)) {
return null;
}
final AbstractTaskDataHandler taskDataHandler = ((AbstractLegacyRepositoryConnector) connector).getLegacyTaskDataHandler();
if (taskDataHandler == null) {
return null;
}
AbstractAttributeFactory attributeFactory = taskDataHandler.getAttributeFactory(taskRepository.getRepositoryUrl(),
taskRepository.getConnectorKind(), AbstractTask.DEFAULT_TASK_KIND);
final RepositoryTaskData taskData = new RepositoryTaskData(attributeFactory, taskRepository.getConnectorKind(),
taskRepository.getRepositoryUrl(), TasksUiPlugin.getDefault().getNextNewRepositoryTaskId());
taskData.setNew(true);
mapper.applyTo(taskData);
try {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
if (!taskDataHandler.initializeTaskData(taskRepository, taskData, monitor)) {
throw new InvocationTargetException(new Exception());
}
} catch (CoreException e) {
throw new InvocationTargetException(e);
} catch (OperationCanceledException e) {
throw new InterruptedException();
}
}
};
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
} catch (InvocationTargetException e) {
return null;
} catch (InterruptedException e) {
throw new OperationCanceledException();
}
taskDataHandler.cloneTaskData(mapper.createTaskSelection().getTaskData(), taskData);
return taskData;
}
private void updateAttributes(RepositoryTaskData taskData, IStatus status) {
}
}
|