package to.etc.domui.component.misc;

import org.eclipse.jdt.annotation.NonNull;
import to.etc.domui.component.misc.MsgBox.Type;
import to.etc.domui.dom.html.NodeContainer;
import to.etc.domui.trouble.UIMsgException;
import to.etc.domui.trouble.ValidationException;
import to.etc.util.StringTool;
import to.etc.webapp.query.QConcurrentUpdateException;

/**
 * @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
 * Created on 2-1-18.
 */
final public class ExceptionDialog {
	private ExceptionDialog() {
	}

	/**
	 * Show an exception as an error dialog.
	 */
	static public void create(NodeContainer container, @NonNull String message, @NonNull Exception x) throws Exception {
		if(x instanceof ValidationException)
			return;
		if(x instanceof QConcurrentUpdateException) {
			MsgBox.error(container, "Concurrent update: " + x);
			return;
		}
		if(x instanceof UIMsgException) {
			UIMsgException msgExc = (UIMsgException) x;
			MsgBox.message(container, msgExc);
			return;
		}

		x.printStackTrace();
		StringBuilder sb = new StringBuilder();
		StringTool.strStacktrace(sb, x);
		MsgBox.message(container, Type.ERROR, message + "\n" + x.toString() + "\n\n" + sb);
	}
}

@@ -115,16 +115,17 @@
 c.MsgBox
+2
 .Type;%0Ai
@@ -1080,32 +1080,199 @@
 sb, x);%0A%09%09MsgBox
+2.on(container)%0A%09%09%09.title(%22An error has occurred%22)%0A%09%09%09.type(Type.ERROR)%0A%09%09%09.text(message + %22%5Cn%22 + x.toString() + %22%5Cn%5Cn%22 + sb)%0A%09%09%09.modal()%0A%09%09%09.size(700, 500)%0A%09%09;%0A%0A%09%09%09//
 .message(contain

Increase dialogbox size.