Coverage Report - org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator
 
Classes in this File Line Coverage Branch Coverage Complexity
KSBlockingProgressIndicator
0%
0/47
0%
0/4
1.25
 
 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  0
 public class KSBlockingProgressIndicator{
 35  
 
 36  0
     private static LinkedList<BlockingTask> tasks = new LinkedList<BlockingTask>();
 37  
 
 38  0
         private static final VerticalPanel mainPanel = new VerticalPanel();
 39  0
         private static final VerticalPanel listPanel = new VerticalPanel();
 40  
 
 41  
         private static KSLightBox popupIndicator;
 42  
 
 43  0
         private static boolean initialized = false;
 44  0
     private static int width = 200;
 45  0
     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  0
                 mainPanel.add(listPanel);
 55  
 
 56  
                 //popupIndicator = new KSLightBox(false);
 57  0
                 popupIndicator = new KSLightBox(false);
 58  
                 //popupIndicator.setShowCloseLink(false);
 59  
                 
 60  0
                 popupIndicator.setWidget(mainPanel);
 61  0
                 popupIndicator.setSize(200, 30);
 62  0
                 popupIndicator.setGlassStyleName("KS-Blocking-Glass");
 63  0
                 popupIndicator.showButtons(false);
 64  0
                 setupDefaultStyle();
 65  0
                 initialized = true;
 66  0
         }
 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  0
                 tasks.add(task);
 76  0
                 updateIndicator();
 77  0
         }
 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  0
                 tasks.remove(task);
 86  0
                 if (tasks.isEmpty()) {
 87  0
                         hideIndicator();
 88  
                 } else {
 89  0
                         updateIndicator();
 90  
                 }
 91  0
         }
 92  
     public static void setSize(final int w, final int h) {
 93  0
      width = w;
 94  0
      height = h;
 95  0
     }
 96  
         private static void updateIndicator() {
 97  
 
 98  0
                 listPanel.clear();
 99  0
                 BlockingTask task = tasks.getLast();
 100  0
                 HorizontalPanel taskPanel = new HorizontalPanel();
 101  0
             Image Image = new Image("images/common/twiddler3.gif");
 102  
 
 103  0
                 taskPanel.add(Image);
 104  0
                 taskPanel.add(new Label(task.getDescription()));
 105  0
                 listPanel.add(taskPanel);
 106  
                 
 107  0
         showIndicator();                
 108  0
         }
 109  
         private static void showIndicator(){
 110  0
                 if(!initialized){
 111  0
                         initialize();
 112  
                 }
 113  0
                 popupIndicator.setSize(width, height);
 114  0
                 popupIndicator.show();
 115  0
         }
 116  
 
 117  
         private static void hideIndicator() {
 118  0
                 popupIndicator.hide();
 119  0
         }
 120  
 
 121  
         private static  void setupDefaultStyle(){
 122  0
                 listPanel.addStyleName("KS-Blocking-Task-List");
 123  0
                 mainPanel.addStyleName("KS-Blocking-Task-Main");
 124  0
                 mainPanel.addStyleName("KS-Mouse-Normal");
 125  0
         }
 126  
 }