| 1 | |
package org.kuali.student.lum.lu.ui.dependency.client.widgets; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.HashMap; |
| 5 | |
import java.util.List; |
| 6 | |
|
| 7 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
| 8 | |
import org.kuali.student.common.ui.client.reporting.ReportExportWidget; |
| 9 | |
import org.kuali.student.common.ui.client.util.ExportElement; |
| 10 | |
import org.kuali.student.common.ui.client.util.ExportUtils; |
| 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.field.layout.element.SpanPanel; |
| 15 | |
import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout; |
| 16 | |
import org.kuali.student.common.ui.client.widgets.search.CollapsablePanel; |
| 17 | |
|
| 18 | |
import com.google.gwt.event.dom.client.ClickEvent; |
| 19 | |
import com.google.gwt.event.dom.client.ClickHandler; |
| 20 | |
import com.google.gwt.user.client.ui.Composite; |
| 21 | |
import com.google.gwt.user.client.ui.FlowPanel; |
| 22 | |
import com.google.gwt.user.client.ui.Widget; |
| 23 | |
|
| 24 | |
public class DependencyResultPanel extends Composite implements ReportExportWidget { |
| 25 | |
|
| 26 | 0 | protected KSLabel headerLabel = new KSLabel(); |
| 27 | |
|
| 28 | 0 | protected VerticalFieldLayout dependencySectionContainer = new VerticalFieldLayout(); |
| 29 | |
|
| 30 | 0 | protected HashMap<String, DependencySection> dependencySections = new HashMap<String, DependencySection>(); |
| 31 | |
|
| 32 | |
|
| 33 | 0 | protected HashMap<String, DependencyTypeSection> dependencyTypeSections = new HashMap<String, DependencyTypeSection>(); |
| 34 | |
|
| 35 | 0 | public DependencyResultPanel() { |
| 36 | 0 | this.initWidget(dependencySectionContainer); |
| 37 | 0 | dependencySectionContainer.addWidget(headerLabel); |
| 38 | 0 | dependencySectionContainer.addStyleName("ks-dependency-results"); |
| 39 | 0 | } |
| 40 | |
|
| 41 | |
public void addSection(String sectionName, String sectionTitle) { |
| 42 | 0 | DependencySection section = new DependencySection(sectionTitle); |
| 43 | 0 | dependencySectionContainer.add(section); |
| 44 | 0 | dependencySections.put(sectionName, section); |
| 45 | 0 | } |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public DependencyTypeSection addDependencyTypeSection(String sectionName, String sectionTypeName, Widget sectionHeader) { |
| 52 | 0 | String typeSectionKey = sectionName + "." + sectionTypeName; |
| 53 | 0 | DependencyTypeSection typeSection = new DependencyTypeSection(sectionHeader); |
| 54 | 0 | dependencyTypeSections.put(typeSectionKey, typeSection); |
| 55 | 0 | DependencySection section = dependencySections.get(sectionName); |
| 56 | 0 | section.addWidget(typeSection); |
| 57 | 0 | return typeSection; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public DependencyTypeSection getDependencyTypeSection(String sectionName, String sectionTypeName) { |
| 61 | 0 | String typeSectionKey = sectionName + "." + sectionTypeName; |
| 62 | 0 | return dependencyTypeSections.get(typeSectionKey); |
| 63 | |
} |
| 64 | |
|
| 65 | |
public void setHeaderTitle(String title) { |
| 66 | |
|
| 67 | 0 | SectionTitle sectionTitle = SectionTitle.generateH2Title(title); |
| 68 | 0 | dependencySectionContainer.setLayoutTitle(sectionTitle); |
| 69 | 0 | dependencySectionContainer.underlineTitle(true); |
| 70 | |
|
| 71 | 0 | KSButton expandLabel = new KSButton("Expand All", ButtonStyle.DEFAULT_ANCHOR); |
| 72 | 0 | KSButton collapseLabel = new KSButton("Collapse All", ButtonStyle.DEFAULT_ANCHOR); |
| 73 | |
|
| 74 | 0 | FlowPanel expandArea = new FlowPanel(); |
| 75 | 0 | expandArea.add(expandLabel); |
| 76 | 0 | SpanPanel spanPanel = new SpanPanel(" | "); |
| 77 | 0 | spanPanel.setExportElement(false); |
| 78 | 0 | expandArea.add(spanPanel); |
| 79 | 0 | expandArea.add(collapseLabel); |
| 80 | 0 | dependencySectionContainer.addWidget(expandArea); |
| 81 | |
|
| 82 | 0 | expandLabel.addClickHandler(new ClickHandler() { |
| 83 | |
public void onClick(ClickEvent event) { |
| 84 | 0 | for (DependencySection section : dependencySections.values()) { |
| 85 | 0 | section.expandAll(); |
| 86 | |
} |
| 87 | 0 | } |
| 88 | |
}); |
| 89 | |
|
| 90 | 0 | collapseLabel.addClickHandler(new ClickHandler() { |
| 91 | |
public void onClick(ClickEvent event) { |
| 92 | 0 | for (DependencySection section : dependencySections.values()) { |
| 93 | 0 | section.collapseAll(); |
| 94 | |
} |
| 95 | 0 | } |
| 96 | |
}); |
| 97 | |
|
| 98 | 0 | } |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public void finishLoad() { |
| 104 | |
|
| 105 | 0 | for (DependencyTypeSection typeSection : dependencyTypeSections.values()) { |
| 106 | 0 | typeSection.finishLoad(); |
| 107 | |
} |
| 108 | |
|
| 109 | |
|
| 110 | 0 | for (DependencySection section : dependencySections.values()) { |
| 111 | 0 | section.setVisible(section.dependencyTypeSections.size() > 0); |
| 112 | |
} |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
public static class DependencySection extends VerticalFieldLayout { |
| 116 | 0 | protected FlowPanel header = new FlowPanel(); |
| 117 | |
|
| 118 | |
|
| 119 | 0 | List<DependencyTypeSection> dependencyTypeSections = new ArrayList<DependencyTypeSection>(); |
| 120 | |
|
| 121 | |
public String getTitleTextFromTitleWidget() { |
| 122 | 0 | if (this.layoutTitle != null) { |
| 123 | |
|
| 124 | 0 | return this.layoutTitle.getElement().getInnerText(); |
| 125 | |
} |
| 126 | 0 | return null; |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | public DependencySection(String title) { |
| 130 | 0 | SectionTitle sectionTitle = SectionTitle.generateH4Title(title); |
| 131 | 0 | sectionTitle.addStyleName("ks-dependency-section-title"); |
| 132 | 0 | header.add(sectionTitle); |
| 133 | 0 | header.addStyleName("header-underline"); |
| 134 | 0 | header.addStyleName("ks-dependency-section-header"); |
| 135 | 0 | this.setTitleWidget(header); |
| 136 | 0 | this.addStyleName("ks-dependency-section"); |
| 137 | |
|
| 138 | 0 | KSButton expandLabel = new KSButton("Expand All", ButtonStyle.DEFAULT_ANCHOR); |
| 139 | 0 | KSButton collapseLabel = new KSButton("Collapse All", ButtonStyle.DEFAULT_ANCHOR); |
| 140 | |
|
| 141 | 0 | expandLabel.addClickHandler(new ClickHandler() { |
| 142 | |
public void onClick(ClickEvent event) { |
| 143 | 0 | DependencySection.this.expandAll(); |
| 144 | 0 | } |
| 145 | |
}); |
| 146 | |
|
| 147 | 0 | collapseLabel.addClickHandler(new ClickHandler() { |
| 148 | |
public void onClick(ClickEvent event) { |
| 149 | 0 | DependencySection.this.collapseAll(); |
| 150 | 0 | } |
| 151 | |
}); |
| 152 | |
|
| 153 | 0 | header.add(expandLabel); |
| 154 | 0 | SpanPanel spanPanel = new SpanPanel(" | "); |
| 155 | 0 | spanPanel.setExportElement(false); |
| 156 | 0 | header.add(spanPanel); |
| 157 | 0 | header.add(collapseLabel); |
| 158 | |
|
| 159 | 0 | } |
| 160 | |
|
| 161 | |
@Override |
| 162 | |
public String addWidget(Widget widget) { |
| 163 | 0 | dependencyTypeSections.add((DependencyTypeSection) widget); |
| 164 | 0 | return super.addWidget(widget); |
| 165 | |
} |
| 166 | |
|
| 167 | |
public void expandAll() { |
| 168 | 0 | for (DependencyTypeSection typeSection : dependencyTypeSections) { |
| 169 | 0 | if (!typeSection.isOpen()) { |
| 170 | 0 | typeSection.open(); |
| 171 | |
} |
| 172 | |
} |
| 173 | 0 | } |
| 174 | |
|
| 175 | |
public void collapseAll() { |
| 176 | 0 | for (DependencyTypeSection typeSection : dependencyTypeSections) { |
| 177 | 0 | typeSection.close(); |
| 178 | |
} |
| 179 | 0 | } |
| 180 | |
|
| 181 | |
protected void setVisibility() { |
| 182 | |
|
| 183 | |
|
| 184 | 0 | int visibleCount = 0; |
| 185 | 0 | for (DependencyTypeSection typeSection : dependencyTypeSections) { |
| 186 | 0 | if (typeSection.isVisible()) { |
| 187 | 0 | visibleCount++; |
| 188 | |
} |
| 189 | |
} |
| 190 | 0 | this.setVisible(visibleCount > 0); |
| 191 | 0 | } |
| 192 | |
} |
| 193 | |
|
| 194 | |
public static class DependencyTypeSection extends CollapsablePanel { |
| 195 | |
|
| 196 | 0 | protected FlowPanel content = new FlowPanel(); |
| 197 | 0 | KSLabel countLabel = new KSLabel(); |
| 198 | |
|
| 199 | 0 | List<CollapsablePanel> dependencyItems = new ArrayList<CollapsablePanel>(); |
| 200 | |
|
| 201 | 0 | public DependencyTypeSection(Widget label) { |
| 202 | 0 | this.init(label, content, isOpen, true, ImagePosition.ALIGN_LEFT); |
| 203 | 0 | content.addStyleName("ks-dependency-type-section"); |
| 204 | 0 | super.linkPanel.add(countLabel); |
| 205 | 0 | } |
| 206 | |
|
| 207 | |
public void finishLoad() { |
| 208 | 0 | int numItems = dependencyItems.size(); |
| 209 | 0 | countLabel.setText("(" + numItems + "):"); |
| 210 | 0 | if (numItems <= 5) { |
| 211 | 0 | super.content.setVisible(true); |
| 212 | 0 | super.isOpen = true; |
| 213 | 0 | super.setImageState(); |
| 214 | |
} |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
public void addDependencyItem(Widget label, Widget details) { |
| 218 | 0 | CollapsablePanel depItem = null; |
| 219 | 0 | if (details != null) { |
| 220 | 0 | depItem = new CollapsablePanel(label, details, false, true, ImagePosition.ALIGN_LEFT); |
| 221 | |
} else { |
| 222 | 0 | depItem = new CollapsablePanel(label, new SpanPanel(), false, false, ImagePosition.ALIGN_LEFT); |
| 223 | |
} |
| 224 | 0 | content.add(depItem); |
| 225 | 0 | dependencyItems.add(depItem); |
| 226 | 0 | } |
| 227 | |
|
| 228 | |
public void expandAll() { |
| 229 | 0 | for (CollapsablePanel depItem : dependencyItems) { |
| 230 | 0 | if (!depItem.isOpen()) { |
| 231 | 0 | depItem.open(); |
| 232 | |
} |
| 233 | |
} |
| 234 | 0 | } |
| 235 | |
|
| 236 | |
public void collapseAll() { |
| 237 | 0 | for (CollapsablePanel depItem : dependencyItems) { |
| 238 | 0 | depItem.close(); |
| 239 | |
} |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
@Override |
| 243 | |
public List<ExportElement> getExportElementSubset(ExportElement parent) { |
| 244 | |
|
| 245 | 0 | ArrayList<ExportElement> linkElementSubItems = new ArrayList<ExportElement>(); |
| 246 | 0 | parent.setPrintType(ExportElement.LIST_SUBREPORT); |
| 247 | 0 | if (this.isVisible()) { |
| 248 | |
|
| 249 | 0 | for (CollapsablePanel depItem : dependencyItems) { |
| 250 | 0 | if (depItem.isVisible()) { |
| 251 | |
|
| 252 | 0 | ExportElement linkElement = new ExportElement(); |
| 253 | 0 | linkElement.setSectionName(parent.getSectionName()); |
| 254 | 0 | linkElement.setViewName(parent.getViewName()); |
| 255 | 0 | linkElement.setFieldValue(depItem.getExportFieldValue()); |
| 256 | |
|
| 257 | 0 | List<ExportElement> subset = depItem.getExportElementSubset(parent); |
| 258 | 0 | linkElement.setSubset(setCurrOverToItalic(subset)); |
| 259 | |
|
| 260 | 0 | String fieldValue = linkElement.getFieldValue(); |
| 261 | 0 | if (fieldValue.indexOf("View Course Set") > 0) { |
| 262 | 0 | fieldValue = fieldValue.replaceAll("View Course Set", ""); |
| 263 | 0 | } else if (fieldValue.indexOf("View Course") > 0) { |
| 264 | 0 | fieldValue = fieldValue.replaceAll("View Course", ""); |
| 265 | 0 | } else if (fieldValue.indexOf("View Program") > 0) { |
| 266 | 0 | fieldValue = fieldValue.replaceAll("View Program", ""); |
| 267 | |
} |
| 268 | |
|
| 269 | 0 | if (fieldValue.indexOf("Different Org") > 0) |
| 270 | 0 | fieldValue = fieldValue.replaceAll("Different Org", " * Different Org"); |
| 271 | |
|
| 272 | 0 | linkElement.setFieldValue(fieldValue); |
| 273 | 0 | if (linkElement.getValue() != ""){ |
| 274 | 0 | if (linkElement.getSubset() == null){ |
| 275 | 0 | linkElement.setPrintType(ExportElement.LIST); |
| 276 | |
} else { |
| 277 | 0 | linkElement.setPrintType(ExportElement.LIST_SUBREPORT); |
| 278 | |
} |
| 279 | |
} |
| 280 | |
|
| 281 | 0 | linkElementSubItems.add(linkElement); |
| 282 | 0 | } |
| 283 | |
} |
| 284 | |
} |
| 285 | 0 | return linkElementSubItems; |
| 286 | |
} |
| 287 | |
|
| 288 | |
private List<ExportElement> setCurrOverToItalic(List<ExportElement> subset){ |
| 289 | 0 | if (subset != null){ |
| 290 | 0 | for (ExportElement element : subset){ |
| 291 | 0 | if ((element.getValue() != null)&&(element.getValue().contains("Curriculum Oversight"))){ |
| 292 | 0 | element.setPrintType(ExportElement.ITALIC); |
| 293 | |
} |
| 294 | 0 | element.setSubset(setCurrOverToItalic(element.getSubset())); |
| 295 | |
} |
| 296 | |
} |
| 297 | 0 | return subset; |
| 298 | |
} |
| 299 | |
|
| 300 | |
@Override |
| 301 | |
public String getExportFieldValue() { |
| 302 | 0 | String text = null; |
| 303 | 0 | for (int i = 0; i < this.linkPanel.getWidgetCount(); i++) { |
| 304 | 0 | Widget child = this.linkPanel.getWidget(i); |
| 305 | 0 | if (child instanceof SpanPanel) { |
| 306 | 0 | SpanPanel header = (SpanPanel) child; |
| 307 | 0 | text = header.getExportFieldValue(); |
| 308 | |
} |
| 309 | 0 | if (child instanceof KSLabel && (text != null) && (text != "")) { |
| 310 | 0 | KSLabel countLabel = (KSLabel) child; |
| 311 | 0 | text = text + countLabel.getText(); |
| 312 | |
} |
| 313 | |
} |
| 314 | 0 | return text; |
| 315 | |
} |
| 316 | |
} |
| 317 | |
|
| 318 | |
public void hide(String dependencySection, String dependencyType) { |
| 319 | 0 | DependencyTypeSection typeSection = dependencyTypeSections.get(dependencySection + "." + dependencyType); |
| 320 | 0 | if (typeSection != null) { |
| 321 | 0 | typeSection.setVisible(false); |
| 322 | 0 | DependencySection section = dependencySections.get(dependencySection); |
| 323 | 0 | section.setVisibility(); |
| 324 | |
} |
| 325 | 0 | } |
| 326 | |
|
| 327 | |
public void show(String dependencySection, String dependencyType) { |
| 328 | 0 | DependencyTypeSection typeSection = dependencyTypeSections.get(dependencySection + "." + dependencyType); |
| 329 | 0 | if (typeSection != null) { |
| 330 | 0 | typeSection.setVisible(true); |
| 331 | 0 | DependencySection section = dependencySections.get(dependencySection); |
| 332 | 0 | section.setVisibility(); |
| 333 | |
} |
| 334 | 0 | } |
| 335 | |
|
| 336 | |
public void hideAll() { |
| 337 | 0 | for (DependencyTypeSection typeSection : dependencyTypeSections.values()) { |
| 338 | 0 | typeSection.setVisible(false); |
| 339 | |
} |
| 340 | 0 | for (DependencySection section : dependencySections.values()) { |
| 341 | 0 | section.setVisible(false); |
| 342 | |
} |
| 343 | 0 | } |
| 344 | |
|
| 345 | |
public void showAll() { |
| 346 | 0 | for (DependencyTypeSection typeSection : dependencyTypeSections.values()) { |
| 347 | 0 | typeSection.setVisible(true); |
| 348 | |
} |
| 349 | 0 | for (DependencySection section : dependencySections.values()) { |
| 350 | 0 | section.setVisible(section.dependencyTypeSections.size() > 0); |
| 351 | |
} |
| 352 | 0 | } |
| 353 | |
|
| 354 | |
public VerticalFieldLayout getDependencySectionContainer() { |
| 355 | 0 | return dependencySectionContainer; |
| 356 | |
} |
| 357 | |
|
| 358 | |
@Override |
| 359 | |
public boolean isExportElement() { |
| 360 | 0 | return true; |
| 361 | |
} |
| 362 | |
|
| 363 | |
@Override |
| 364 | |
public List<ExportElement> getExportElementSubset(ExportElement parent) { |
| 365 | 0 | ArrayList<ExportElement> returnItems = new ArrayList<ExportElement>(); |
| 366 | |
|
| 367 | 0 | if (this.getWidget() instanceof VerticalFieldLayout) { |
| 368 | 0 | VerticalFieldLayout verticalFieldLayoutWidget = (VerticalFieldLayout) this.getWidget(); |
| 369 | 0 | returnItems.addAll(ExportUtils.getDetailsForWidget(verticalFieldLayoutWidget.getVerticalLayout(), parent.getViewName(), parent.getSectionName())); |
| 370 | |
} |
| 371 | |
|
| 372 | 0 | for (DependencySection section : this.dependencySections.values()) { |
| 373 | |
|
| 374 | 0 | returnItems.addAll(ExportUtils.getDetailsForWidget(section, parent.getViewName(), parent.getSectionName())); |
| 375 | |
} |
| 376 | 0 | return returnItems; |
| 377 | |
} |
| 378 | |
|
| 379 | |
@Override |
| 380 | |
public String getExportFieldValue() { |
| 381 | 0 | return null; |
| 382 | |
} |
| 383 | |
|
| 384 | |
} |