KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > ADialog


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import java.awt.*;
17 import javax.swing.*;
18 import java.awt.event.*;
19 import java.util.*;
20
21 import org.compiere.*;
22 import org.compiere.util.*;
23
24 /**
25  * Info Dialog Management
26  *
27  * @author Jorg Janke
28  * @version $Id: ADialog.java,v 1.13 2003/11/01 02:32:20 jjanke Exp $
29  */

30
31 public final class ADialog
32 {
33     /** Show ADialogADialog - if false use JOptionPane */
34     public static boolean showDialog = true;
35
36     /**
37      * Show plain message
38      * @param WindowNo Number of Window
39      * @param c Container (owner)
40      * @param clearHeading Translated Title of window
41      * @param clearMessage Translated message
42      * @param clearText Additional message
43      */

44     public static void info (int WindowNo, Container c, String JavaDoc clearHeading, String JavaDoc clearMessage, String JavaDoc clearText)
45     {
46         Log.trace(Log.l1_User, "Dialog.info: " + clearHeading,
47             clearMessage + " " + clearText);
48         String JavaDoc out = clearMessage;
49         if (clearText != null && !clearText.equals(""))
50             out += "\n" + clearText;
51         //
52
Window parent = Env.getParent(c);
53         if (parent == null)
54             parent = Env.getWindow(WindowNo);
55         //
56
if (showDialog && parent != null)
57         {
58             if (parent instanceof JFrame)
59                 new ADialogDialog ((JFrame)parent,
60                     clearHeading,
61                     out,
62                     JOptionPane.INFORMATION_MESSAGE);
63             else
64                 new ADialogDialog ((JDialog)parent,
65                     clearHeading,
66                     out,
67                     JOptionPane.INFORMATION_MESSAGE);
68         }
69         else
70             JOptionPane.showMessageDialog(parent,
71                 out + "\n", // message
72
clearHeading, // title
73
JOptionPane.INFORMATION_MESSAGE);
74     } // info
75

76     /**
77      * Show message with info icon
78      * @param WindowNo Number of Window
79      * @param c Container (owner)
80      * @param AD_Message Message to be translated
81      * @param msg Additional message
82      */

83     public static void info (int WindowNo, Container c, String JavaDoc AD_Message, String JavaDoc msg)
84     {
85         Log.trace(Log.l1_User, "Dialog.info: " + AD_Message, msg);
86         Properties ctx = Env.getCtx();
87         StringBuffer JavaDoc out = new StringBuffer JavaDoc();
88         if (AD_Message != null && !AD_Message.equals(""))
89             out.append(Msg.getMsg(ctx, AD_Message));
90         if (msg != null && msg.length() > 0)
91             out.append("\n").append(msg);
92         //
93
Window parent = Env.getParent(c);
94         if (parent == null)
95             parent = Env.getWindow(WindowNo);
96         //
97
if (showDialog && parent != null)
98         {
99             if (parent instanceof JFrame)
100                 new ADialogDialog ((JFrame)parent,
101                     Env.getHeader(ctx, WindowNo),
102                     out.toString(),
103                     JOptionPane.INFORMATION_MESSAGE);
104             else
105                 new ADialogDialog ((JDialog)parent,
106                     Env.getHeader(ctx, WindowNo),
107                     out.toString(),
108                     JOptionPane.INFORMATION_MESSAGE);
109         }
110         else
111             JOptionPane.showMessageDialog(parent,
112                 out.toString() + "\n", // message
113
Env.getHeader(ctx, WindowNo), // title
114
JOptionPane.INFORMATION_MESSAGE);
115     } // info
116

117     /**
118      * Show message with info icon
119      * @param WindowNo Number of Window
120      * @param c Container (owner)
121      * @param AD_Message Message to be translated
122      */

123     public static void info (int WindowNo, Container c, String JavaDoc AD_Message)
124     {
125         info (WindowNo, c, AD_Message, null);
126     } // info
127

128
129     /*************************************************************************/
130
131     /**
132      * Display warning with warning icon
133      * @param WindowNo Number of Window
134      * @param c Container (owner)
135      * @param AD_Message Message to be translated
136      * @param msg Additional message
137      */

138     public static void warn (int WindowNo, Container c, String JavaDoc AD_Message, String JavaDoc msg)
139     {
140         Log.trace(Log.l1_User, "Dialog.warn: " + AD_Message, msg);
141         Properties ctx = Env.getCtx();
142         StringBuffer JavaDoc out = new StringBuffer JavaDoc();
143         if (AD_Message != null && !AD_Message.equals(""))
144             out.append(Msg.getMsg(ctx, AD_Message));
145         if (msg != null && msg.length() > 0)
146             out.append("\n").append(msg);
147         //
148
Window parent = Env.getParent(c);
149         if (parent == null)
150             parent = Env.getWindow(WindowNo);
151         //
152
if (showDialog && parent != null)
153         {
154             if (parent instanceof JFrame)
155                 new ADialogDialog ((JFrame)parent,
156                     Env.getHeader(ctx, WindowNo),
157                     out.toString(),
158                     JOptionPane.WARNING_MESSAGE);
159             else
160                 new ADialogDialog ((JDialog)parent,
161                     Env.getHeader(ctx, WindowNo),
162                     out.toString(),
163                     JOptionPane.WARNING_MESSAGE);
164         }
165         else
166             JOptionPane.showMessageDialog(parent,
167                 out.toString() + "\n", // message
168
Env.getHeader(ctx, WindowNo), // title
169
JOptionPane.WARNING_MESSAGE);
170     } // warn (int, String)
171

172     /**
173      * Display warning with warning icon
174      * @param WindowNo Number of Window
175      * @param c Container (owner)
176      * @param AD_Message Message to be translated
177      */

178     public static void warn (int WindowNo, Container c, String JavaDoc AD_Message)
179     {
180         warn (WindowNo, c, AD_Message, null);
181     } // warn (int, String)
182

183     /*************************************************************************/
184
185     /**
186      * Display error with error icon
187      * @param WindowNo Number of Window
188      * @param c Container (owner)
189      * @param AD_Message Message to be translated
190      * @param msg Additional message
191      */

192     public static void error (int WindowNo, Container c, String JavaDoc AD_Message, String JavaDoc msg)
193     {
194         Log.trace(Log.l1_User, "Dialog.error: " + AD_Message, msg);
195         if (Log.isTraceLevel(10))
196             Trace.printStack();
197         Properties ctx = Env.getCtx();
198         StringBuffer JavaDoc out = new StringBuffer JavaDoc();
199         if (AD_Message != null && !AD_Message.equals(""))
200             out.append(Msg.getMsg(ctx, AD_Message));
201         if (msg != null && msg.length() > 0)
202             out.append("\n").append(msg);
203         //
204
Window parent = Env.getParent(c);
205         if (parent == null)
206             parent = Env.getWindow(WindowNo);
207         //
208
if (showDialog && parent != null)
209         {
210             if (parent instanceof JFrame)
211                 new ADialogDialog ((JFrame)parent,
212                     Env.getHeader(ctx, WindowNo),
213                     out.toString(),
214                     JOptionPane.ERROR_MESSAGE);
215             else if (parent instanceof JDialog)
216                 new ADialogDialog ((JDialog)parent,
217                     Env.getHeader(ctx, WindowNo),
218                     out.toString(),
219                     JOptionPane.ERROR_MESSAGE);
220         }
221         else
222             JOptionPane.showMessageDialog(Env.getWindow(WindowNo),
223                 out.toString() + "\n", // message
224
Env.getHeader(ctx, WindowNo), // title
225
JOptionPane.ERROR_MESSAGE);
226     } // error (int, String)
227

228     /**
229      * Display error with error icon
230      * @param WindowNo Number of Window
231      * @param c Container (owner)
232      * @param AD_Message Message to be translated
233      */

234     public static void error (int WindowNo, Container c, String JavaDoc AD_Message)
235     {
236         error (WindowNo, c, AD_Message, null);
237     } // error (int, String)
238

239     /*************************************************************************/
240
241     /**
242      * Ask Question with question icon and (OK) (Cancel) buttons
243      * @param WindowNo Number of Window
244      * @param c Container (owner)
245      * @param AD_Message Message to be translated
246      * @param msg Additional clear text message
247      * @returns true, if OK
248      */

249     public static boolean ask (int WindowNo, Container c, String JavaDoc AD_Message, String JavaDoc msg)
250     {
251         Log.trace(Log.l1_User, "Dialog.ask: " + AD_Message, msg);
252         Properties ctx = Env.getCtx();
253         StringBuffer JavaDoc out = new StringBuffer JavaDoc();
254         if (AD_Message != null && !AD_Message.equals(""))
255             out.append(Msg.getMsg(ctx, AD_Message));
256         if (msg != null && msg.length() > 0)
257             out.append("\n").append(msg);
258         //
259
Window parent = Env.getParent(c);
260         if (parent == null)
261             parent = Env.getWindow(WindowNo);
262
263         boolean retValue = false;
264         if (showDialog && parent != null)
265         {
266             if (parent instanceof JFrame)
267             {
268                 ADialogDialog d = new ADialogDialog ((JFrame)parent,
269                     Env.getHeader(ctx, WindowNo),
270                     out.toString(),
271                     JOptionPane.QUESTION_MESSAGE);
272                 retValue = d.getReturnCode() == ADialogDialog.A_OK;
273             }
274             else
275             {
276                 ADialogDialog d = new ADialogDialog ((JDialog)parent,
277                     Env.getHeader(ctx, WindowNo),
278                     out.toString(),
279                     JOptionPane.QUESTION_MESSAGE);
280                 retValue = d.getReturnCode() == ADialogDialog.A_OK;
281             }
282         }
283         else
284         {
285             Object JavaDoc[] optionsOC = {Msg.getMsg(ctx, "OK"), Msg.getMsg(ctx, "Cancel")};
286             int i = JOptionPane.showOptionDialog(parent,
287                 out.toString() + "\n", // message
288
Env.getHeader(ctx, WindowNo), // title
289
JOptionPane.DEFAULT_OPTION,
290                 JOptionPane.QUESTION_MESSAGE,
291                 null,
292                 optionsOC,
293                 optionsOC[0]);
294             retValue = i == 0;
295         }
296         return retValue;
297     } // ask
298

299     /**
300      * Ask Question with question icon and (OK) (Cancel) buttons
301      * @param WindowNo Number of Window
302      * @param c Container (owner)
303      * @param AD_Message Message to be translated
304      * @returns true, if OK
305      */

306     public static boolean ask (int WindowNo, Container c, String JavaDoc AD_Message)
307     {
308         return ask (WindowNo, c, AD_Message, null);
309     } // ask
310

311     /*************************************************************************/
312
313     /**
314      * Display parsed development info Message string
315      * @param WindowNo Number of parent window (if zero, no parent window)
316      * @param c Container (owner)
317      * @param ParseString String to be parsed
318      */

319     public static void clear (int WindowNo, Container c, String JavaDoc ParseString)
320     {
321         Log.trace(Log.l1_User, "Dialog.clear: " + ParseString);
322         Properties ctx = Env.getCtx();
323         String JavaDoc parse = Env.parseContext(ctx, WindowNo, ParseString, false);
324         if (parse.length() == 0)
325             parse = "ERROR parsing: " + ParseString;
326         //
327
Window parent = Env.getParent(c);
328         if (parent == null)
329             parent = Env.getWindow(WindowNo);
330         //
331
if (showDialog && parent != null)
332         {
333             if (parent instanceof JFrame)
334                 new ADialogDialog ((JFrame)parent,
335                     Env.getHeader(ctx, WindowNo),
336                     "=> " + parse,
337                     JOptionPane.INFORMATION_MESSAGE);
338             else
339                 new ADialogDialog ((JDialog)parent,
340                     Env.getHeader(ctx, WindowNo),
341                     "=> " + parse,
342                     JOptionPane.INFORMATION_MESSAGE);
343         }
344         else
345             JOptionPane.showMessageDialog(parent,
346                 "=> " + parse + "\n", // message
347
Env.getHeader(ctx, WindowNo), // title
348
JOptionPane.INFORMATION_MESSAGE);
349     } // clear
350

351
352     /**
353      * Display parsed development info Message string <x> if condition is true
354      * @param WindowNo Number of parent window (if zero, no parent window)
355      * @param c Container (owner)
356      * @param ParseString Parsed Message
357      * @param condition to print must be true and debugging enabled
358      */

359     public static void clear (int WindowNo, Container c, String JavaDoc ParseString, boolean condition)
360     {
361         if (!condition || Log.getTraceLevel() < 1)
362             return;
363         clear(WindowNo, c, ParseString);
364         if (WindowNo == 0)
365             Log.error("WIndowNo == 0");
366     } // clear
367

368     /**
369      * Display parsed development info Message string
370      * @param ParseString String to be parsed
371      * @deprecated
372      */

373     public static void clear (String JavaDoc ParseString)
374     {
375         clear(0, null, ParseString);
376     } // clear
377

378     /*************************************************************************
379
380     /**
381      * Create Support EMail
382      * @param owner owner
383      * @param subject subkect
384      * @param message message
385      */

386     public static void createSupportEMail(Dialog owner, String JavaDoc subject, String JavaDoc message)
387     {
388         Log.trace(Log.l3_Util, "ADialog.createSupportEMail");
389         String JavaDoc to = Compiere.getSupportEMail();
390         String JavaDoc from = EMailUtil.getEMail_User(Env.getCtx(), false);
391         //
392
StringBuffer JavaDoc myMessage = new StringBuffer JavaDoc(message);
393         myMessage.append("\n\n").append(AboutBox.getInfo());
394         Log.getInfo(myMessage, Env.getCtx());
395
396         EMailDialog emd = new EMailDialog(owner,
397             Msg.getMsg(Env.getCtx(), "EMailSupport"),
398             from, to, "Support: " + subject, myMessage.toString());
399     } // createEmail
400

401     /**
402      * Create Support EMail
403      * @param owner owner
404      * @param subject subkect
405      * @param message message
406      */

407     public static void createSupportEMail(Frame owner, String JavaDoc subject, String JavaDoc message)
408     {
409         Log.trace(Log.l3_Util, "ADialog.createSupportEMail");
410         String JavaDoc to = Compiere.getSupportEMail();
411         String JavaDoc from = EMailUtil.getEMail_User(Env.getCtx(), false);
412         //
413
StringBuffer JavaDoc myMessage = new StringBuffer JavaDoc(message);
414         myMessage.append("\n\n").append(AboutBox.getInfo());
415         Log.getInfo(myMessage, Env.getCtx());
416
417         EMailDialog emd = new EMailDialog(owner,
418             Msg.getMsg(Env.getCtx(), "EMailSupport"),
419             from, to, "Support: " + subject, myMessage.toString());
420     } // createEmail
421

422     /*************************************************************************/
423
424     /**
425      * Beep
426      */

427     public static void beep()
428     {
429         Toolkit.getDefaultToolkit().beep();
430     } // beep
431

432 } // Dialog
433
Popular Tags