{
public ExceptionDetailsMessageBox(final BaseAction<?> action, final Throwable exception)
{
super(false, 1, DisplayableButton.CANCEL);
setResizable(true);
final TextArea textArea = new TextArea();
textArea.setHeight(500);
setWidth(1050);
final StringBuilder stringBuilder = new StringBuilder(1000);
stringBuilder.append("ERROR REPORT: [").append(new Date().toString()).append("]").append(newLine);
stringBuilder.append("Page URL: ").append(Window.Location.getHref()).append(newLine).append(newLine);
if (action != null)
{
stringBuilder.append("Actions chain :").append(newLine);
BaseAction<?> currentAction = action;
int count = 0; // prevent infinite loop ... we never know :P
while (currentAction != null && count++ < 100)
{
if (count > 1)
{
stringBuilder.append(newLine).append("Called by: ");
}
stringBuilder.append(currentAction.getProgressMessage());
currentAction = currentAction.getParentChainAction();
}
stringBuilder.append(newLine).append(newLine);
}
if (exception instanceof DkException)
{
final DkException gwtlibException = (DkException) exception;
stringBuilder.append("Server Error Context: ").append(newLine);
for (final Entry<String, String> entry : gwtlibException.getContext().getContextMap().entrySet())
{
stringBuilder.append(entry.getKey()).append(": ").append(entry.getValue()).append(newLine);
}
stringBuilder.append(newLine).append(newLine);
}
if (exception.getMessage() != null)
{
stringBuilder.append("Exception Message: ");
}
if (exception instanceof DkException)
{
final DkException gwtlibException = (DkException) exception;
final Iterator<Couple<String, List<String>>> it = gwtlibException.getContext().getStackTrace().iterator();
while (it.hasNext())
{
final Couple<String, List<String>> couple = it.next();
stringBuilder.append(couple.first).append(newLine);
for (final String stackTraceElement : couple.second)
{
stringBuilder.append(stackTraceElement).append(newLine);
}
if (it.hasNext())
{
stringBuilder.append(newLine).append("Caused by: ");
}
}
}
else
{
stringBuilder.append(exception.getMessage()).append(newLine);
for (final StackTraceElement stackTraceElement : exception.getStackTrace())
{
stringBuilder.append(stackTraceElement).append(newLine);
}
if (exception.getCause() != null
&& !DkObjectUtils.equalsWithNull(exception.getMessage(), exception.getCause().getMessage()))
{
stringBuilder.append(newLine).append("Caused by: ").append(exception.getCause().getMessage()).append(newLine);
for (final StackTraceElement stackTraceElement : exception.getCause().getStackTrace())
{
stringBuilder.append(stackTraceElement).append(newLine);
}
}
}
stringBuilder.append(newLine);
textArea.setValue(stringBuilder.toString());
addField(textArea);
}