Coverage Report - org.kuali.student.common.ui.client.widgets.notification.KSNotifier
 
Classes in this File Line Coverage Branch Coverage Complexity
KSNotifier
0%
0/19
0%
0/4
1.4
KSNotifier$1
0%
0/4
N/A
1.4
KSNotifier$2
0%
0/4
N/A
1.4
KSNotifier$2$1
0%
0/4
N/A
1.4
KSNotifier$3
0%
0/8
0%
0/4
1.4
 
 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.notification;
 17  
 
 18  
 import org.kuali.student.common.ui.client.mvc.Holder;
 19  
 import org.kuali.student.common.ui.client.util.Elements;
 20  
 
 21  
 import com.google.gwt.event.logical.shared.CloseEvent;
 22  
 import com.google.gwt.event.logical.shared.CloseHandler;
 23  
 import com.google.gwt.event.shared.HandlerRegistration;
 24  
 import com.google.gwt.user.client.Timer;
 25  
 import com.google.gwt.user.client.ui.FlowPanel;
 26  
 import com.google.gwt.user.client.ui.RootPanel;
 27  
 
 28  0
 public class KSNotifier {
 29  0
     private static final FlowPanel notifier = new FlowPanel();
 30  
 
 31  
     public static final int FADE_DURATION = 1000;
 32  
 
 33  
     private static final int DEFAULT_FADE_DURATION = 4000;
 34  
 
 35  
     static {
 36  0
         notifier.setStyleName("ks-notification-container");
 37  0
     }
 38  
 
 39  0
     private KSNotifier() {
 40  
 
 41  0
     }
 42  
 
 43  
     public static void show(String message) {
 44  0
         add(new KSNotification(message, false, DEFAULT_FADE_DURATION));
 45  0
     }
 46  
 
 47  
     public static void add(final KSNotification notification) {
 48  0
         if (notifier.getWidgetCount() == 0) {
 49  0
             RootPanel.get().add(notifier);
 50  
         }
 51  
 
 52  0
         final Holder<HandlerRegistration> reg = new Holder<HandlerRegistration>();
 53  0
         reg.set(notification.addCloseHandler(new CloseHandler<KSNotification>() {
 54  
             @Override
 55  
             public void onClose(CloseEvent<KSNotification> event) {
 56  0
                 reg.get().removeHandler();
 57  0
                 remove(notification, false);
 58  0
             }
 59  
         }));
 60  
 
 61  0
         Elements.setOpacity(notification.getElement(), 0);
 62  0
         notifier.add(notification);
 63  0
         Elements.fadeIn(notification, FADE_DURATION, 85, new Elements.FadeCallback() {
 64  
 
 65  
             @Override
 66  
             public void onFadeStart() {
 67  
                 // do nothing
 68  0
             }
 69  
 
 70  
             @Override
 71  
             public void onFadeComplete() {
 72  0
                 new Timer() {
 73  
                     @Override
 74  
                     public void run() {
 75  0
                         reg.get().removeHandler();
 76  0
                         remove(notification, true);
 77  0
                     }
 78  
                 }.schedule(notification.getDuration());
 79  0
             }
 80  
         });
 81  
 
 82  0
     }
 83  
 
 84  
     public static void remove(final KSNotification notification, final boolean fireEvents) {
 85  0
         if (notifier.getWidgetIndex(notification) != -1) {
 86  0
             Elements.fadeOut(notification, FADE_DURATION, 0, new Elements.FadeCallback() {
 87  
                 @Override
 88  
                 public void onFadeStart() {
 89  
                     // do nothing
 90  0
                 }
 91  
 
 92  
                 @Override
 93  
                 public void onFadeComplete() {
 94  0
                     notifier.remove(notification);
 95  0
                     if (fireEvents) {
 96  0
                         CloseEvent.fire(notification, notification);
 97  
                     }
 98  0
                     if (notifier.getWidgetCount() == 0) {
 99  0
                         RootPanel.get().remove(notifier);
 100  
                     }
 101  0
                 }
 102  
             });
 103  
         }
 104  0
     }
 105  
 }