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