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