Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2010-09-01 21:46:25 -0400
committerspingel2010-09-01 21:46:25 -0400
commit3a0429389854d4f0f18d1f6de684f5419af03df2 (patch)
tree44fe336d630915679ced2ecc6e06870be0b28269
parent72345ce416ba57fd0d3c6b7cf60c418c5e97b09c (diff)
downloadorg.eclipse.mylyn.tasks-3a0429389854d4f0f18d1f6de684f5419af03df2.tar.gz
org.eclipse.mylyn.tasks-3a0429389854d4f0f18d1f6de684f5419af03df2.tar.xz
org.eclipse.mylyn.tasks-3a0429389854d4f0f18d1f6de684f5419af03df2.zip
RESOLVED - bug 316234: repository error dialog fails with SWTError if internal browser is not available
https://bugs.eclipse.org/bugs/show_bug.cgi?id=316234
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/WebBrowserDialog.java59
1 files changed, 55 insertions, 4 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/WebBrowserDialog.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/WebBrowserDialog.java
index 5e4c53d0c..4daeebf1f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/WebBrowserDialog.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/WebBrowserDialog.java
@@ -11,9 +11,21 @@
package org.eclipse.mylyn.internal.tasks.ui.util;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
@@ -21,6 +33,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
/**
* Dialog to show the contents of an html page to the user
@@ -31,6 +44,8 @@ public class WebBrowserDialog extends MessageDialog {
private String data = null;
+ private static Boolean browserAvailable;
+
public WebBrowserDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
int dialogImageType, String[] dialogButtonLabels, int defaultIndex, String data) {
super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels,
@@ -40,10 +55,33 @@ public class WebBrowserDialog extends MessageDialog {
}
public static int openAcceptAgreement(Shell parent, String title, String message, String data) {
- WebBrowserDialog dialog = new WebBrowserDialog(parent, title, null, // accept
- message, NONE, new String[] { IDialogConstants.OK_LABEL }, 0, data);
- // ok is the default
- return dialog.open();
+ if (isInternalBrowserAvailable(parent)) {
+ WebBrowserDialog dialog = new WebBrowserDialog(parent, title, null, // accept
+ message, NONE, new String[] { IDialogConstants.OK_LABEL }, 0, data);
+ // ok is the default
+ return dialog.open();
+ } else {
+ File file = null;
+ try {
+ file = File.createTempFile("mylyn-error", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
+ file.deleteOnExit();
+ BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+ try {
+ writer.write(message);
+ } finally {
+ writer.close();
+ }
+ } catch (IOException e) {
+ if (file != null) {
+ file.delete();
+ }
+ StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
+ "Unexpected error while displaying error", e));
+ return Window.CANCEL;
+ }
+ WorkbenchUtil.openUrl(file.toURI().toString(), IWorkbenchBrowserSupport.AS_EXTERNAL);
+ return Window.OK;
+ }
}
@Override
@@ -62,4 +100,17 @@ public class WebBrowserDialog extends MessageDialog {
return parent;
}
+ private static synchronized boolean isInternalBrowserAvailable(Composite composite) {
+ if (browserAvailable == null) {
+ try {
+ Browser browser = new Browser(composite, SWT.NULL);
+ browser.dispose();
+ browserAvailable = true;
+ } catch (SWTError e) {
+ browserAvailable = false;
+ }
+ }
+ return browserAvailable;
+ }
+
}

Back to the top