001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.console.client.dialogs;
025:
026: import com.bostechcorp.cbesb.console.client.ConsoleImageBundle;
027: import com.bostechcorp.cbesb.console.client.ClientUtils;
028: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
029: import com.google.gwt.core.client.GWT;
030: import com.google.gwt.user.client.ui.Button;
031: import com.google.gwt.user.client.ui.ClickListener;
032: import com.google.gwt.user.client.ui.DialogBox;
033: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
034: import com.google.gwt.user.client.ui.HasVerticalAlignment;
035: import com.google.gwt.user.client.ui.HorizontalPanel;
036: import com.google.gwt.user.client.ui.Image;
037: import com.google.gwt.user.client.ui.Label;
038: import com.google.gwt.user.client.ui.PushButton;
039: import com.google.gwt.user.client.ui.VerticalPanel;
040: import com.google.gwt.user.client.ui.Widget;
041:
042: public class ConfirmationViewDialog extends DialogBox {
043:
044: private static final String YES_BUTTON = ((ConsoleMessages) GWT
045: .create(ConsoleMessages.class)).yes();
046:
047: private static final String CANCEL_BUTTON = ((ConsoleMessages) GWT
048: .create(ConsoleMessages.class)).Cancel();
049:
050: private static final String NO_BUTTON = ((ConsoleMessages) GWT
051: .create(ConsoleMessages.class)).no();
052:
053: private static final String OK_BUTTON = ((ConsoleMessages) GWT
054: .create(ConsoleMessages.class)).OK();
055:
056: private int result;
057:
058: private VerticalPanel confirmPanel = new VerticalPanel();
059:
060: // private DisclosurePanel errorContainer = new DisclosurePanel();
061: private HorizontalPanel messageTextPanel = new HorizontalPanel();
062:
063: private HorizontalPanel widgetPanel = new HorizontalPanel();
064:
065: private HorizontalPanel ButtonsPanel = new HorizontalPanel();
066:
067: private Label messageTextLabel = new Label();
068:
069: String messageTextContent;
070:
071: ConsoleImageBundle images = (ConsoleImageBundle) GWT
072: .create(ConsoleImageBundle.class);
073:
074: Image messageImage;
075:
076: public ConfirmationViewDialog(String messageText,
077: Widget additionalWidget, String button1, String button2,
078: String button3, String button4, String button5) {
079: super (false, true);
080: initContent();
081: setMessage(messageText);
082: setStyle();
083: setWidget(confirmPanel);
084: initContent(additionalWidget);
085:
086: initButtonsPanels(button1, button2, button3, button4, button5);
087: }
088:
089: private void initButtonsPanels(String button1, String button2,
090: String button3, String button4, String button5) {
091:
092: if (button1 != null) {
093: PushButton button = new PushButton(button1);
094: button.addClickListener(new ButtonCLickListener());
095: ButtonsPanel.add(button);
096: }
097:
098: if (button2 != null) {
099: PushButton button = new PushButton(button2);
100: ButtonsPanel.add(button);
101: }
102:
103: if (button3 != null) {
104: PushButton button = new PushButton(button3);
105: ButtonsPanel.add(button);
106: }
107:
108: if (button4 != null) {
109: PushButton button = new PushButton(button4);
110: ButtonsPanel.add(button);
111: }
112:
113: if (button5 != null) {
114: PushButton button = new PushButton(button5);
115: ButtonsPanel.add(button);
116: }
117: confirmPanel.add(ButtonsPanel);
118: }
119:
120: private void setMessage(String messageTextContent) {
121: this .messageTextContent = messageTextContent;
122: }
123:
124: private void setStyle() {
125: // TODO Auto-generated method stub
126:
127: }
128:
129: private void initContent(Widget additionalWidget) {
130:
131: messageTextLabel.setText(messageTextContent);
132: messageTextLabel.setWordWrap(true);
133: messageTextLabel.setWidth("100%");
134: messageTextPanel.add(messageImage);
135: messageTextPanel.add(messageTextLabel);
136: messageTextPanel.setCellHorizontalAlignment(messageImage,
137: HasHorizontalAlignment.ALIGN_LEFT);
138: messageTextPanel.setCellHorizontalAlignment(messageTextLabel,
139: HasHorizontalAlignment.ALIGN_RIGHT);
140:
141: messageTextPanel.setCellVerticalAlignment(messageImage,
142: HasVerticalAlignment.ALIGN_MIDDLE);
143: messageTextPanel.setCellVerticalAlignment(messageTextLabel,
144: HasVerticalAlignment.ALIGN_MIDDLE);
145:
146: confirmPanel.add(messageTextPanel);
147: initWidgetPanel(additionalWidget);
148: // final PushButton okButton = new PushButton(" "
149: // + ((ConsoleMessages) GWT.create(ConsoleMessages.class)).OK()
150: // + " ");
151: // okButton.setWidth("100px");
152: // okButton.addClickListener(new ClickListener() {
153: // public void onClick(Widget w) {
154: // close();
155: // }
156: // });
157: // confirmPanel.add(okButton);
158: // confirmPanel.setCellHorizontalAlignment(okButton,
159: // HasHorizontalAlignment.ALIGN_CENTER);
160:
161: }
162:
163: private void initWidgetPanel(Widget addWidget) {
164: if (addWidget != null) {
165: widgetPanel.add(addWidget);
166: confirmPanel.add(widgetPanel);
167: } else {
168: // don't add the panel
169: }
170:
171: }
172:
173: //
174: private void initContent() {
175: // if (iconStyle == 0) {
176: // get info icon
177: setText(((ConsoleMessages) GWT.create(ConsoleMessages.class))
178: .confirmation());
179: messageImage = images.informationImage().createImage();
180: }
181:
182: public static int showOkCancel(String question, Widget parentWidget) {
183:
184: return showCustomButtons(question, null, OK_BUTTON,
185: CANCEL_BUTTON, null, null, null, parentWidget);
186: }
187:
188: public static int showYesNo(String question, Widget parentWidget) {
189: return showCustomButtons(question, null, YES_BUTTON, NO_BUTTON,
190: null, null, null, parentWidget);
191: }
192:
193: public static int showYesNoCancel(String question,
194: Widget parentWidget) {
195: return showCustomButtons(question, null, YES_BUTTON, NO_BUTTON,
196: CANCEL_BUTTON, null, null, parentWidget);
197: }
198:
199: public static int showCustomButtons(String question,
200: Widget additionalWidget, String button1, String button2,
201: String button3, String button4, String button5,
202: Widget parentWidget) {
203:
204: ConfirmationViewDialog dialog = new ConfirmationViewDialog(
205: question, additionalWidget, button1, button2, button3,
206: button4, button5);
207: dialog.show(parentWidget);
208: return dialog.getResult();
209: }
210:
211: public void show(Widget w) {
212: setPopupPosition(w.getAbsoluteLeft() + w.getOffsetWidth() / 4,
213: w.getAbsoluteTop() + w.getOffsetHeight() / 4);
214: show();
215: }
216:
217: class ButtonCLickListener implements ClickListener {
218: public void onClick(Widget sender) {
219: if (((ConsoleMessages) GWT.create(ConsoleMessages.class))
220: .yes().equals(((Button) sender).getText()))
221: ConfirmationViewDialog.this .result = 1;
222: else if (((ConsoleMessages) GWT
223: .create(ConsoleMessages.class)).no().equals(
224: ((Button) sender).getText()))
225: ConfirmationViewDialog.this .result = 2;
226: else if (((ConsoleMessages) GWT
227: .create(ConsoleMessages.class)).OK().equals(
228: ((Button) sender).getText()))
229: ConfirmationViewDialog.this .result = 3;
230: else if (((ConsoleMessages) GWT
231: .create(ConsoleMessages.class)).Cancel().equals(
232: ((Button) sender).getText()))
233: ConfirmationViewDialog.this .result = 4;
234: // Integer
235: // .parseInt(((PushButton) sender).getTitle());
236: ConfirmationViewDialog.this .hide();
237: }
238: }
239:
240: public int getResult() {
241: return result;
242: }
243:
244: }
|