| 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 | 0 |              ArrayList<ExportElement> linkElementSubItems = new ArrayList<ExportElement>(); | 
  | 245 | 0 |              for (CollapsablePanel depItem : dependencyItems) { | 
  | 246 | 0 |                  ExportElement linkElement = new ExportElement(); | 
  | 247 | 0 |                  linkElement.setSectionName(parent.getSectionName()); | 
  | 248 | 0 |                  linkElement.setViewName(parent.getViewName()); | 
  | 249 | 0 |                  linkElement.setFieldValue(depItem.getExportFieldValue()); | 
  | 250 | 0 |                  linkElement.setSubset(depItem.getExportElementSubset(parent)); | 
  | 251 | 0 |                  linkElementSubItems.add(linkElement); | 
  | 252 | 0 |              } | 
  | 253 | 0 |              return linkElementSubItems; | 
  | 254 |  |          } | 
  | 255 |  |   | 
  | 256 |  |          @Override | 
  | 257 |  |          public String getExportFieldValue() { | 
  | 258 | 0 |              String text = null; | 
  | 259 | 0 |              for (int i = 0; i < this.linkPanel.getWidgetCount(); i++) { | 
  | 260 | 0 |                  Widget child = this.linkPanel.getWidget(i); | 
  | 261 | 0 |                  if (child instanceof SpanPanel) { | 
  | 262 | 0 |                      SpanPanel header = (SpanPanel) child; | 
  | 263 | 0 |                      text = header.getText(); | 
  | 264 |  |                  } | 
  | 265 |  |              } | 
  | 266 | 0 |              return text; | 
  | 267 |  |          } | 
  | 268 |  |      } | 
  | 269 |  |   | 
  | 270 |  |      public void hide(String dependencySection, String dependencyType) { | 
  | 271 | 0 |          DependencyTypeSection typeSection = dependencyTypeSections.get(dependencySection + "." + dependencyType); | 
  | 272 | 0 |          if (typeSection != null) { | 
  | 273 | 0 |              typeSection.setVisible(false); | 
  | 274 | 0 |              DependencySection section = dependencySections.get(dependencySection); | 
  | 275 | 0 |              section.setVisibility(); | 
  | 276 |  |          } | 
  | 277 | 0 |      } | 
  | 278 |  |   | 
  | 279 |  |      public void show(String dependencySection, String dependencyType) { | 
  | 280 | 0 |          DependencyTypeSection typeSection = dependencyTypeSections.get(dependencySection + "." + dependencyType); | 
  | 281 | 0 |          if (typeSection != null) { | 
  | 282 | 0 |              typeSection.setVisible(true); | 
  | 283 | 0 |              DependencySection section = dependencySections.get(dependencySection); | 
  | 284 | 0 |              section.setVisibility(); | 
  | 285 |  |          } | 
  | 286 | 0 |      } | 
  | 287 |  |   | 
  | 288 |  |      public void hideAll() { | 
  | 289 | 0 |          for (DependencyTypeSection typeSection : dependencyTypeSections.values()) { | 
  | 290 | 0 |              typeSection.setVisible(false); | 
  | 291 |  |          } | 
  | 292 | 0 |          for (DependencySection section : dependencySections.values()) { | 
  | 293 | 0 |              section.setVisible(false); | 
  | 294 |  |          } | 
  | 295 | 0 |      } | 
  | 296 |  |   | 
  | 297 |  |      public void showAll() { | 
  | 298 | 0 |          for (DependencyTypeSection typeSection : dependencyTypeSections.values()) { | 
  | 299 | 0 |              typeSection.setVisible(true); | 
  | 300 |  |          } | 
  | 301 | 0 |          for (DependencySection section : dependencySections.values()) { | 
  | 302 | 0 |              section.setVisible(section.dependencyTypeSections.size() > 0); | 
  | 303 |  |          } | 
  | 304 | 0 |      } | 
  | 305 |  |   | 
  | 306 |  |      public VerticalFieldLayout getDependencySectionContainer() { | 
  | 307 | 0 |          return dependencySectionContainer; | 
  | 308 |  |      } | 
  | 309 |  |   | 
  | 310 |  |      @Override | 
  | 311 |  |      public boolean isExportElement() { | 
  | 312 | 0 |          return true; | 
  | 313 |  |      } | 
  | 314 |  |   | 
  | 315 |  |      @Override | 
  | 316 |  |      public List<ExportElement> getExportElementSubset(ExportElement parent) { | 
  | 317 | 0 |          ArrayList<ExportElement> returnItems = new ArrayList<ExportElement>(); | 
  | 318 |  |           | 
  | 319 | 0 |          if (this.getWidget() instanceof VerticalFieldLayout) { | 
  | 320 | 0 |              VerticalFieldLayout verticalFieldLayoutWidget = (VerticalFieldLayout) this.getWidget(); | 
  | 321 | 0 |              returnItems.addAll(ExportUtils.getDetailsForWidget(verticalFieldLayoutWidget.getVerticalLayout(), parent.getViewName(), parent.getSectionName())); | 
  | 322 |  |          } | 
  | 323 |  |           | 
  | 324 | 0 |          for (DependencySection section : this.dependencySections.values()) { | 
  | 325 | 0 |              returnItems.addAll(ExportUtils.getDetailsForWidget(section, parent.getViewName(), parent.getSectionName())); | 
  | 326 |  |          } | 
  | 327 | 0 |          return returnItems; | 
  | 328 |  |      } | 
  | 329 |  |   | 
  | 330 |  |      @Override | 
  | 331 |  |      public String getExportFieldValue() { | 
  | 332 | 0 |          return null; | 
  | 333 |  |      } | 
  | 334 |  |   | 
  | 335 |  |  } |