Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz844509 - uncaught exception in GWT will display in a popup with s…
Browse files Browse the repository at this point in the history
…tacktrace and links
  • Loading branch information
Patrick Huang committed Sep 5, 2012
1 parent e3a3b6a commit db04247
Showing 1 changed file with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.zanata.webtrans.client.EventProcessor.StartCallback;
import org.zanata.webtrans.client.gin.WebTransGinjector;
import org.zanata.webtrans.client.presenter.AppPresenter;
import org.zanata.webtrans.client.rpc.NoOpAsyncCallback;
import org.zanata.webtrans.shared.NoSuchWorkspaceException;
import org.zanata.webtrans.shared.auth.AuthenticationError;
import org.zanata.webtrans.shared.auth.Identity;
Expand All @@ -21,14 +22,20 @@
import com.google.common.base.Strings;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.http.client.URL;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.ClosingEvent;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

Expand All @@ -48,8 +55,21 @@ public class Application implements EntryPoint

private final static WebTransGinjector injector = GWT.create(WebTransGinjector.class);

private final DialogBox globalPopup = new DialogBox(false, true);
private final Button closeGlobalPopupButton = new Button("Close", new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
{
globalPopup.hide();
}
});

public void onModuleLoad()
{
globalPopup.setGlassEnabled(true);
registerUncaughtExceptionHandler();

injector.getDispatcher().execute(new ActivateWorkspaceAction(getWorkspaceId()), new AsyncCallback<ActivateWorkspaceResult>()
{

Expand Down Expand Up @@ -92,25 +112,11 @@ public void onSuccess(ActivateWorkspaceResult result)

});

registerUncaughtExceptionHandler();
}

public static void exitWorkspace()
{
injector.getDispatcher().execute(new ExitWorkspaceAction(identity.getPerson()), new AsyncCallback<ExitWorkspaceResult>()
{
@Override
public void onFailure(Throwable caught)
{

}

@Override
public void onSuccess(ExitWorkspaceResult result)
{

}
});
injector.getDispatcher().execute(new ExitWorkspaceAction(identity.getPerson()), new NoOpAsyncCallback<ExitWorkspaceResult>());
}

private void startApp()
Expand Down Expand Up @@ -170,7 +176,9 @@ public static ProjectIterationId getProjectIterationId()
String projectSlug = Window.Location.getParameter("project");
String iterationSlug = Window.Location.getParameter("iteration");
if (projectSlug == null || iterationSlug == null)
{
return null;
}
try
{
return new ProjectIterationId(projectSlug, iterationSlug);
Expand All @@ -192,28 +200,10 @@ public static void redirectToLogin()
redirectToUrl(getModuleParentBaseUrl() + "account/sign_in?continue=" + URL.encodeQueryString(Window.Location.getHref()));
}

public static void redirectToLogout()
{
redirectToUrl(getModuleParentBaseUrl() + "account/sign_out");
}

public static void redirectToZanataProjectHome(WorkspaceId workspaceId)
{
redirectToUrl(getModuleParentBaseUrl() + "project/view/" + workspaceId.getProjectIterationId().getProjectSlug());
}

public static native void redirectToUrl(String url)/*-{
$wnd.location = url;
}-*/;

public static native void openNewWindowToUrl(String url)/*-{
$wnd.open(url);
}-*/;

public static native void closeWindow()/*-{
$wnd.close();
}-*/;

public static WorkspaceId getWorkspaceId()
{
if (workspaceId == null)
Expand Down Expand Up @@ -289,6 +279,27 @@ private void registerUncaughtExceptionHandler()
public void onUncaughtException(Throwable e)
{
Log.error("uncaught exception", e);
globalPopup.getCaption().setHTML("<div class=\"globalPopupCaption\">ERROR: " + e.getMessage() + "</div>");
SafeHtmlBuilder htmlBuilder = new SafeHtmlBuilder();
htmlBuilder.appendHtmlConstant("<h3>")
.appendEscaped("Stack trace for the error:")
.appendHtmlConstant("</h3>");
htmlBuilder.appendHtmlConstant("<pre>");
for (StackTraceElement ste : e.getStackTrace())
{
htmlBuilder.appendEscaped(ste.toString() + "\n\t");
}
htmlBuilder.appendHtmlConstant("</pre>");
htmlBuilder.appendHtmlConstant("<h3>Please recall your actions and take one of the following steps:</h3>")
.appendHtmlConstant("<ul>")
.appendHtmlConstant("<li>Check if it's a <a href=\"https://bugzilla.redhat.com/buglist.cgi?product=Zanata&bug_status=__open__\" target=\"_blank\">known issue</a>; Or</li>")
.appendHtmlConstant("<li><a href=\"https://bugzilla.redhat.com/enter_bug.cgi?format=guided&product=Zanata\" target=\"_blank\">Report a problem</a>; Or</li>")
.appendHtmlConstant("<li>Email <a href=\"mailto:zanata-users@redhat.com\">Zanata users mailing list</a></li>")
.appendHtmlConstant("</ul>");
HTMLPanel popupContent = new HTMLPanel(htmlBuilder.toSafeHtml());
popupContent.add(closeGlobalPopupButton);
globalPopup.setWidget(popupContent);
globalPopup.center();
}
});
}
Expand Down

0 comments on commit db04247

Please sign in to comment.