01: package org.swingml.errors.handlers;
02:
03: import org.swingml.errors.*;
04: import org.swingml.system.*;
05:
06: /**
07: * @author CrossLogic
08: */
09: public class ErrorHandlerUtilities {
10:
11: /**
12: * Returns a SwingML Spec xml string for rendering a Dialog with the given
13: * ISwingMLError text in it.
14: *
15: * @param error
16: * @return
17: */
18: public static String getDialogFor(ISwingMLError error) {
19: return getDialogFor(new ISwingMLError[] { error });
20: }
21:
22: private static String getDialogFooter() {
23: return "</GRIDBAG-PANEL>"
24: + "</PANEL>"
25: + "<PANEL NAME=\"OkButtonOuterPanel\" ORIENTATION=\"South\" LAYOUT=\"BorderLayout\">"
26: + "<PANEL NAME=\"OkButtonPanel\" ORIENTATION=\"Center\" LAYOUT=\"FlowLayout\">"
27: + "<BUTTON ENABLED=\"True\" NAME=\"okButton\" TEXT=\"OK\">"
28: + "<LISTENER EVENT=\"ActionListener.actionPerformed\">"
29: + "<EXTERNAL-ACTION COMPONENT=\"ServerErrorsWindow\" EXTERNAL-CLASS=\"com.yell.common.swingmlclient.controller.DesktopEventHandler\">"
30: + "<ACTION-PARAM NAME=\"CLOSE\" VALUE=\"ServerErrors\" />"
31: + "<ACTION-PARAM NAME=\"EVENT-SOURCE\" VALUE=\"okButton\" />"
32: + "</EXTERNAL-ACTION>" + "</LISTENER>" + "</BUTTON>"
33: + "</PANEL>" + "</PANEL>" + "</DIALOG>";
34: }
35:
36: private static String getDialogHeader(int width, int height) {
37: return "<DIALOG WIDTH=\""
38: + width
39: + "\" HEIGHT=\""
40: + height
41: + "\" LAYOUT=\"BorderLayout\" MODAL=\"True\" NAME=\"ServerErrorsWindow\" TEXT=\"Error\">"
42: + "<PANEL NAME=\"ServerErrorsPanel\" LAYOUT=\"BorderLayout\" ORIENTATION=\"West\">"
43: + "<GRIDBAG-PANEL NAME=\"GridErrorPanel\" ORIENTATION=\"Center\">";
44: }
45:
46: /**
47: * Returns a SwingML Spec xml string for rendering a Dialog with all the
48: * given ISwingMLErrors' text in it.
49: *
50: * @param error
51: * @return
52: */
53: public static String getDialogFor(ISwingMLError[] errors) {
54: String result = "";
55: if (errors != null && errors.length > 0) {
56:
57: int height = SwingMLTextUtilities.getStringHeight()
58: * errors.length + 50;
59:
60: // Build a Panel of Error messages
61: String fontStyle = "";
62: ISwingMLError error;
63: int width = 0;
64: for (int x = 0; x < errors.length; x++) {
65: error = errors[x];
66: if (error.getType() != ISwingMLError.ERROR_BUSINESS_LOGIC) {
67: fontStyle = "BOLD";
68: } else {
69: fontStyle = "PLAIN";
70: }
71: result += "<GRIDBAG-ROW FILL=\"Horizontal\"><GRIDBAG-CELL><LABEL NAME=\"SpacerLabel_"
72: + x
73: + "\" TEXT=\" \" /></GRIDBAG-CELL><GRIDBAG-CELL ANCHOR=\"Center\">"
74: + "<LABEL FONT-STYLE=\""
75: + fontStyle
76: + "\" NAME=\"ErrorLabel_"
77: + x
78: + "\" TEXT=\""
79: + error.getText()
80: + "\" />"
81: + "</GRIDBAG-CELL></GRIDBAG-ROW>";
82: width = Math.max(width, SwingMLTextUtilities
83: .getStringWidth(error.getText()));
84: }
85:
86: result = getDialogHeader(width + 50, height + 50) + result
87: + getDialogFooter();
88: }
89: return result;
90: }
91: }
|