KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > ActivityChecker


1 package sellwin.gui;
2
3 import sellwin.domain.*;
4 import sellwin.utils.*;
5 import javax.swing.*;
6 import java.util.*;
7
8 // SellWin http://sourceforge.net/projects/sellwincrm
9
//Contact support@open-app.com for commercial help with SellWin
10
//This software is provided "AS IS", without a warranty of any kind.
11

12 /**
13  * This class is run in a separate thread in the
14  * Swing GUi to check for alarms associated with
15  * this user's set of activities across all
16  * of the user's opportunities and for alarms
17  * set by other users where this user is a
18  * a member of the group of recipients.
19  */

20 public class ActivityChecker extends Thread JavaDoc {
21     private Whiteboard wb;
22     private Runnable JavaDoc runnable;
23     private static final int ACT_CHK_TIME = 1000 * 60 * 5; //5 minutes
24
private ArrayList alarms=null;
25     
26     /**
27      * this method is called by Swing as it processes
28      * it's event queue which gets populated by the invokeLater()
29      * below
30      */

31     public ActivityChecker() {
32
33         wb = MainWindow.getWhiteboard();
34
35         runnable = new Runnable JavaDoc() {
36             public void run() {
37                 Activity alarm;
38                 AlarmDialog ad;
39                 LogWrite.write("ActivityChecker sees "+ alarms.size() + " alarms");
40                 for (int i=0;i<alarms.size();i++) {
41                     alarm = (Activity)alarms.get(i);
42                     ad = new AlarmDialog(MainWindow.getMainParent(), false, alarm);
43                     ad.show();
44                 }
45             }
46         };
47     }
48
49     /**
50      * the main entry point for this Thread, an infinite loop that
51      * wakes up every so often (ACT_CHK_TIME), does some checking to
52      * see if we need to process some activities, and then queue a
53      * request to Swing's internal event queue processing mechanism,
54      * then go back to waiting for the next wakeup.
55     */

56     public void run() {
57         try {
58             while (true) {
59                 sleep(ACT_CHK_TIME);
60                 try {
61                     alarms = wb.getAlarms();
62                 } catch (AngError x) {
63                     ErrorHandler.show(MainWindow.getMainParent(), x);
64                 }
65                 SwingUtilities.invokeLater(runnable);
66             }
67         } catch (Exception JavaDoc e) {
68             ErrorHandler.show(MainWindow.getMainParent(), e);
69         }
70     }
71
72 }
73         
74
Popular Tags