Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ViewContext |
|
| 1.3076923076923077;1.308 |
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.application; | |
17 | ||
18 | import java.util.HashMap; | |
19 | import java.util.Map; | |
20 | ||
21 | import org.kuali.student.common.rice.authorization.PermissionType; | |
22 | import org.kuali.student.common.ui.shared.IdAttributes.IdType; | |
23 | ||
24 | /** | |
25 | * ViewContext can be used to pass along context information when switching or initializing a view. | |
26 | * | |
27 | * For example a display view requires the id of the object to display, the view context can be used | |
28 | * to pass along that information from a different controller or view. | |
29 | * | |
30 | */ | |
31 | 0 | public class ViewContext implements Comparable<ViewContext>{ |
32 | ||
33 | public static final String ID_ATR = "docId"; | |
34 | public static final String ID_TYPE_ATR = "idType"; | |
35 | ||
36 | ||
37 | 0 | private Map<String, String> attributes = new HashMap<String, String>(); |
38 | 0 | private String id = ""; |
39 | 0 | private IdType idType = null; |
40 | // FIXME: change state to proper default or null | |
41 | 0 | private String state = "draft"; |
42 | private PermissionType permissionType; | |
43 | ||
44 | public String getId() { | |
45 | 0 | return id; |
46 | } | |
47 | ||
48 | /** | |
49 | * Set the id for this view context, this will appear as part of the address bar when used in | |
50 | * a controller, the controller can use this id to determine what to show (determine the context) | |
51 | */ | |
52 | public void setId(String id) { | |
53 | 0 | this.id = id; |
54 | 0 | } |
55 | ||
56 | public IdType getIdType() { | |
57 | 0 | return idType; |
58 | } | |
59 | ||
60 | /** | |
61 | * Set the type of id for this view context, this will appear as part of the address bar when used in | |
62 | * a controller | |
63 | */ | |
64 | public void setIdType(IdType idType) { | |
65 | 0 | this.idType = idType; |
66 | 0 | } |
67 | ||
68 | public void setIdType(String idTypeString){ | |
69 | 0 | this.idType = IdType.fromString(idTypeString); |
70 | 0 | } |
71 | ||
72 | public String getState() { | |
73 | 0 | return state; |
74 | } | |
75 | ||
76 | public void setState(String state) { | |
77 | 0 | this.state = state; |
78 | 0 | } |
79 | ||
80 | public PermissionType getPermissionType() { | |
81 | 0 | return permissionType; |
82 | } | |
83 | ||
84 | /** | |
85 | * Sets the type of permission needed to be at the the current view, this is interpreted by the controller | |
86 | * if set which checks with the server to see if the user has this kind of permission. Doesn't appear in | |
87 | * the address bar | |
88 | */ | |
89 | public void setPermissionType(PermissionType permissionType) { | |
90 | 0 | this.permissionType = permissionType; |
91 | 0 | } |
92 | ||
93 | @Override | |
94 | public int compareTo(ViewContext o) { | |
95 | 0 | if(o.getId().equals(id) && o.getIdType() == idType && o.getAttributes().equals(attributes)){ |
96 | 0 | return 0; |
97 | } | |
98 | else{ | |
99 | 0 | return -1; |
100 | } | |
101 | } | |
102 | ||
103 | /** | |
104 | * Add an additional attribute to the view context, this will appear in the address bar like id | |
105 | * and type does | |
106 | */ | |
107 | public void setAttribute(String key, String value) { | |
108 | 0 | attributes.put(key, value); |
109 | 0 | } |
110 | ||
111 | public String getAttribute(String key){ | |
112 | 0 | return attributes.get(key); |
113 | } | |
114 | ||
115 | public Map<String, String> getAttributes(){ | |
116 | 0 | return attributes; |
117 | } | |
118 | ||
119 | } |