001: package com.bostechcorp.cbesb.console.client.dialogs;
002:
003: import com.bostechcorp.cbesb.console.client.ConsoleImageBundle;
004: import com.bostechcorp.cbesb.console.client.StyleConstants;
005: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
006: import com.google.gwt.core.client.GWT;
007: import com.google.gwt.user.client.ui.Button;
008: import com.google.gwt.user.client.ui.ClickListener;
009: import com.google.gwt.user.client.ui.DialogBox;
010: import com.google.gwt.user.client.ui.DisclosureEvent;
011: import com.google.gwt.user.client.ui.DisclosureHandler;
012: import com.google.gwt.user.client.ui.DisclosurePanel;
013: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
014: import com.google.gwt.user.client.ui.HasVerticalAlignment;
015: import com.google.gwt.user.client.ui.HorizontalPanel;
016: import com.google.gwt.user.client.ui.Image;
017: import com.google.gwt.user.client.ui.Label;
018: import com.google.gwt.user.client.ui.PushButton;
019: import com.google.gwt.user.client.ui.TextArea;
020: import com.google.gwt.user.client.ui.VerticalPanel;
021: import com.google.gwt.user.client.ui.Widget;
022:
023: public class MessageViewDialog extends DialogBox {
024: private VerticalPanel messagePanel = new VerticalPanel();
025:
026: private HorizontalPanel messageTextPanel = new HorizontalPanel();
027:
028: private VerticalPanel widgetPanel = new VerticalPanel();
029:
030: private Label messageTextLabel = new Label("", true);
031:
032: String messageTextContent;
033: // Image icon;
034:
035: ConsoleImageBundle images = (ConsoleImageBundle) GWT
036: .create(ConsoleImageBundle.class);
037:
038: Image messageImage;
039:
040: private PushButton okButton;
041:
042: public MessageViewDialog(String messageText,
043: Widget additionalWidget, int iconStyle) {
044: super (false, true);
045: initContent(iconStyle);
046: setMessage(messageText);
047: setStyle();
048: setWidget(messagePanel);
049: if (additionalWidget == null)
050: messagePanel.setWidth("300px");
051: else
052: messagePanel.setWidth("500px");
053: initContent(additionalWidget);
054: show();
055: center();
056: }
057:
058: public MessageViewDialog(String messageText,
059: Widget additionalWidget, int iconStyle,
060: ClickListener listener) {
061: super (false, true);
062: initContent(iconStyle);
063: setMessage(messageText);
064: setStyle();
065: setWidget(messagePanel);
066: if (additionalWidget == null)
067: messagePanel.setWidth("300px");
068: else
069: messagePanel.setWidth("500px");
070: initContent(additionalWidget);
071: okButton.addClickListener(listener);
072: show();
073: center();
074: }
075:
076: private void setMessage(String messageTextContent) {
077: this .messageTextContent = messageTextContent;
078: }
079:
080: private void setStyle() {
081: // TODO Auto-generated method stub
082: }
083:
084: private void initContent(Widget additionalWidget) {
085:
086: messageTextLabel.setText(messageTextContent);
087: // messageTextLabel.setHeight("10px");
088: messageTextLabel.setWidth("100%");
089:
090: messageTextPanel.setHeight("50px");
091: messageTextPanel.add(messageImage);
092: messageTextPanel.add(messageTextLabel);
093: messageTextPanel.setCellWidth(messageTextLabel, "100%");
094: messageTextPanel.setCellHorizontalAlignment(messageImage,
095: HasHorizontalAlignment.ALIGN_LEFT);
096: messageTextPanel.setCellHorizontalAlignment(messageTextLabel,
097: HasHorizontalAlignment.ALIGN_LEFT);
098:
099: messageTextPanel.setCellVerticalAlignment(messageImage,
100: HasVerticalAlignment.ALIGN_MIDDLE);
101: messageTextPanel.setCellVerticalAlignment(messageTextLabel,
102: HasVerticalAlignment.ALIGN_MIDDLE);
103:
104: messagePanel.add(messageTextPanel);
105: messagePanel.setCellVerticalAlignment(messageTextPanel,
106: HasVerticalAlignment.ALIGN_MIDDLE);
107: initWidgetPanel(additionalWidget);
108: okButton = new PushButton(" "
109: + ((ConsoleMessages) GWT.create(ConsoleMessages.class))
110: .OK() + " ");
111: okButton.setWidth("100%");
112: okButton.addClickListener(new ClickListener() {
113: public void onClick(Widget w) {
114: close();
115: }
116: });
117: messagePanel.add(okButton);
118: messagePanel.setCellWidth(okButton, "100%");
119: messagePanel.setCellHorizontalAlignment(okButton,
120: HasHorizontalAlignment.ALIGN_CENTER);
121:
122: }
123:
124: /**
125: * initialize additional widget panel
126: * @param addWidget
127: */
128: private void initWidgetPanel(Widget addWidget) {
129: if (addWidget != null) {
130: // addWidget.setWidth("100%");
131: widgetPanel.add(addWidget);
132: widgetPanel.setCellWidth(addWidget, "100%");
133: messagePanel.add(widgetPanel);
134: messagePanel.setCellWidth(widgetPanel, "100%");
135: } else {
136: // don't add the panel
137: }
138:
139: }
140:
141: private void initContent(int iconStyle) {
142: if (iconStyle == 0) {
143: // get info icon
144: setText(((ConsoleMessages) GWT
145: .create(ConsoleMessages.class)).Information());
146: messageImage = images.informationImage().createImage();
147: } else if (iconStyle == 1) {
148: // get warning icon
149: setText(((ConsoleMessages) GWT
150: .create(ConsoleMessages.class)).Warning());
151: messageImage = images.warningImage().createImage();
152: } else if (iconStyle == 2) {
153: setText(((ConsoleMessages) GWT
154: .create(ConsoleMessages.class)).Error());
155: messageImage = images.errorImage().createImage();
156: }
157: }
158:
159: private void close() {
160: hide();
161: messagePanel.removeFromParent();
162: this .removeFromParent();
163: }
164:
165: // /
166: public static void showInfo(String informationMessage) {
167: new MessageViewDialog(informationMessage, null, 0);
168: }
169:
170: public static void showInfo(String informationmessage,
171: Widget additionalWidget) {
172: new MessageViewDialog(informationmessage, additionalWidget, 0);
173: }
174:
175: public static void showWarning(String warningMessage) {
176: new MessageViewDialog(warningMessage, null, 1);
177: }
178:
179: public static void showError(String errorText, String errorTrace) {
180:
181: new MessageViewDialog(errorText,
182: initErrorContainer(errorTrace), 2);
183: }
184:
185: public static void showError(String errorText,
186: StackTraceElement[] stTr) {
187:
188: new MessageViewDialog(errorText,
189: initErrorContainer(stackTraceToString(stTr)), 2);
190: // mvd.show(parentWidget);
191: }
192:
193: private static String stackTraceToString(StackTraceElement[] stTr) {
194: String result = "";
195: for (int i = 0; i < stTr.length; i++) {
196: result += "\t" + stTr[i].getClassName() + "-"
197: + stTr[i].getMethodName() + "("
198: + stTr[i].getFileName() + ":"
199: + stTr[i].getLineNumber() + ")\n";
200: }
201: return result;
202: }
203:
204: public static void showTimeoutDialog(String text,
205: ClickListener listener) {
206: new MessageViewDialog(text, null, 1, listener);
207: }
208:
209: /**
210: * auxiliar method to create and display the errorPanel
211: * @param errorText
212: * @return
213: */
214: public static Widget initErrorContainer(String errorText) {
215: // Error Area
216: final Button headerButton = new Button(((ConsoleMessages) GWT
217: .create(ConsoleMessages.class)).ShowDetails());
218: // headerLabel.setWidth("100%");
219: headerButton
220: .addStyleName(StyleConstants.POPUP_DIALOG_SHOW_DETAILS);
221: DisclosurePanel errorContainer = new DisclosurePanel();
222: errorContainer.setHeader(headerButton);
223: // errorContainer.addStyleName("headerX");
224: errorContainer.addEventHandler(new DisclosureHandler() {
225: public void onClose(DisclosureEvent event) {
226: headerButton.setText(((ConsoleMessages) GWT
227: .create(ConsoleMessages.class)).ShowDetails());
228: }
229:
230: public void onOpen(DisclosureEvent event) {
231: headerButton.setText(((ConsoleMessages) GWT
232: .create(ConsoleMessages.class)).CloseDetails());
233: }
234: });
235: final TextArea errorTraceArea = new TextArea();
236: errorTraceArea.setWidth("500px");
237: errorContainer.setWidth("500px");
238: // Fixed textarea size
239: // errorTraceArea.setCharacterWidth(80);
240: errorTraceArea.setVisibleLines(9);
241: errorTraceArea.setText(errorText);
242: errorContainer.add(errorTraceArea);
243: // errorContainer.setContent(errorContainer);
244: return errorContainer;
245: }
246: }
|