View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.ui.client.widgets.progress;
17  
18  import java.util.LinkedList;
19  
20  import org.kuali.student.common.ui.client.widgets.KSLightBox;
21  
22  import com.google.gwt.user.client.ui.HorizontalPanel;
23  import com.google.gwt.user.client.ui.Image;
24  import com.google.gwt.user.client.ui.Label;
25  import com.google.gwt.user.client.ui.VerticalPanel;
26  
27  /**
28   * This class handles a static list of BlockingTasks, when a blocking task is added to the list, the blocking
29   * progress indicator is shown to the user and the user can perform no action until all blocking tasks are finished/removed.
30   *
31   * @author Bsmith
32   *
33   */
34  public class KSBlockingProgressIndicator{
35  
36      private static LinkedList<BlockingTask> tasks = new LinkedList<BlockingTask>();
37  
38  	private static final VerticalPanel mainPanel = new VerticalPanel();
39  	private static final VerticalPanel listPanel = new VerticalPanel();
40  
41  	private static KSLightBox popupIndicator;
42  
43  	private static boolean initialized = false;
44      private static int width = 200;
45      private static int height = 30;
46  	/**
47  	 * Initializes the blocking progress indicator.  This must be called before
48  	 * blocking task are added.
49  	 *
50  	 */
51  	public static void initialize(){
52  
53  
54  		mainPanel.add(listPanel);
55  
56  		//popupIndicator = new KSLightBox(false);
57  		popupIndicator = new KSLightBox(false);
58  		//popupIndicator.setShowCloseLink(false);
59  		
60  		popupIndicator.setWidget(mainPanel);
61  		popupIndicator.setSize(200, 30);
62  		popupIndicator.setGlassStyleName("KS-Blocking-Glass");
63  		popupIndicator.showButtons(false);
64  		setupDefaultStyle();
65  		initialized = true;
66  	}
67  
68  	/**
69  	 * Adds a blocking task to the queue.  When all tasks are removed, the indicator
70  	 * is no longer shown.
71  	 *
72  	 * @param task the task description to be added
73  	 */
74  	public static void addTask(BlockingTask task) {
75  		tasks.add(task);
76  		updateIndicator();
77  	}
78  
79  	/**
80  	 * Removes the blocking task from the queue
81  	 *
82  	 * @param task the task to be removed from the blocking task queue
83  	 */
84  	public static void removeTask(BlockingTask task) {
85  		tasks.remove(task);
86  		if (tasks.isEmpty()) {
87  			hideIndicator();
88  		} else {
89  			updateIndicator();
90  		}
91  	}
92      public static void setSize(final int w, final int h) {
93       width = w;
94       height = h;
95      }
96  	private static void updateIndicator() {
97  
98  		listPanel.clear();
99  		BlockingTask task = tasks.getLast();
100 		HorizontalPanel taskPanel = new HorizontalPanel();
101 	    Image Image = new Image("images/common/twiddler3.gif");
102 
103 		taskPanel.add(Image);
104 		taskPanel.add(new Label(task.getDescription()));
105 		listPanel.add(taskPanel);
106 		
107         showIndicator();		
108 	}
109 	private static void showIndicator(){
110 		if(!initialized){
111 			initialize();
112 		}
113 		popupIndicator.setSize(width, height);
114 		popupIndicator.show();
115 	}
116 
117 	private static void hideIndicator() {
118 		popupIndicator.hide();
119 	}
120 
121 	private static  void setupDefaultStyle(){
122 		listPanel.addStyleName("KS-Blocking-Task-List");
123 		mainPanel.addStyleName("KS-Blocking-Task-Main");
124 		mainPanel.addStyleName("KS-Mouse-Normal");
125 	}
126 }