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 | 0 | public class CluSetDetailsWidget extends Composite { |
32 | |
|
33 | |
private CluSetInformation cluSetInformation; |
34 | |
private SimplePanel mainPanel; |
35 | 0 | private FlexTable detailsTable = new FlexTable(); |
36 | |
private boolean showClus; |
37 | 0 | private Map<String, Boolean> showCluSetFlags = new HashMap<String, Boolean>(); |
38 | 0 | private static final SimpleDateFormat DT_FOMRAT = new SimpleDateFormat("MM/dd/yyyy"); |
39 | |
private CluSetRetriever cluSetRetriever; |
40 | |
|
41 | 0 | private BlockingTask retrievingTask = new BlockingTask("Retrieving details"); |
42 | |
|
43 | 0 | public CluSetDetailsWidget(CluSetInformation cluSetInformation, CluSetRetriever cluSetRetriever) { |
44 | 0 | mainPanel = new SimplePanel(); |
45 | 0 | this.initWidget(mainPanel); |
46 | 0 | this.cluSetRetriever = cluSetRetriever; |
47 | 0 | setCluSetInformation(cluSetInformation); |
48 | 0 | redraw(); |
49 | 0 | } |
50 | |
|
51 | 0 | public CluSetDetailsWidget(String cluSetId, CluSetRetriever cluSetRetriever) { |
52 | 0 | mainPanel = new SimplePanel(); |
53 | 0 | this.initWidget(mainPanel); |
54 | 0 | this.cluSetRetriever = cluSetRetriever; |
55 | |
|
56 | 0 | KSBlockingProgressIndicator.addTask(retrievingTask); |
57 | 0 | cluSetRetriever.getCluSetInformation(cluSetId, new Callback<CluSetInformation>() { |
58 | |
@Override |
59 | |
public void exec(CluSetInformation result) { |
60 | 0 | if (result != null) { |
61 | 0 | setCluSetInformation(result); |
62 | 0 | redraw(); |
63 | |
} |
64 | 0 | KSBlockingProgressIndicator.removeTask(retrievingTask); |
65 | 0 | } |
66 | |
}); |
67 | 0 | } |
68 | |
|
69 | |
private void redraw() { |
70 | 0 | List<CluInformation> clus = null; |
71 | 0 | List<CluSetInfo> cluSets = null; |
72 | 0 | MembershipQueryInfo membershipQueryInfo = null; |
73 | 0 | List<CluInformation> clusInRange = null; |
74 | 0 | int rowIndex = 0; |
75 | 0 | mainPanel.clear(); |
76 | 0 | detailsTable.clear(); |
77 | 0 | if (cluSetInformation == null) { |
78 | 0 | return; |
79 | |
} else { |
80 | 0 | clus = cluSetInformation.getClus(); |
81 | 0 | cluSets = cluSetInformation.getCluSets(); |
82 | 0 | membershipQueryInfo = cluSetInformation.getMembershipQueryInfo(); |
83 | 0 | clusInRange = cluSetInformation.getClusInRange(); |
84 | |
} |
85 | 0 | StringBuilder titleTextSb = new StringBuilder(); |
86 | 0 | titleTextSb.append("INDIVIDUAL COURSE(S)"); |
87 | 0 | KSLabel coursesHeader = new KSLabel(titleTextSb.toString()); |
88 | |
|
89 | 0 | detailsTable.setWidget(rowIndex, 0, coursesHeader); |
90 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 2); |
91 | 0 | if (cluSets != null && cluSets.size() > 0 || |
92 | |
clusInRange != null && clusInRange.size() > 0) { |
93 | 0 | coursesHeader.setVisible(true); |
94 | |
} else { |
95 | 0 | coursesHeader.setVisible(false); |
96 | |
} |
97 | |
{ |
98 | |
|
99 | 0 | int numClus = (clus == null)? 0 : clus.size(); |
100 | 0 | StringBuilder hideClusTextSb = new StringBuilder(); |
101 | 0 | showClus = true; |
102 | 0 | if (showClus) { |
103 | 0 | hideClusTextSb.append("Hide courses(").append(numClus).append(")"); |
104 | |
} else { |
105 | 0 | hideClusTextSb.append("Show courses(").append(numClus).append(")"); |
106 | |
} |
107 | 0 | KSButton hideClusButton = new KSButton(hideClusTextSb.toString(), ButtonStyle.DEFAULT_ANCHOR); |
108 | 0 | detailsTable.setWidget(rowIndex, 1, hideClusButton); |
109 | 0 | hideClusButton.addClickHandler(new ClickHandler() { |
110 | |
@Override |
111 | |
public void onClick(ClickEvent event) { |
112 | 0 | showClus = !showClus; |
113 | 0 | redraw(); |
114 | 0 | } |
115 | |
}); |
116 | 0 | if (numClus > 10) { |
117 | 0 | hideClusButton.setVisible(true); |
118 | |
} else { |
119 | 0 | hideClusButton.setVisible(false); |
120 | |
} |
121 | |
} |
122 | |
|
123 | 0 | rowIndex++; |
124 | 0 | if (clus != null && showClus) { |
125 | 0 | for (CluInformation clu : clus) { |
126 | 0 | addClusDisplayToTable(rowIndex, clu); |
127 | 0 | rowIndex++; |
128 | |
} |
129 | |
} |
130 | 0 | if (cluSets != null) { |
131 | 0 | if (cluSets.size() > 0) { |
132 | 0 | KSLabel spacer = new KSLabel(); |
133 | 0 | spacer.getElement().getStyle().setPaddingTop(10, Style.Unit.PX); |
134 | 0 | detailsTable.setWidget(rowIndex, 0, spacer); |
135 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 3); |
136 | 0 | rowIndex++; |
137 | |
} |
138 | 0 | for (final CluSetInfo cluSet : cluSets) { |
139 | 0 | int columnIndex = 0; |
140 | 0 | final String cluSetId = cluSet.getId(); |
141 | 0 | HorizontalPanel cluSetNamePanel = new HorizontalPanel(); |
142 | 0 | Anchor cluSetNameLabel = new Anchor(cluSet.getName()); |
143 | 0 | cluSetNameLabel.addClickHandler(new ClickHandler(){ |
144 | |
|
145 | |
@Override |
146 | |
public void onClick(ClickEvent event) { |
147 | 0 | String url = "http://" + Window.Location.getHost() + Window.Location.getPath() + |
148 | |
"?view=" + AppLocations.Locations.VIEW_CLU_SET + "&docId=" + cluSetId; |
149 | 0 | 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 | 0 | Window.open(url, HTMLPanel.createUniqueId(), features); |
152 | |
|
153 | 0 | } |
154 | |
}); |
155 | 0 | KSLabel itemType = new KSLabel("Course Set"); |
156 | 0 | itemType.getElement().getStyle().setProperty("color", "grey"); |
157 | 0 | itemType.getElement().getStyle().setPaddingLeft(5, Style.Unit.PX); |
158 | 0 | cluSetNamePanel.add(cluSetNameLabel); |
159 | 0 | cluSetNamePanel.add(itemType); |
160 | 0 | boolean showCluSet = (showCluSetFlags.get(cluSet.getId()) == null)? false : |
161 | |
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 | |
"?view=" + AppLocations.Locations.VIEW_COURSE + "&idType=" + IdType.OBJECT_ID +"&docId=" + clu.getVerIndependentId(); |
267 | 0 | 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 | 0 | Window.open(url, HTMLPanel.createUniqueId(), features); |
270 | 0 | } |
271 | |
}); |
272 | 0 | columnIndex++; |
273 | |
|
274 | 0 | KSLabel cluTitleLabel = new KSLabel(clu.getTitle()); |
275 | 0 | detailsTable.setWidget(rowIndex, columnIndex, cluTitleLabel); |
276 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1); |
277 | 0 | columnIndex++; |
278 | |
|
279 | 0 | if (clu.getCredits() != null && !clu.getCredits().trim().isEmpty()) { |
280 | 0 | KSLabel cluCreditsLabel = new KSLabel(clu.getCredits() + " credits"); |
281 | 0 | detailsTable.setWidget(rowIndex, columnIndex, cluCreditsLabel); |
282 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1); |
283 | 0 | columnIndex++; |
284 | |
} |
285 | 0 | } |
286 | |
|
287 | |
private String translateSearchKey(String searchKey) { |
288 | 0 | String result = ""; |
289 | 0 | if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalDivision")) { |
290 | 0 | result = "Department"; |
291 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalCrsNoRange")) { |
292 | 0 | result = "Course Number Range"; |
293 | 0 | } else if (searchKey != null && searchKey.equals("lo.queryParam.loDescPlain")) { |
294 | 0 | result = "Description"; |
295 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate1")) { |
296 | 0 | result = "Effective From"; |
297 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) { |
298 | 0 | result = "Effective To"; |
299 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) { |
300 | |
|
301 | |
} |
302 | |
|
303 | 0 | return result; |
304 | |
} |
305 | |
|
306 | |
public CluSetInformation getCluSetInformation() { |
307 | 0 | return cluSetInformation; |
308 | |
} |
309 | |
|
310 | |
public void setCluSetInformation(CluSetInformation cluSetInformation) { |
311 | 0 | this.cluSetInformation = cluSetInformation; |
312 | 0 | } |
313 | |
|
314 | |
public String toString() { |
315 | 0 | return detailsTable.toString(); |
316 | |
} |
317 | |
} |