Coverage Report - org.kuali.student.common.ui.client.widgets.notification.KSNotification
 
Classes in this File Line Coverage Branch Coverage Complexity
KSNotification
0%
0/43
0%
0/4
1.25
KSNotification$1
0%
0/3
N/A
1.25
KSNotification$2
0%
0/3
N/A
1.25
KSNotification$3
0%
0/5
0%
0/2
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.notification;
 17  
 
 18  
 import com.google.gwt.dom.client.Element;
 19  
 import com.google.gwt.event.dom.client.ClickEvent;
 20  
 import com.google.gwt.event.dom.client.ClickHandler;
 21  
 import com.google.gwt.event.dom.client.MouseOutEvent;
 22  
 import com.google.gwt.event.dom.client.MouseOutHandler;
 23  
 import com.google.gwt.event.dom.client.MouseOverEvent;
 24  
 import com.google.gwt.event.dom.client.MouseOverHandler;
 25  
 import com.google.gwt.event.logical.shared.CloseEvent;
 26  
 import com.google.gwt.event.logical.shared.CloseHandler;
 27  
 import com.google.gwt.event.logical.shared.HasCloseHandlers;
 28  
 import com.google.gwt.event.shared.HandlerRegistration;
 29  
 import com.google.gwt.user.client.DOM;
 30  
 import com.google.gwt.user.client.Event;
 31  
 import com.google.gwt.user.client.ui.Composite;
 32  
 import com.google.gwt.user.client.ui.HTML;
 33  
 import com.google.gwt.user.client.ui.HTMLPanel;
 34  
 import com.google.gwt.user.client.ui.Widget;
 35  
 
 36  0
 public class KSNotification extends Composite implements HasCloseHandlers<KSNotification>{
 37  
         private final int duration;
 38  
         public static final int DEFAULT_DURATION = 4000;
 39  0
         private final String id = HTMLPanel.createUniqueId();
 40  0
         private final String contentId = HTMLPanel.createUniqueId();
 41  0
         private final String closeLinkId = HTMLPanel.createUniqueId();
 42  0
         private final HTMLPanel panel = new HTMLPanel("<p id='" + contentId + "'></p><a href='javascript:return false;' title='Close' class='ks-notification-close' style='visibility: hidden' id='" + closeLinkId + "'></a>");
 43  
         
 44  0
         public KSNotification(final String message, boolean isHtml, final int duration) {
 45  0
                 this.duration = duration;
 46  0
                 panel.setStyleName("ks-notification-message");
 47  0
                 panel.getElement().setId(id);
 48  
                 
 49  0
                 if (isHtml) {
 50  0
                         panel.add(new HTML(message), contentId);
 51  
                 } else {
 52  0
                         panel.getElementById(contentId).setInnerText(message);
 53  
                 }
 54  
                 
 55  0
                 initHandlers();
 56  0
                 super.initWidget(panel);
 57  0
         }
 58  
         
 59  0
         public KSNotification(final String message, boolean isHtml) {
 60  0
                 this.duration = DEFAULT_DURATION;
 61  0
                 panel.setStyleName("ks-notification-message");
 62  0
                 panel.getElement().setId(id);
 63  
                 
 64  0
                 if (isHtml) {
 65  0
                         panel.add(new HTML(message), contentId);
 66  
                 } else {
 67  0
                         panel.getElementById(contentId).setInnerText(message);
 68  
                 }
 69  
                 
 70  0
                 initHandlers();
 71  0
                 super.initWidget(panel);
 72  0
         }
 73  
 
 74  0
         public KSNotification(final Widget widget, final int duration) {
 75  0
                 this.duration = duration;
 76  0
                 panel.setStyleName("ks-notification-message");
 77  0
                 panel.getElement().setId(id);
 78  0
                 panel.add(widget, contentId);
 79  
                 
 80  0
                 initHandlers();
 81  0
                 super.initWidget(panel);
 82  0
         }
 83  
 
 84  
         private void initHandlers() {
 85  0
                 addDomHandler(new MouseOverHandler() {
 86  
                         @Override
 87  
                         public void onMouseOver(MouseOverEvent event) {
 88  0
                                 DOM.getElementById(closeLinkId).getStyle().setProperty("visibility", "visible");
 89  0
                         }
 90  
                 }, MouseOverEvent.getType());
 91  
 
 92  0
                 addDomHandler(new MouseOutHandler() {
 93  
                         @Override
 94  
                         public void onMouseOut(MouseOutEvent event) {
 95  0
                                 DOM.getElementById(closeLinkId).getStyle().setProperty("visibility", "hidden");
 96  0
                         }
 97  
                 }, MouseOutEvent.getType());
 98  
                 
 99  0
                 DOM.sinkEvents(panel.getElementById(closeLinkId), Event.ONCLICK);
 100  0
                 addDomHandler(new ClickHandler() {
 101  
                         @Override
 102  
                         public void onClick(ClickEvent event) {
 103  0
                                 Element e = Element.as(event.getNativeEvent().getEventTarget());
 104  0
                                 if (e.equals(panel.getElementById(closeLinkId))) {
 105  0
                                         CloseEvent.fire(KSNotification.this, KSNotification.this);
 106  
                                 }
 107  0
                         }
 108  
                 }, ClickEvent.getType());
 109  0
         }
 110  
         
 111  
         /**
 112  
          * @return the duration
 113  
          */
 114  
         public int getDuration() {
 115  0
                 return duration;
 116  
         }
 117  
 
 118  
         public String getId() {
 119  0
                 return id;
 120  
         }
 121  
 
 122  
         public String getContentId() {
 123  0
                 return contentId;
 124  
         }
 125  
 
 126  
         public String getCloseLinkId() {
 127  0
                 return closeLinkId;
 128  
         }
 129  
 
 130  
         
 131  
         @Override
 132  
         public HandlerRegistration addCloseHandler(
 133  
                         CloseHandler<KSNotification> handler) {
 134  0
                 return addHandler(handler, CloseEvent.getType());
 135  
         }
 136  
 }