1 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 30 31 public final class ADialog 32 { 33 34 public static boolean showDialog = true; 35 36 44 public static void info (int WindowNo, Container c, String clearHeading, String clearMessage, String clearText) 45 { 46 Log.trace(Log.l1_User, "Dialog.info: " + clearHeading, 47 clearMessage + " " + clearText); 48 String out = clearMessage; 49 if (clearText != null && !clearText.equals("")) 50 out += "\n" + clearText; 51 Window parent = Env.getParent(c); 53 if (parent == null) 54 parent = Env.getWindow(WindowNo); 55 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", clearHeading, JOptionPane.INFORMATION_MESSAGE); 74 } 76 83 public static void info (int WindowNo, Container c, String AD_Message, String msg) 84 { 85 Log.trace(Log.l1_User, "Dialog.info: " + AD_Message, msg); 86 Properties ctx = Env.getCtx(); 87 StringBuffer out = new StringBuffer (); 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 Window parent = Env.getParent(c); 94 if (parent == null) 95 parent = Env.getWindow(WindowNo); 96 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", Env.getHeader(ctx, WindowNo), JOptionPane.INFORMATION_MESSAGE); 115 } 117 123 public static void info (int WindowNo, Container c, String AD_Message) 124 { 125 info (WindowNo, c, AD_Message, null); 126 } 128 129 130 131 138 public static void warn (int WindowNo, Container c, String AD_Message, String msg) 139 { 140 Log.trace(Log.l1_User, "Dialog.warn: " + AD_Message, msg); 141 Properties ctx = Env.getCtx(); 142 StringBuffer out = new StringBuffer (); 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 Window parent = Env.getParent(c); 149 if (parent == null) 150 parent = Env.getWindow(WindowNo); 151 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", Env.getHeader(ctx, WindowNo), JOptionPane.WARNING_MESSAGE); 170 } 172 178 public static void warn (int WindowNo, Container c, String AD_Message) 179 { 180 warn (WindowNo, c, AD_Message, null); 181 } 183 184 185 192 public static void error (int WindowNo, Container c, String AD_Message, String 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 out = new StringBuffer (); 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 Window parent = Env.getParent(c); 205 if (parent == null) 206 parent = Env.getWindow(WindowNo); 207 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", Env.getHeader(ctx, WindowNo), JOptionPane.ERROR_MESSAGE); 226 } 228 234 public static void error (int WindowNo, Container c, String AD_Message) 235 { 236 error (WindowNo, c, AD_Message, null); 237 } 239 240 241 249 public static boolean ask (int WindowNo, Container c, String AD_Message, String msg) 250 { 251 Log.trace(Log.l1_User, "Dialog.ask: " + AD_Message, msg); 252 Properties ctx = Env.getCtx(); 253 StringBuffer out = new StringBuffer (); 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 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 [] optionsOC = {Msg.getMsg(ctx, "OK"), Msg.getMsg(ctx, "Cancel")}; 286 int i = JOptionPane.showOptionDialog(parent, 287 out.toString() + "\n", Env.getHeader(ctx, WindowNo), JOptionPane.DEFAULT_OPTION, 290 JOptionPane.QUESTION_MESSAGE, 291 null, 292 optionsOC, 293 optionsOC[0]); 294 retValue = i == 0; 295 } 296 return retValue; 297 } 299 306 public static boolean ask (int WindowNo, Container c, String AD_Message) 307 { 308 return ask (WindowNo, c, AD_Message, null); 309 } 311 312 313 319 public static void clear (int WindowNo, Container c, String ParseString) 320 { 321 Log.trace(Log.l1_User, "Dialog.clear: " + ParseString); 322 Properties ctx = Env.getCtx(); 323 String parse = Env.parseContext(ctx, WindowNo, ParseString, false); 324 if (parse.length() == 0) 325 parse = "ERROR parsing: " + ParseString; 326 Window parent = Env.getParent(c); 328 if (parent == null) 329 parent = Env.getWindow(WindowNo); 330 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", Env.getHeader(ctx, WindowNo), JOptionPane.INFORMATION_MESSAGE); 349 } 351 352 359 public static void clear (int WindowNo, Container c, String 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 } 368 373 public static void clear (String ParseString) 374 { 375 clear(0, null, ParseString); 376 } 378 386 public static void createSupportEMail(Dialog owner, String subject, String message) 387 { 388 Log.trace(Log.l3_Util, "ADialog.createSupportEMail"); 389 String to = Compiere.getSupportEMail(); 390 String from = EMailUtil.getEMail_User(Env.getCtx(), false); 391 StringBuffer myMessage = new StringBuffer (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 } 401 407 public static void createSupportEMail(Frame owner, String subject, String message) 408 { 409 Log.trace(Log.l3_Util, "ADialog.createSupportEMail"); 410 String to = Compiere.getSupportEMail(); 411 String from = EMailUtil.getEMail_User(Env.getCtx(), false); 412 StringBuffer myMessage = new StringBuffer (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 } 422 423 424 427 public static void beep() 428 { 429 Toolkit.getDefaultToolkit().beep(); 430 } 432 } | Popular Tags |