KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 import java.sql.*;
21 import java.util.*;
22 import java.text.*;
23
24 import org.compiere.print.*;
25 import org.compiere.util.*;
26 import org.compiere.plaf.*;
27 import org.compiere.swing.*;
28 import org.compiere.process.*;
29
30 /**
31  * Dialog to Start process.
32  * Displays information about the process
33  * and lets the user decide to start it
34  * and displays results (optionally print them).
35  * Calls ProcessCtl to execute.
36  *
37  * @author Jorg Janke
38  * @version $Id: ProcessDialog.java,v 1.24 2003/08/06 06:50:47 jjanke Exp $
39  */

40 public class ProcessDialog extends JFrame
41     implements ActionListener, ASyncProcess
42 {
43     /**
44      * Dialog to start Process
45      *
46      * @param AD_Process_ID process
47      * @param isSOTrx is sales trx
48      */

49     public ProcessDialog (int AD_Process_ID, boolean isSOTrx)
50     {
51         super();
52         Log.trace(Log.l1_User, "ProcessDialog - Process=" + AD_Process_ID + "; SOTrx=" + isSOTrx);
53         enableEvents(AWTEvent.WINDOW_EVENT_MASK);
54         m_AD_Process_ID = AD_Process_ID;
55         m_WindowNo = Env.createWindowNo (this);
56         Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N");
57         try
58         {
59             jbInit();
60         }
61         catch(Exception JavaDoc ex)
62         {
63             Log.error("ProcessDialog", ex);
64         }
65     } // ProcessDialog
66

67     private int m_AD_Process_ID;
68     private int m_WindowNo;
69     private String JavaDoc m_Name = null;
70     private boolean m_IsReport = false;
71     private int[] m_ids = null;
72     private boolean m_isLocked = false;
73     private StringBuffer JavaDoc m_messageText = new StringBuffer JavaDoc();
74     //
75

76     private CPanel dialog = new CPanel();
77     private BorderLayout mainLayout = new BorderLayout();
78     private CPanel southPanel = new CPanel();
79     private JButton bOK = new JButton();
80     private FlowLayout southLayout = new FlowLayout();
81 // private CText message = new CText();
82
private JEditorPane message = new JEditorPane();
83     private JScrollPane messagePane = new JScrollPane(message);
84     private CButton bPrint = new CButton();
85
86     /**
87      * Static Layout
88      * @throws Exception
89      */

90     private void jbInit() throws Exception JavaDoc
91     {
92         CompiereColor.setBackground(this);
93         this.setIconImage(org.compiere.Compiere.getImage16());
94         //
95
dialog.setLayout(mainLayout);
96         bOK.setHorizontalTextPosition(SwingConstants.LEFT);
97         bOK.setIcon(Env.getImageIcon("Ok24.gif"));
98         bOK.addActionListener(this);
99         bPrint.setIcon(Env.getImageIcon("Print24.gif"));
100         bPrint.setMargin(new Insets(2, 2, 2, 2));
101         bPrint.addActionListener(this);
102         //
103
southPanel.setLayout(southLayout);
104         southLayout.setAlignment(FlowLayout.RIGHT);
105         dialog.setPreferredSize(new Dimension(500, 150));
106         message.setContentType("text/html");
107         message.setEditable(false);
108         message.setBackground(CompierePLAF.getFieldBackground_Inactive());
109         getContentPane().add(dialog);
110         dialog.add(southPanel, BorderLayout.SOUTH);
111         southPanel.add(bPrint, null);
112         southPanel.add(bOK, null);
113         dialog.add(messagePane, BorderLayout.CENTER);
114     } // jbInit
115

116     /**
117      * Dispose
118      */

119     public void dispose()
120     {
121         Env.clearWinContext(m_WindowNo);
122         super.dispose();
123     } // dispose
124

125
126     /**
127      * Dynamic Init
128      * @return true, if there is something to process (start from menu)
129      */

130     public boolean init()
131     {
132         Log.trace(Log.l3_Util, "ProcessDialog.init");
133         //
134
boolean trl = !Env.isBaseLanguage(Env.getCtx(), "AD_Process");
135         String JavaDoc SQL = "SELECT Name, Description, Help, IsReport "
136                 + "FROM AD_Process "
137                 + "WHERE AD_Process_ID=?";;
138         if (trl)
139             SQL = "SELECT t.Name, t.Description, t.Help, p.IsReport "
140                 + "FROM AD_Process p, AD_Process_Trl t "
141                 + "WHERE p.AD_Process_ID=t.AD_Process_ID"
142                 + " AND p.AD_Process_ID=? AND t.AD_Language=?";
143         try
144         {
145             PreparedStatement pstmt = DB.prepareStatement(SQL);
146             pstmt.setInt(1, m_AD_Process_ID);
147             if (trl)
148                 pstmt.setString(2, Env.getAD_Language(Env.getCtx()));
149             ResultSet rs = pstmt.executeQuery();
150             if (rs.next())
151             {
152                 m_Name = rs.getString(1);
153                 m_IsReport = rs.getString(4).equals("Y");
154                 //
155
m_messageText.append("<b>");
156                 String JavaDoc s = rs.getString(2); // Description
157
if (rs.wasNull())
158                     m_messageText.append(Msg.getMsg(Env.getCtx(), "StartProcess?"));
159                 else
160                     m_messageText.append(s);
161                 m_messageText.append("</b>");
162                 s = rs.getString(3); // Help
163
if (!rs.wasNull())
164                     m_messageText.append("<p>").append(s).append("</p>");
165             }
166
167             rs.close();
168             pstmt.close();
169         }
170         catch (SQLException e)
171         {
172             Log.error("ProcessDialog.init", e);
173             return false;
174         }
175
176         if (m_Name == null)
177             return false;
178         //
179
this.setTitle(m_Name);
180         message.setText(m_messageText.toString());
181         bOK.setText(Msg.getMsg(Env.getCtx(), "Start"));
182
183         /** Start Reports w/o asking
184         if (m_IsReport)
185         {
186             bOK.doClick();
187             return false; // don't show
188         }
189         **/

190         return true;
191     } // init
192

193     /**
194      * ActionListener (Start)
195      * @param e ActionEvent
196      */

197     public void actionPerformed (ActionEvent e)
198     {
199         if (e.getSource() == bOK)
200         {
201             if (bOK.getText().length() == 0)
202                 dispose();
203             else
204             {
205                 // Similar to APanel.actionButton
206
ProcessInfo pi = new ProcessInfo(m_Name, m_AD_Process_ID, 0);
207                 m_messageText.append("<p>** ").append(m_Name).append("</p>");
208                 message.setText(m_messageText.toString());
209                 ProcessCtl.process(this, m_WindowNo, pi);
210             }
211         }
212
213         else if (e.getSource() == bPrint)
214             printScreen();
215     } // actionPerformed
216

217
218     /**
219      * Lock User Interface
220      * Called from the Worker before processing
221      * @param pi process info
222      */

223     public void lockUI (ProcessInfo pi)
224     {
225         bOK.setText("");
226         bOK.setEnabled(false);
227         this.setEnabled(false);
228         m_isLocked = true;
229     } // lockUI
230

231     /**
232      * Unlock User Interface.
233      * Called from the Worker when processing is done
234      * @param pi process info
235      */

236     public void unlockUI (ProcessInfo pi)
237     {
238         ProcessInfoUtil.setLogFromDB(pi);
239         m_messageText.append("<p><font color=\"").append(pi.isError() ? "#FF0000" : "#0000FF").append("\">** ")
240             .append(pi.getSummary())
241             .append("</font></p>");
242         m_messageText.append(pi.getLogInfo(true));
243         message.setText(m_messageText.toString());
244         message.setCaretPosition(message.getDocument().getLength()); // scroll down
245
m_ids = pi.getIDs();
246         //
247
bOK.setEnabled(true);
248         this.setEnabled(true);
249         m_isLocked = false;
250         //
251
afterProcessTask();
252         // Close automatically
253
if (m_IsReport && !pi.isError())
254             bOK.doClick();
255     } // unlockUI
256

257     /**
258      * Is the UI locked (Internal method)
259      * @return true, if UI is locked
260      */

261     public boolean isUILocked()
262     {
263         return m_isLocked;
264     } // isLoacked
265

266     /**
267      * Method to be executed async.
268      * Called from the ASyncProcess worker
269      * @param pi process info
270      */

271     public void executeASync (ProcessInfo pi)
272     {
273         Log.trace(Log.l3_Util, "ProcessDialog.executeASync");
274     } // executeASync
275

276     /*************************************************************************/
277
278     /**
279      * Optional Processing Task
280      */

281     private void afterProcessTask()
282     {
283         // something to do?
284
if (m_ids != null && m_ids.length > 0)
285         {
286             Log.trace(Log.l3_Util, "ProcessDialog.afterProcessTask");
287             // Print invoices
288
if (m_AD_Process_ID == 119)
289                 printInvoices();
290             else if (m_AD_Process_ID == 118)
291                 printShipments();
292         }
293
294     } // afterProcessTask
295

296     /*************************************************************************/
297
298     /**
299      * Print Shipments
300      */

301     private void printShipments()
302     {
303         if (m_ids == null)
304             return;
305         if (!ADialog.ask(m_WindowNo, this, "PrintShipments"))
306             return;
307         m_messageText.append("<p>").append(Msg.getMsg(Env.getCtx(), "PrintShipments")).append("</p>");
308         message.setText(m_messageText.toString());
309         do
310         {
311             // Loop through all items
312
for (int i = 0; i < m_ids.length; i++)
313             {
314                 int M_InOut_ID = m_ids[i];
315                 ReportCtl.startDocumentPrint(ReportCtl.SHIPMENT, M_InOut_ID, true);
316             }
317         }
318         while (!ADialog.ask(m_WindowNo, this, "PrintoutOK?"));
319     } // printInvoices
320

321     /**
322      * Print Invoices
323      */

324     private void printInvoices()
325     {
326         if (m_ids == null)
327             return;
328         if (!ADialog.ask(m_WindowNo, this, "PrintInvoices"))
329             return;
330         m_messageText.append("<p>").append(Msg.getMsg(Env.getCtx(), "PrintInvoices")).append("</p>");
331         message.setText(m_messageText.toString());
332         do
333         {
334             // Loop through all items
335
for (int i = 0; i < m_ids.length; i++)
336             {
337                 int AD_Invoice_ID = m_ids[i];
338                 ReportCtl.startDocumentPrint(ReportCtl.INVOICE, AD_Invoice_ID, true);
339             }
340         }
341         while (!ADialog.ask(m_WindowNo, this, "PrintoutOK?"));
342     } // printInvoices
343

344     /**
345      * Print Screen
346      */

347     private void printScreen()
348     {
349         PrintScreenPainter.printScreen (this);
350     } // printScreen
351

352 } // ProcessDialog
353
Popular Tags