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