Coverage Report - org.kuali.student.common.ui.client.widgets.NavigationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
NavigationHandler
0%
0/29
N/A
1.25
NavigationHandler$1
0%
0/8
0%
0/6
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;
 17  
 
 18  
 import org.kuali.student.common.ui.client.event.NavigationActionEvent;
 19  
 import org.kuali.student.common.ui.client.mvc.Callback;
 20  
 import org.kuali.student.common.ui.client.mvc.Controller;
 21  
 
 22  
 import com.google.gwt.event.dom.client.ClickEvent;
 23  
 import com.google.gwt.event.dom.client.ClickHandler;
 24  
 import com.google.gwt.event.dom.client.KeyDownEvent;
 25  
 import com.google.gwt.event.dom.client.KeyDownHandler;
 26  
 import com.google.gwt.user.client.Window;
 27  
 
 28  0
 public abstract class NavigationHandler implements ClickHandler, KeyDownHandler {
 29  
         private final String url;
 30  
          private final Controller controller;
 31  
          private final String navigationKey;
 32  
          private final Enum<?> navEnum;
 33  
          
 34  0
          public NavigationHandler(String url) {
 35  0
           this.url = url;
 36  0
           this.controller = null;
 37  0
           this.navigationKey = null;
 38  0
           this.navEnum = null;
 39  0
          }
 40  
          
 41  0
          public NavigationHandler(Controller controller, String navigationKey) {
 42  0
           this.url = null;
 43  0
           this.controller = controller;
 44  0
           this.navigationKey = navigationKey;
 45  0
           this.navEnum = null;
 46  0
          }
 47  
          
 48  0
          public NavigationHandler(Controller controller, Enum<?> navigationEnum) {
 49  0
                   this.url = null;
 50  0
                   this.controller = controller;
 51  0
                   this.navigationKey = null;
 52  0
                   this.navEnum = navigationEnum;
 53  0
          }
 54  
          
 55  
          public void onClick(ClickEvent event) {
 56  0
                  doNavigate();
 57  0
          }
 58  
 
 59  
          public void onKeyDown(KeyDownEvent event) {
 60  0
                  doNavigate();
 61  0
          }
 62  
          
 63  
          protected void doNavigate() {
 64  0
                  beforeNavigate(new Callback<Boolean>() {
 65  
 
 66  
                    @Override
 67  
                            public void exec(Boolean result) {
 68  0
                             if (result) {
 69  0
                                      if (url != null) {
 70  0
                                              Window.Location.assign(url);
 71  0
                                      } else if(navEnum != null){
 72  0
                                              controller.fireApplicationEvent(new NavigationActionEvent(navEnum));
 73  
                                      }
 74  
                                      else{
 75  0
                                              controller.fireApplicationEvent(new NavigationActionEvent(navigationKey));
 76  
                                      }
 77  
                                 }
 78  0
                         }
 79  
                    
 80  
                  });
 81  0
          }
 82  
          
 83  
          
 84  
                  
 85  
          public String getUrl() {
 86  0
                 return url;
 87  
         }
 88  
 
 89  
         public Controller getController() {
 90  0
                 return controller;
 91  
         }
 92  
 
 93  
         public String getNavigationKey() {
 94  0
                 return navigationKey;
 95  
         }
 96  
 
 97  
         public Enum<?> getNavEnum() {
 98  0
                 return navEnum;
 99  
         }
 100  
 
 101  
         public abstract void beforeNavigate(Callback<Boolean> callback);
 102  
 }