1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.widgets;
17
18 import org.kuali.student.common.ui.client.mvc.Callback;
19 import org.kuali.student.common.ui.client.mvc.Controller;
20
21 import com.google.gwt.event.dom.client.ClickEvent;
22 import com.google.gwt.event.dom.client.ClickHandler;
23 import com.google.gwt.event.dom.client.KeyDownEvent;
24 import com.google.gwt.event.dom.client.KeyDownHandler;
25 import com.google.gwt.user.client.Window;
26
27 public abstract class NavigationHandler implements ClickHandler, KeyDownHandler {
28 private final String url;
29 private final Controller controller;
30 private final String navigationKey;
31 private final Enum<?> navEnum;
32
33 public NavigationHandler(String url) {
34 this.url = url;
35 this.controller = null;
36 this.navigationKey = null;
37 this.navEnum = null;
38 }
39
40 public NavigationHandler(Controller controller, String navigationKey) {
41 this.url = null;
42 this.controller = controller;
43 this.navigationKey = navigationKey;
44 this.navEnum = null;
45 }
46
47 public NavigationHandler(Controller controller, Enum<?> navigationEnum) {
48 this.url = null;
49 this.controller = controller;
50 this.navigationKey = null;
51 this.navEnum = navigationEnum;
52 }
53
54 public void onClick(ClickEvent event) {
55 doNavigate();
56 }
57
58 public void onKeyDown(KeyDownEvent event) {
59 doNavigate();
60 }
61
62 protected void doNavigate() {
63 beforeNavigate(new Callback<Boolean>() {
64
65 @Override
66 public void exec(Boolean result) {
67 if (result) {
68 if (url != null) {
69 Window.Location.assign(url);
70 }
71 }
72 }
73
74 });
75 }
76
77
78
79 public String getUrl() {
80 return url;
81 }
82
83 public Controller getController() {
84 return controller;
85 }
86
87 public String getNavigationKey() {
88 return navigationKey;
89 }
90
91 public Enum<?> getNavEnum() {
92 return navEnum;
93 }
94
95 public abstract void beforeNavigate(Callback<Boolean> callback);
96 }