1 package org.kuali.student.lum.common.client.widgets;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.kuali.student.common.ui.client.mvc.Callback;
10 import org.kuali.student.common.ui.client.widgets.KSButton;
11 import org.kuali.student.common.ui.client.widgets.KSLabel;
12 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
13 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
14 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
15 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
16 import org.kuali.student.core.search.dto.SearchParam;
17 import org.kuali.student.lum.lu.dto.CluSetInfo;
18 import org.kuali.student.lum.lu.dto.MembershipQueryInfo;
19
20 import com.google.gwt.dom.client.Style;
21 import com.google.gwt.event.dom.client.ClickEvent;
22 import com.google.gwt.event.dom.client.ClickHandler;
23 import com.google.gwt.user.client.Window;
24 import com.google.gwt.user.client.ui.Anchor;
25 import com.google.gwt.user.client.ui.Composite;
26 import com.google.gwt.user.client.ui.FlexTable;
27 import com.google.gwt.user.client.ui.HTMLPanel;
28 import com.google.gwt.user.client.ui.HorizontalPanel;
29 import com.google.gwt.user.client.ui.SimplePanel;
30
31 public class CluSetDetailsWidget extends Composite {
32
33 private CluSetInformation cluSetInformation;
34 private SimplePanel mainPanel;
35 private FlexTable detailsTable = new FlexTable();
36 private boolean showClus;
37 private Map<String, Boolean> showCluSetFlags = new HashMap<String, Boolean>();
38 private static final SimpleDateFormat DT_FOMRAT = new SimpleDateFormat("MM/dd/yyyy");
39 private CluSetRetriever cluSetRetriever;
40
41 private BlockingTask retrievingTask = new BlockingTask("Retrieving details");
42
43 public CluSetDetailsWidget(CluSetInformation cluSetInformation, CluSetRetriever cluSetRetriever) {
44 mainPanel = new SimplePanel();
45 this.initWidget(mainPanel);
46 this.cluSetRetriever = cluSetRetriever;
47 setCluSetInformation(cluSetInformation);
48 redraw();
49 }
50
51 public CluSetDetailsWidget(String cluSetId, CluSetRetriever cluSetRetriever) {
52 mainPanel = new SimplePanel();
53 this.initWidget(mainPanel);
54 this.cluSetRetriever = cluSetRetriever;
55
56 KSBlockingProgressIndicator.addTask(retrievingTask);
57 cluSetRetriever.getCluSetInformation(cluSetId, new Callback<CluSetInformation>() {
58 @Override
59 public void exec(CluSetInformation result) {
60 if (result != null) {
61 setCluSetInformation(result);
62 redraw();
63 }
64 KSBlockingProgressIndicator.removeTask(retrievingTask);
65 }
66 });
67 }
68
69 private void redraw() {
70 List<CluInformation> clus = null;
71 List<CluSetInfo> cluSets = null;
72 MembershipQueryInfo membershipQueryInfo = null;
73 List<CluInformation> clusInRange = null;
74 int rowIndex = 0;
75 mainPanel.clear();
76 detailsTable.clear();
77 if (cluSetInformation == null) {
78 return;
79 } else {
80 clus = cluSetInformation.getClus();
81 cluSets = cluSetInformation.getCluSets();
82 membershipQueryInfo = cluSetInformation.getMembershipQueryInfo();
83 clusInRange = cluSetInformation.getClusInRange();
84 }
85 StringBuilder titleTextSb = new StringBuilder();
86 titleTextSb.append("INDIVIDUAL COURSE(S)");
87 KSLabel coursesHeader = new KSLabel(titleTextSb.toString());
88
89 detailsTable.setWidget(rowIndex, 0, coursesHeader);
90 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 2);
91 if (cluSets != null && cluSets.size() > 0 ||
92 clusInRange != null && clusInRange.size() > 0) {
93 coursesHeader.setVisible(true);
94 } else {
95 coursesHeader.setVisible(false);
96 }
97 {
98
99 int numClus = (clus == null)? 0 : clus.size();
100 StringBuilder hideClusTextSb = new StringBuilder();
101 showClus = true;
102 if (showClus) {
103 hideClusTextSb.append("Hide courses(").append(numClus).append(")");
104 } else {
105 hideClusTextSb.append("Show courses(").append(numClus).append(")");
106 }
107 KSButton hideClusButton = new KSButton(hideClusTextSb.toString(), ButtonStyle.DEFAULT_ANCHOR);
108 detailsTable.setWidget(rowIndex, 1, hideClusButton);
109 hideClusButton.addClickHandler(new ClickHandler() {
110 @Override
111 public void onClick(ClickEvent event) {
112 showClus = !showClus;
113 redraw();
114 }
115 });
116 if (numClus > 10) {
117 hideClusButton.setVisible(true);
118 } else {
119 hideClusButton.setVisible(false);
120 }
121 }
122
123 rowIndex++;
124 if (clus != null && showClus) {
125 for (CluInformation clu : clus) {
126 addClusDisplayToTable(rowIndex, clu);
127 rowIndex++;
128 }
129 }
130 if (cluSets != null) {
131 if (cluSets.size() > 0) {
132 KSLabel spacer = new KSLabel();
133 spacer.getElement().getStyle().setPaddingTop(10, Style.Unit.PX);
134 detailsTable.setWidget(rowIndex, 0, spacer);
135 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 3);
136 rowIndex++;
137 }
138 for (final CluSetInfo cluSet : cluSets) {
139 int columnIndex = 0;
140 final String cluSetId = cluSet.getId();
141 HorizontalPanel cluSetNamePanel = new HorizontalPanel();
142 Anchor cluSetNameLabel = new Anchor(cluSet.getName());
143 cluSetNameLabel.addClickHandler(new ClickHandler(){
144
145 @Override
146 public void onClick(ClickEvent event) {
147 String url = "http://" + Window.Location.getHost() + Window.Location.getPath() +
148 "?view=" + AppLocations.Locations.VIEW_CLU_SET + "&docId=" + cluSetId;
149 String features = "height=600,width=960,dependent=0,directories=1," +
150 "fullscreen=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1";
151 Window.open(url, HTMLPanel.createUniqueId(), features);
152
153 }
154 });
155 KSLabel itemType = new KSLabel("Course Set");
156 itemType.getElement().getStyle().setProperty("color", "grey");
157 itemType.getElement().getStyle().setPaddingLeft(5, Style.Unit.PX);
158 cluSetNamePanel.add(cluSetNameLabel);
159 cluSetNamePanel.add(itemType);
160 boolean showCluSet = (showCluSetFlags.get(cluSet.getId()) == null)? false :
161 showCluSetFlags.get(cluSet.getId()).booleanValue();
162 detailsTable.setWidget(rowIndex, columnIndex, cluSetNamePanel);
163 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
164 columnIndex++;
165
166
167
168 columnIndex++;
169 StringBuilder hideCluSetTextSb = new StringBuilder();
170 if (showCluSet) {
171 hideCluSetTextSb.append("Hide Courses");
172 } else {
173 hideCluSetTextSb.append("Show Courses");
174 }
175 KSButton hideCluSetButton = new KSButton(hideCluSetTextSb.toString(), ButtonStyle.DEFAULT_ANCHOR);
176 detailsTable.setWidget(rowIndex, columnIndex, hideCluSetButton);
177 rowIndex++;
178 hideCluSetButton.addClickHandler(new ClickHandler() {
179 @Override
180 public void onClick(ClickEvent event) {
181 Boolean showCluSetDetails = showCluSetFlags.get(cluSet.getId());
182 showCluSetDetails = (showCluSetDetails == null)? false : showCluSetDetails;
183 showCluSetFlags.put(cluSet.getId(), !showCluSetDetails);
184 Boolean newShowCluSetDetails = !showCluSetDetails;
185 if (newShowCluSetDetails) {
186 CluSetInformation subCluSetInformation = cluSetInformation.getSubCluSetInformations().get(cluSet.getId());
187 if (subCluSetInformation == null) {
188 cluSetRetriever.getCluSetInformation(cluSet.getId(), new Callback<CluSetInformation>() {
189 @Override
190 public void exec(CluSetInformation result) {
191 if (result != null) {
192 cluSetInformation.getSubCluSetInformations().put(cluSet.getId(), result);
193 redraw();
194 }
195 }
196 });
197 } else {
198 redraw();
199 }
200 } else {
201 redraw();
202 }
203 }
204 });
205 if (showCluSet) {
206 CluSetInformation subCluSetInformation = cluSetInformation.getSubCluSetInformations().get(cluSet.getId());
207 CluSetDetailsWidget subCluSetWidget = new CluSetDetailsWidget(subCluSetInformation, cluSetRetriever);
208 subCluSetWidget.getElement().getStyle().setPaddingLeft(20, Style.Unit.PX);
209 detailsTable.setWidget(rowIndex, 0, subCluSetWidget);
210 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 3);
211 rowIndex++;
212 }
213
214 }
215 }
216 if (membershipQueryInfo != null) {
217 List<SearchParam> searchParams = membershipQueryInfo.getQueryParamValueList();
218 if (searchParams != null) {
219 HorizontalPanel queryDisplayPanel = new HorizontalPanel();
220 for (SearchParam searchParam : searchParams) {
221 KSLabel paramDescLabel = new KSLabel();
222 KSLabel paramValueLabel = new KSLabel();
223 String paramDesc = translateSearchKey(searchParam.getKey());
224 paramDescLabel.setText(paramDesc);
225 Object value = searchParam.getValue();
226 String displayValue = "";
227 if (value instanceof Date) {
228 displayValue = DT_FOMRAT.format((Date)value);
229 } else {
230 displayValue = value.toString();
231 }
232 paramDescLabel.getElement().getStyle().setProperty("color", "grey");
233 paramDescLabel.getElement().getStyle().setPaddingRight(5, Style.Unit.PX);
234 paramValueLabel.setText(displayValue);
235 paramValueLabel.getElement().getStyle().setPaddingRight(10, Style.Unit.PX);
236 queryDisplayPanel.getElement().getStyle().setPaddingTop(10, Style.Unit.PX);
237 queryDisplayPanel.add(paramDescLabel);
238 queryDisplayPanel.add(paramValueLabel);
239 }
240 detailsTable.setWidget(rowIndex, 0, queryDisplayPanel);
241 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 2);
242 rowIndex++;
243 }
244 if (clusInRange != null) {
245 for (CluInformation clu : clusInRange) {
246 addClusDisplayToTable(rowIndex, clu);
247 rowIndex++;
248 }
249 } else {
250 Window.alert("num clusInRange is null");
251 }
252 }
253 mainPanel.setWidget(detailsTable);
254 }
255
256 private void addClusDisplayToTable(int rowIndex, final CluInformation clu) {
257 int columnIndex = 0;
258 KSButton cluCodeLink = new KSButton(clu.getCode(), ButtonStyle.DEFAULT_ANCHOR);
259 cluCodeLink.getElement().getStyle().setPaddingLeft(10, Style.Unit.PX);
260 detailsTable.setWidget(rowIndex, columnIndex, cluCodeLink);
261 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
262 cluCodeLink.addClickHandler(new ClickHandler() {
263 @Override
264 public void onClick(ClickEvent event) {
265 String url = "http://" + Window.Location.getHost() + Window.Location.getPath() +
266 "?view=" + AppLocations.Locations.VIEW_COURSE + "&idType=" + IdType.OBJECT_ID +"&docId=" + clu.getVerIndependentId();
267 String features = "height=600,width=960,dependent=0,directories=1," +
268 "fullscreen=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1";
269 Window.open(url, HTMLPanel.createUniqueId(), features);
270 }
271 });
272 columnIndex++;
273
274 KSLabel cluTitleLabel = new KSLabel(clu.getTitle());
275 detailsTable.setWidget(rowIndex, columnIndex, cluTitleLabel);
276 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
277 columnIndex++;
278
279 if (clu.getCredits() != null && !clu.getCredits().trim().isEmpty()) {
280 KSLabel cluCreditsLabel = new KSLabel(clu.getCredits() + " credits");
281 detailsTable.setWidget(rowIndex, columnIndex, cluCreditsLabel);
282 detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1);
283 columnIndex++;
284 }
285 }
286
287 private String translateSearchKey(String searchKey) {
288 String result = "";
289 if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalDivision")) {
290 result = "Department";
291 } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalCrsNoRange")) {
292 result = "Course Number Range";
293 } else if (searchKey != null && searchKey.equals("lo.queryParam.loDescPlain")) {
294 result = "Description";
295 } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate1")) {
296 result = "Effective From";
297 } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) {
298 result = "Effective To";
299 } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) {
300
301 }
302
303 return result;
304 }
305
306 public CluSetInformation getCluSetInformation() {
307 return cluSetInformation;
308 }
309
310 public void setCluSetInformation(CluSetInformation cluSetInformation) {
311 this.cluSetInformation = cluSetInformation;
312 }
313
314 public String toString() {
315 return detailsTable.toString();
316 }
317 }