View Javadoc

1   /*
2    * Created on Jun 5, 2006 by scytacki
3    *
4    * Copyright (c) 2006 Regents of the University of California (Regents). Created
5    * by TELS, Graduate School of Education, University of California at Berkeley.
6    *
7    * This software is distributed under the GNU Lesser General Public License, v2.
8    *
9    * Permission is hereby granted, without written agreement and without license
10   * or royalty fees, to use, copy, modify, and distribute this software and its
11   * documentation for any purpose, provided that the above copyright notice and
12   * the following two paragraphs appear in all copies of this software.
13   *
14   * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16   * PURPOSE. THE SOFTWAREAND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
17   * HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
18   * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
19   *
20   * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
21   * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
22   * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
23   * REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24   */
25  
26  package net.sf.sail.core.service.impl;
27  
28  import javax.swing.ProgressMonitor;
29  
30  import net.sf.sail.core.beans.SessionContext;
31  import net.sf.sail.core.bundle.Bundle;
32  import net.sf.sail.core.service.ServiceContext;
33  import net.sf.sail.core.service.SessionLifecycleListener;
34  import net.sf.sail.core.service.SessionManager;
35  
36  /**
37   * It does not register any service, but consumes service
38   * 
39   * @author scytacki
40   * AUDIT07-
41   */
42  public class SessionLoadMonitor implements Bundle, SessionLifecycleListener {
43  	ProgressMonitor progressMonitor;
44  
45  	/**
46  	 * @see net.sf.sail.core.bundle.Bundle#registerServices(java.beans.beancontext.BeanContextServices)
47  	 */
48  	public void registerServices(ServiceContext serviceContext) {
49  		// no services to register
50  	}
51  
52  	/**
53  	 * This actually show the progress bar. listens for session events. Intialized before curnit is downloaded.
54  	 * 
55  	 * @param serviceContext - the service context
56  	 * 
57  	 */
58  	public void initializeBundle(ServiceContext serviceContext) {
59  		// look up the SessionManager and add ourselves.
60  		SessionManager manager = (SessionManager)
61  		serviceContext.getService(SessionManager.class);
62  		manager.addSessionLifecycleListener(this);
63  	}
64  
65  	/**
66  	 * Creates progress monitor and shows it.
67  	 * 
68  	 *  @param SessionManager sessionManager - the session manager
69  	 */
70  	public void sessionStart(SessionManager manager) {
71  		progressMonitor = new ProgressMonitor(null,
72  				"Launching Session", "", 0, 4);
73  		progressMonitor.setNote("Loading curnit");
74  
75  		// we want this to popup immediately.
76  		// the default is 2 seconds.
77  		progressMonitor.setMillisToDecideToPopup(0);
78  		progressMonitor.setMillisToPopup(0);
79  
80  		// This has to occur after the millis settings because
81  		// calling this method is when the millis are decided
82  		progressMonitor.setProgress(1);
83  		
84  
85  	}
86  
87  	/* (non-Javadoc)
88  	 * @see net.sf.sail.core.service.SessionLifecycleListener#sessionContextCreated(net.sf.sail.core.service.SessionManager, net.sf.sail.core.beans.SessionContext)
89  	 */
90  	public void sessionContextCreated(SessionManager manager,
91  			SessionContext context) {
92  		progressMonitor.setProgress(2);
93  		progressMonitor.setNote("Initiating session");
94  	}
95  
96  	/* (non-Javadoc)
97  	 * @see net.sf.sail.core.service.SessionLifecycleListener#sessionContextIntiated(net.sf.sail.core.service.SessionManager, net.sf.sail.core.beans.SessionContext)
98  	 */
99  	public void sessionContextIntiated(SessionManager manager,
100 			SessionContext context) {
101 		progressMonitor.setProgress(3);
102 		progressMonitor.setNote("Starting session");
103 	}
104 
105 	/* (non-Javadoc)
106 	 * @see net.sf.sail.core.service.SessionLifecycleListener#sessionContextStarted(net.sf.sail.core.service.SessionManager, net.sf.sail.core.beans.SessionContext)
107 	 */
108 	public void sessionContextStarted(SessionManager manager,
109 			SessionContext context) {
110 		progressMonitor.setProgress(4);
111 	}
112 
113 	/* (non-Javadoc)
114 	 * @see net.sf.sail.core.service.SessionLifecycleListener#sessionContextStopped(net.sf.sail.core.service.SessionManager, net.sf.sail.core.beans.SessionContext)
115 	 */
116 	public void sessionContextStopped(SessionManager manager,
117 			SessionContext context) {
118 		// TODO Auto-generated method stub
119 
120 	}
121 
122 }