KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.event.*;
18 import javax.swing.*;
19 import java.sql.*;
20 import java.util.*;
21
22 import org.compiere.util.*;
23 import org.compiere.process.*;
24
25 /**
26  * User Start Reports & Processes directly (from AMenu).
27  * Lists user startable processes and reports and starts tem via ProcessCtl
28  *
29  * @author Jorg Janke
30  * @version $Id: ProcessStart.java,v 1.12 2003/08/04 03:55:24 jjanke Exp $
31  */

32 public class ProcessStart extends JFrame
33     implements ActionListener, ASyncProcess
34 {
35     /**
36      * Show executable Processes and Reports
37      */

38     public ProcessStart()
39     {
40         super(Msg.getMsg(Env.getCtx(), "StartReports"));
41         m_WindowNo = Env.createWindowNo (this);
42
43         setIconImage(org.compiere.Compiere.getImage16());
44         loadProcess();
45         try
46         {
47             jbInit();
48             setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
49         }
50         catch(Exception JavaDoc e)
51         {
52             Log.error("ProcessStart", e);
53         }
54         pack();
55         setVisible(true);
56     } // ProcessStart
57

58     //
59
private int m_WindowNo;
60     private boolean m_isLocked = false;
61
62     private JPanel mainPanel = new JPanel();
63     private JList processList;
64     private BorderLayout mainLayout = new BorderLayout();
65     private ConfirmPanel confirmPanel = new ConfirmPanel(true);
66
67     /**
68      * Static Frame Init
69      * @throws Exception
70      */

71     private void jbInit() throws Exception JavaDoc
72     {
73         mainPanel.setLayout(mainLayout);
74         mainPanel.setBorder(BorderFactory.createLoweredBevelBorder());
75         processList.setPreferredSize(new Dimension(300, 150));
76         this.getContentPane().add(mainPanel, BorderLayout.CENTER);
77         mainPanel.add(processList, BorderLayout.CENTER);
78         mainPanel.add(confirmPanel, BorderLayout.SOUTH);
79         //
80
confirmPanel.addActionListener(this);
81     } // jbInit
82

83     /**
84      * Close Window
85      */

86     public void dispose()
87     {
88         Env.clearWinContext(m_WindowNo);
89         removeAll();
90         super.dispose();
91     } // cancel
92

93     /**
94      * ActionListener
95      * @param e event
96      */

97     public void actionPerformed(ActionEvent e)
98     {
99         if (e.getActionCommand().equals(ConfirmPanel.A_OK))
100         {
101             Process JavaDoc p = (Process JavaDoc)processList.getSelectedValue();
102             startProcess (p.AD_Process_ID, p.Name, 0);
103         }
104         else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
105             dispose();
106     } // actionPerformed
107

108
109     /**
110      * Load List
111      */

112     private void loadProcess()
113     {
114         String JavaDoc SQL = "SELECT * FROM AD_Process WHERE IsActive='Y'";
115         if (!Env.getContext(Env.getCtx(), "#AD_User_ID").equals("0"))
116             SQL += " AND IsUserStartable='Y'";
117         Vector v = new Vector();
118         try
119         {
120             Statement stmt = DB.createStatement();
121             ResultSet rs = stmt.executeQuery(SQL);
122             while (rs.next())
123             {
124                 String JavaDoc Name = rs.getString("Name");
125                 int ID = rs.getInt("AD_Process_ID");
126                 boolean IsReport = rs.getString("IsReport").equals("Y");
127                 Process JavaDoc p = new Process JavaDoc(ID, Name, IsReport);
128                 v.addElement(p);
129             }
130             rs.close();
131             stmt.close();
132         }
133         catch (SQLException e)
134         {
135             Log.error("ProcessStart.loadProcess", e);
136             return;
137         }
138         processList = new JList(v);
139     } // loadProcess
140

141     /**
142      * Start Process
143      * @param AD_Process_ID AD_Process_ID
144      * @param Name Name
145      * @param entityID ID
146      */

147     private void startProcess (int AD_Process_ID, String JavaDoc Name, int entityID)
148     {
149         Log.trace(Log.l1_User, "ProcessStart.startProcess " + Name);
150         //
151
ProcessInfo pi = new ProcessInfo (Name, AD_Process_ID, entityID);
152         ProcessCtl.process (this, m_WindowNo, pi); // calles lockUI,..
153
} // startProcess
154

155
156     /**
157      * Lock User Interface
158      * Called from the Worker before processing
159      * @param pi process info
160      */

161     public void lockUI (ProcessInfo pi)
162     {
163         confirmPanel.getOKButton().setEnabled(false);
164         this.setEnabled(false);
165         m_isLocked = true;
166     } // lockUI
167

168     /**
169      * Unlock User Interface.
170      * Called from the Worker when processing is done
171      * @param pi process info
172      */

173     public void unlockUI (ProcessInfo pi)
174     {
175         ProcessInfoUtil.setLogFromDB(pi);
176         ADialog.info(m_WindowNo, this, pi.getTitle(), pi.getLogInfo());
177         //
178
confirmPanel.getOKButton().setEnabled(false);
179         this.setEnabled(true);
180         m_isLocked = false;
181     } // unlockUI
182

183     /**
184      * Is the UI locked (Internal method)
185      * @return true, if UI is locked
186      */

187     public boolean isUILocked()
188     {
189         return m_isLocked;
190     } // isLoacked
191

192     /**
193      * Method to be executed async.
194      * Called from the ASyncProcess worker
195      * @param pi process info
196      */

197     public void executeASync (ProcessInfo pi)
198     {
199         Log.trace(Log.l3_Util, "ProcessStart.executeASync");
200     } // executeASync
201

202
203
204     /**
205      * Process Info
206      */

207     class Process
208     {
209         public Process(int AD_Process_ID, String JavaDoc Name, boolean IsReport)
210         {
211             this.AD_Process_ID = AD_Process_ID;
212             this.Name = Name;
213             this.IsReport = IsReport;
214         } // Process
215

216         public int AD_Process_ID;
217         public String JavaDoc Name;
218         public boolean IsReport;
219
220         public String JavaDoc toString()
221         {
222             return Name;
223         }
224     }
225 } // ProcessStart
226
Popular Tags