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
|
/*******************************************************************************
* Copyright (c) 2004, 2010 Tasktop Technologies 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:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.bugs;
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.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonUiUtil;
import org.eclipse.mylyn.internal.provisional.commons.ui.ICoreRunnable;
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
import org.eclipse.mylyn.internal.tasks.bugs.wizards.ReportErrorWizard;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.bugs.IProduct;
import org.eclipse.mylyn.tasks.bugs.ITaskContribution;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.swt.widgets.Display;
/**
* @author Steffen Pingel
*/
public class TaskErrorReporter {
private final SupportHandlerManager handlerManager;
private final SupportProviderManager providerManager;
public TaskErrorReporter() {
this.handlerManager = new SupportHandlerManager();
this.providerManager = new SupportProviderManager();
}
public SupportHandlerManager getHandlerManager() {
return handlerManager;
}
public SupportRequest preProcess(IStatus status, IProduct product) {
Assert.isNotNull(status);
//Map<String, String> attributes = mappingManager.getAllAttributes(namespace);
SupportRequest request = new SupportRequest(providerManager, status, product);
handlerManager.preProcess(request);
return request;
}
public boolean process(final ITaskContribution response, IRunnableContext context) {
Assert.isNotNull(response);
ICoreRunnable runner = new ICoreRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(Messages.TaskErrorReporter_Job_Progress_Process_support_request, IProgressMonitor.UNKNOWN);
process((AttributeTaskMapper) response, monitor);
} finally {
monitor.done();
}
}
};
try {
CommonUiUtil.run(context, runner);
} catch (CoreException e) {
TasksUiInternal.logAndDisplayStatus(Messages.TaskErrorReporter_Create_Task_Error_Title, new Status(IStatus.ERROR, TasksBugsPlugin.ID_PLUGIN,
Messages.TaskErrorReporter_Create_Task_Error_Message, e));
return false;
} catch (OperationCanceledException e) {
return false;
}
return true;
}
public void process(AttributeTaskMapper mapper, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(mapper);
handlerManager.process(mapper, monitor);
if (!mapper.isHandled()) {
final TaskData taskData = mapper.createTaskData(monitor);
mapper.setTaskData(taskData);
handlerManager.postProcess(mapper, monitor);
// XXX open task asynchronously to make sure the workbench is active
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
TasksUiInternal.createAndOpenNewTask(taskData);
} catch (CoreException e) {
StatusHandler.log(new Status(IStatus.ERROR, TasksBugsPlugin.ID_PLUGIN,
"Unexpected error while creating task", e)); //$NON-NLS-1$
}
}
});
}
}
public void handle(final IStatus status) {
ReportErrorWizard wizard = new ReportErrorWizard(this, status);
WizardDialog dialog = new WizardDialog(WorkbenchUtil.getShell(), wizard);
dialog.setBlockOnOpen(false);
dialog.setPageSize(500, 200);
dialog.open();
}
public SupportProviderManager getProviderManager() {
return providerManager;
}
}
|