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
|
/*******************************************************************************
* 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.ui;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.mylyn.internal.monitor.core.util.IStatusHandler;
import org.eclipse.mylyn.internal.tasks.ui.util.WebBrowserDialog;
import org.eclipse.mylyn.monitor.core.StatusHandler;
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
/**
* @author Mik Kersten
* @author Rob Elves
*/
public class RepositoryAwareStatusHandler implements IStatusHandler {
protected static final String ERROR_MESSAGE = "Please report the following error at:\n"
+ "http://bugs.eclipse.org/bugs/enter_bug.cgi?product=Mylyn\n\n"
+ "Or select Report as Bug from popup menu on error in the Error Log (Window -> Show View -> Error Log)";
// TODO: implement option to report bug
public void fail(final IStatus status, boolean informUser) {
if (informUser && Platform.isRunning()) {
try {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
Shell shell = null;
if (PlatformUI.getWorkbench() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
}
ErrorDialog.openError(shell, "Mylyn Error", ERROR_MESSAGE, status);
}
});
} catch (Throwable t) {
status.getException().printStackTrace();
}
}
}
public void displayStatus(final String title, final IStatus status) {
if (status.getCode() == RepositoryStatus.ERROR_INTERNAL) {
StatusHandler.log(status);
fail(status, true);
return;
}
if (Platform.isRunning()) {
try {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
Shell shell = null;
if (PlatformUI.getWorkbench() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
}
if (status instanceof RepositoryStatus && ((RepositoryStatus) status).isHtmlMessage()) {
WebBrowserDialog.openAcceptAgreement(shell, title, status.getMessage(),
((RepositoryStatus) status).getHtmlMessage());
return;
}
switch (status.getSeverity()) {
case IStatus.CANCEL:
case IStatus.INFO:
createDialog(shell, title, status.getMessage(), MessageDialog.INFORMATION).open();
break;
case IStatus.WARNING:
createDialog(shell, title, status.getMessage(), MessageDialog.WARNING).open();
break;
case IStatus.ERROR:
default:
createDialog(shell, title, status.getMessage(), MessageDialog.ERROR).open();
break;
}
}
});
} catch (Throwable t) {
status.getException().printStackTrace();
}
}
}
private MessageDialog createDialog(Shell shell, String title, String message, int type) {
return new MessageDialog(shell, title, null, message, type, new String[] { IDialogConstants.OK_LABEL }, 0);
}
}
|