KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > ASyncWorker


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.util;
15
16 import javax.swing.*;
17
18 import org.compiere.process.*;
19
20 /**
21  * ASync Worker for starting methods in classes implementing ASyncProcess
22  *
23  * @author Jorg Janke
24  * @version $Id: ASyncWorker.java,v 1.4 2003/02/15 06:31:15 jjanke Exp $
25  */

26 public class ASyncWorker extends Thread JavaDoc
27 {
28     /**
29      * Execute method Synchronously
30      * @param parent parent
31      * @param pi process info
32      * @return result
33      */

34     public static ProcessInfo executeSync (ASyncProcess parent, ProcessInfo pi)
35     {
36         ASyncWorker worker = new ASyncWorker (parent, pi);
37         worker.start();
38         try
39         {
40             worker.join();
41         }
42         catch (InterruptedException JavaDoc e)
43         {
44             Log.error("ASyncWorker.executeSync", e);
45         }
46         return worker.getResult();
47     } // executeSync
48

49     /**
50      * Constructor
51      * @param parent Parent Process
52      * @param pi process info
53      */

54     public ASyncWorker (ASyncProcess parent, ProcessInfo pi)
55     {
56         m_parent = parent;
57         m_pi = pi;
58     } // ASuncWorker
59

60     private ProcessInfo m_pi;
61     private ASyncProcess m_parent;
62
63     /**
64      * The Worker Method
65      */

66     public void run()
67     {
68         SwingUtilities.invokeLater(new Runnable JavaDoc()
69         {
70             public void run()
71             {
72                 m_parent.lockUI(m_pi);
73             }
74         });
75
76         //
77
m_parent.executeASync(m_pi);
78         //
79

80         SwingUtilities.invokeLater(new Runnable JavaDoc()
81         {
82             public void run()
83             {
84                 m_parent.unlockUI (m_pi);
85             }
86         });
87     } // run
88

89     /**
90      * Get Result (usually not used as result is returned via unlockUI
91      * @return result
92      */

93     public ProcessInfo getResult()
94     {
95         return m_pi;
96     } // getResult
97

98 } // ASyncWorker
99
Popular Tags