001 /** 002 * Copyright 2010 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016 package org.kuali.student.common.ui.client.widgets; 017 018 import org.kuali.student.common.ui.client.mvc.Callback; 019 import org.kuali.student.common.ui.client.mvc.Controller; 020 021 import com.google.gwt.event.dom.client.ClickEvent; 022 import com.google.gwt.event.dom.client.ClickHandler; 023 import com.google.gwt.event.dom.client.KeyDownEvent; 024 import com.google.gwt.event.dom.client.KeyDownHandler; 025 import com.google.gwt.user.client.Window; 026 027 public abstract class NavigationHandler implements ClickHandler, KeyDownHandler { 028 private final String url; 029 private final Controller controller; 030 private final String navigationKey; 031 private final Enum<?> navEnum; 032 033 public NavigationHandler(String url) { 034 this.url = url; 035 this.controller = null; 036 this.navigationKey = null; 037 this.navEnum = null; 038 } 039 040 public NavigationHandler(Controller controller, String navigationKey) { 041 this.url = null; 042 this.controller = controller; 043 this.navigationKey = navigationKey; 044 this.navEnum = null; 045 } 046 047 public NavigationHandler(Controller controller, Enum<?> navigationEnum) { 048 this.url = null; 049 this.controller = controller; 050 this.navigationKey = null; 051 this.navEnum = navigationEnum; 052 } 053 054 public void onClick(ClickEvent event) { 055 doNavigate(); 056 } 057 058 public void onKeyDown(KeyDownEvent event) { 059 doNavigate(); 060 } 061 062 protected void doNavigate() { 063 beforeNavigate(new Callback<Boolean>() { 064 065 @Override 066 public void exec(Boolean result) { 067 if (result) { 068 if (url != null) { 069 Window.Location.assign(url); 070 } 071 } 072 } 073 074 }); 075 } 076 077 078 079 public String getUrl() { 080 return url; 081 } 082 083 public Controller getController() { 084 return controller; 085 } 086 087 public String getNavigationKey() { 088 return navigationKey; 089 } 090 091 public Enum<?> getNavEnum() { 092 return navEnum; 093 } 094 095 public abstract void beforeNavigate(Callback<Boolean> callback); 096 }