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