1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.organization.ui.client.mvc.view; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
21 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
22 | |
import org.kuali.student.common.ui.client.event.ModifyActionEvent; |
23 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
24 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
25 | |
import org.kuali.student.core.organization.dto.OrgHierarchyInfo; |
26 | |
import org.kuali.student.core.organization.dto.OrgTreeInfo; |
27 | |
import org.kuali.student.core.organization.ui.client.service.OrgRpcService; |
28 | |
import org.kuali.student.core.organization.ui.client.service.OrgRpcServiceAsync; |
29 | |
import org.kuali.student.core.organization.ui.client.theme.OrgTreeImages; |
30 | |
|
31 | |
import com.google.gwt.core.client.GWT; |
32 | |
import com.google.gwt.event.dom.client.ClickEvent; |
33 | |
import com.google.gwt.event.dom.client.ClickHandler; |
34 | |
import com.google.gwt.event.logical.shared.OpenEvent; |
35 | |
import com.google.gwt.event.logical.shared.OpenHandler; |
36 | |
import com.google.gwt.user.client.DOM; |
37 | |
import com.google.gwt.user.client.ui.Composite; |
38 | |
import com.google.gwt.user.client.ui.Panel; |
39 | |
import com.google.gwt.user.client.ui.SimplePanel; |
40 | |
import com.google.gwt.user.client.ui.Tree; |
41 | |
import com.google.gwt.user.client.ui.TreeImages; |
42 | |
import com.google.gwt.user.client.ui.TreeItem; |
43 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
44 | |
|
45 | 0 | public class OrgTree extends Composite{ |
46 | 0 | private OrgRpcServiceAsync orgRpcServiceAsync = GWT.create(OrgRpcService.class); |
47 | 0 | Panel w = new SimplePanel(); |
48 | 0 | TreeImages images = (TreeImages)GWT.create(OrgTreeImages.class); |
49 | 0 | Tree tree = new Tree(images); |
50 | |
VerticalSectionView containingSection; |
51 | 0 | boolean loaded = false; |
52 | |
|
53 | 0 | public OrgTree(){ |
54 | 0 | super.initWidget(w); |
55 | 0 | w.add(tree); |
56 | 0 | tree.setWidth("100%"); |
57 | 0 | KSLabel lbl = new KSLabel("Please Wait..."); |
58 | |
|
59 | 0 | tree.addOpenHandler(new OpenHandler<TreeItem>(){ |
60 | |
|
61 | |
@Override |
62 | |
public void onOpen(OpenEvent<TreeItem> event) { |
63 | 0 | TreeItem item = event.getTarget(); |
64 | 0 | Node rootNode = (Node)item.getWidget(); |
65 | 0 | String orgId = rootNode.getOrgId(); |
66 | 0 | String orgName = rootNode.getName(); |
67 | 0 | item.removeItems(); |
68 | 0 | item.addItem(""); |
69 | 0 | if(item.getChildCount()==1){ |
70 | 0 | getOrgTree(orgId,rootNode.getHierarchyId(),item); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | |
}); |
75 | 0 | } |
76 | |
|
77 | |
public OrgTree(VerticalSectionView section) { |
78 | 0 | this(); |
79 | 0 | this.containingSection = section; |
80 | 0 | } |
81 | |
|
82 | |
public boolean isLoaded(){ |
83 | 0 | return loaded; |
84 | |
} |
85 | |
public void setLoaded(boolean loaded){ |
86 | 0 | this.loaded=loaded; |
87 | 0 | } |
88 | |
protected void onLoad(){ |
89 | 0 | if (!loaded){ |
90 | 0 | loaded = true; |
91 | 0 | orgRpcServiceAsync.getOrgHierarchies(new KSAsyncCallback<List<OrgHierarchyInfo>>(){ |
92 | |
|
93 | |
public void onSuccess(List<OrgHierarchyInfo> result) { |
94 | 0 | if(result != null){ |
95 | 0 | for(final OrgHierarchyInfo orgHInfo:result){ |
96 | |
|
97 | |
|
98 | 0 | orgRpcServiceAsync.getOrgDisplayTree(orgHInfo.getRootOrgId(), orgHInfo.getId(), -1, new KSAsyncCallback<List<OrgTreeInfo> >(){ |
99 | |
|
100 | |
@Override |
101 | |
public void onSuccess(List<OrgTreeInfo> result) { |
102 | 0 | OrgTreeInfo root = result.get(0); |
103 | 0 | TreeItem item = new TreeItem(new RootNode(root.getOrgId(),root.getDisplayName(),root.getPositions(),root.getOrgHierarchyId())); |
104 | 0 | tree.addItem(item); |
105 | 0 | item.addItem(""); |
106 | 0 | } |
107 | |
|
108 | |
}); |
109 | |
|
110 | |
} |
111 | |
} |
112 | 0 | } |
113 | |
}); |
114 | |
} |
115 | 0 | } |
116 | |
|
117 | |
|
118 | |
protected void getOrgTree(final String orgId, final String hierarchyId, final TreeItem node){ |
119 | |
|
120 | 0 | orgRpcServiceAsync.getOrgDisplayTree(orgId, hierarchyId, 1, new KSAsyncCallback<List<OrgTreeInfo> >(){ |
121 | |
|
122 | |
@Override |
123 | |
public void onSuccess(List<OrgTreeInfo> result) { |
124 | 0 | for(OrgTreeInfo orgTreeInfo:result){ |
125 | 0 | if (!orgTreeInfo.getOrgId().equals(orgId)) { |
126 | 0 | TreeItem item = new TreeItem(new OrgWidget(orgTreeInfo.getOrgId(), orgTreeInfo.getDisplayName(), orgTreeInfo.getPositions(), hierarchyId)); |
127 | 0 | node.addItem(item); |
128 | 0 | item.addItem(""); |
129 | 0 | } |
130 | |
} |
131 | 0 | node.getChild(0).remove(); |
132 | |
|
133 | 0 | node.setState(true, false); |
134 | |
|
135 | 0 | } |
136 | |
|
137 | |
}); |
138 | 0 | } |
139 | |
private class RootNode extends Composite implements Node{ |
140 | 0 | VerticalPanel w = new VerticalPanel(); |
141 | |
String orgId; |
142 | |
String name; |
143 | |
String hierarchyId; |
144 | 0 | boolean showMembers = false; |
145 | |
public String getOrgId(){ |
146 | 0 | return orgId; |
147 | |
} |
148 | |
|
149 | |
public String getName(){ |
150 | 0 | return name; |
151 | |
} |
152 | |
|
153 | |
public String getHierarchyId(){ |
154 | 0 | return hierarchyId; |
155 | |
} |
156 | |
|
157 | 0 | public RootNode( final String orgId,String name,final long positions, String hierarchyId){ |
158 | 0 | super.initWidget(w); |
159 | 0 | this.name=name; |
160 | 0 | this.orgId=orgId; |
161 | 0 | this.hierarchyId = hierarchyId; |
162 | |
|
163 | 0 | KSLabel label = new KSLabel(name); |
164 | 0 | label.addStyleName("KS-Org-Tree-Label"); |
165 | 0 | final MembersTable memberTable = new MembersTable(); |
166 | 0 | DOM.setElementAttribute(memberTable.getElement(), "id", "orgTreeMemberTable"); |
167 | 0 | memberTable.setOrgId(orgId); |
168 | 0 | ClickHandler handlerModify = new ClickHandler() { |
169 | |
@Override |
170 | |
public void onClick(ClickEvent event) { |
171 | 0 | Controller orgController = containingSection.getController(); |
172 | 0 | orgController.fireApplicationEvent(new ModifyActionEvent(orgId)); |
173 | 0 | } |
174 | |
}; |
175 | 0 | label.addClickHandler(handlerModify); |
176 | |
|
177 | 0 | ClickHandler memberHandler = new ClickHandler() { |
178 | |
|
179 | |
@Override |
180 | |
public void onClick(ClickEvent event) { |
181 | 0 | if(!showMembers){ |
182 | 0 | ((KSLabel)event.getSource()).getElement().setInnerText("Hide Members " + "["+ positions + "]"); |
183 | 0 | w.add(memberTable); |
184 | 0 | memberTable.fetchMemberTable(); |
185 | 0 | memberTable.setVisible(true); |
186 | 0 | showMembers = true; |
187 | |
|
188 | |
} |
189 | |
else{ |
190 | 0 | ((KSLabel)event.getSource()).getElement().setInnerText("Members " + "["+ positions + "]"); |
191 | 0 | memberTable.setVisible(false); |
192 | 0 | showMembers = false; |
193 | |
} |
194 | 0 | } |
195 | |
|
196 | |
}; |
197 | |
|
198 | |
|
199 | 0 | final KSLabel members = new KSLabel("Members " + "["+ positions + "]"); |
200 | 0 | members.addStyleName("action"); |
201 | 0 | members.addClickHandler(memberHandler); |
202 | 0 | members.getElement().setAttribute("value", ""); |
203 | 0 | w.add(label); |
204 | 0 | w.add(members); |
205 | 0 | w.addStyleName("KS-Org-Tree-Section"); |
206 | 0 | addStyleName("KS-Org-Widget"); |
207 | |
|
208 | |
|
209 | 0 | } |
210 | |
} |
211 | |
|
212 | |
private class OrgWidget extends Composite implements Node{ |
213 | 0 | VerticalPanel w = new VerticalPanel(); |
214 | 0 | boolean showMembers = false; |
215 | |
String orgId; |
216 | |
String name; |
217 | |
String hierarchyId; |
218 | |
|
219 | |
public String getOrgId(){ |
220 | 0 | return orgId; |
221 | |
} |
222 | |
|
223 | |
public String getName(){ |
224 | 0 | return name; |
225 | |
} |
226 | |
|
227 | |
public String getHierarchyId(){ |
228 | 0 | return hierarchyId; |
229 | |
} |
230 | |
|
231 | 0 | public OrgWidget(final String id, final String name, final long positions, String hierarchyId) { |
232 | 0 | super.initWidget(w); |
233 | 0 | this.name = name; |
234 | 0 | this.orgId=id; |
235 | 0 | this.hierarchyId=hierarchyId; |
236 | 0 | final MembersTable memberTable = new MembersTable(); |
237 | 0 | DOM.setElementAttribute(memberTable.getElement(), "id", "orgTreeMemberTable"); |
238 | 0 | memberTable.setOrgId(id); |
239 | |
|
240 | 0 | final KSLabel label = new KSLabel(name); |
241 | 0 | label.addStyleName("KS-Org-Tree-Label"); |
242 | 0 | ClickHandler handlerModify = new ClickHandler() { |
243 | |
@Override |
244 | |
public void onClick(ClickEvent event) { |
245 | 0 | Controller orgController = containingSection.getController(); |
246 | 0 | orgController.fireApplicationEvent(new ModifyActionEvent(id)); |
247 | 0 | } |
248 | |
}; |
249 | 0 | label.addClickHandler(handlerModify); |
250 | |
|
251 | 0 | ClickHandler memberHandler = new ClickHandler() { |
252 | |
|
253 | |
@Override |
254 | |
public void onClick(ClickEvent event) { |
255 | 0 | if(!showMembers){ |
256 | 0 | ((KSLabel)event.getSource()).getElement().setInnerText("Hide Members " + "["+ positions + "]"); |
257 | 0 | w.add(memberTable); |
258 | 0 | memberTable.fetchMemberTable(); |
259 | 0 | memberTable.setVisible(true); |
260 | 0 | showMembers = true; |
261 | |
|
262 | |
} |
263 | |
else{ |
264 | 0 | ((KSLabel)event.getSource()).getElement().setInnerText("Members " + "["+ positions + "]"); |
265 | 0 | memberTable.setVisible(false); |
266 | 0 | showMembers = false; |
267 | |
} |
268 | 0 | } |
269 | |
|
270 | |
}; |
271 | |
|
272 | |
|
273 | 0 | final KSLabel members = new KSLabel("Members " + "["+ positions + "]"); |
274 | 0 | members.addStyleName("action"); |
275 | 0 | members.addClickHandler(memberHandler); |
276 | 0 | members.getElement().setAttribute("value", ""); |
277 | |
|
278 | 0 | w.add(label); |
279 | 0 | w.add(members); |
280 | 0 | w.addStyleName("KS-Org-Tree-Section"); |
281 | |
|
282 | 0 | addStyleName("KS-Org-Widget"); |
283 | 0 | } |
284 | |
|
285 | |
} |
286 | |
|
287 | |
interface Node{ |
288 | |
public String getOrgId(); |
289 | |
|
290 | |
public String getName(); |
291 | |
|
292 | |
public String getHierarchyId(); |
293 | |
} |
294 | |
|
295 | |
|
296 | |
} |