| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.ui.client.widgets.search; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.ArrayList; | 
  | 19 |  |  import java.util.HashMap; | 
  | 20 |  |  import java.util.List; | 
  | 21 |  |  import java.util.Map; | 
  | 22 |  |   | 
  | 23 |  |  import org.kuali.student.common.ui.client.widgets.KSButton; | 
  | 24 |  |  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; | 
  | 25 |  |  import org.kuali.student.common.ui.client.widgets.layout.HorizontalBlockFlowPanel; | 
  | 26 |  |  import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; | 
  | 27 |  |   | 
  | 28 |  |  import com.google.gwt.event.dom.client.ClickEvent; | 
  | 29 |  |  import com.google.gwt.event.dom.client.ClickHandler; | 
  | 30 |  |  import com.google.gwt.user.client.ui.Composite; | 
  | 31 |  |  import com.google.gwt.user.client.ui.SimplePanel; | 
  | 32 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 33 |  |   | 
  | 34 | 0 |  public class LinkPanel extends Composite{ | 
  | 35 |  |   | 
  | 36 | 0 |          private Map<Enum<?>, PanelInfo> panels = new HashMap<Enum<?>, PanelInfo>(); | 
  | 37 | 0 |          private SimplePanel container = new SimplePanel(); | 
  | 38 |  |   | 
  | 39 |  |          private class PanelInfo extends Composite{ | 
  | 40 | 0 |                  private VerticalFlowPanel layout = new VerticalFlowPanel(); | 
  | 41 | 0 |                  private HorizontalBlockFlowPanel linkPanel = new HorizontalBlockFlowPanel(); | 
  | 42 |  |                  private Enum<?> key; | 
  | 43 |  |                  private Widget content; | 
  | 44 | 0 |                  private List<NavLink> links = new ArrayList<NavLink>(); | 
  | 45 | 0 |                  private class NavLink{ | 
  | 46 |  |                          protected String linkName; | 
  | 47 |  |                          protected Enum<?> linkToKey; | 
  | 48 |  |                  } | 
  | 49 |  |   | 
  | 50 | 0 |                  public PanelInfo(Enum<?> key, Widget content){ | 
  | 51 | 0 |                          this.key = key; | 
  | 52 | 0 |                          this.content = content; | 
  | 53 | 0 |                          layout.add(content); | 
  | 54 | 0 |                          layout.add(linkPanel); | 
  | 55 | 0 |                          this.initWidget(layout); | 
  | 56 | 0 |                  } | 
  | 57 |  |   | 
  | 58 |  |                  public KSButton addLink(String linkText, final Enum<?> linkedPanelKey){ | 
  | 59 | 0 |                          NavLink link = new NavLink(); | 
  | 60 | 0 |                          link.linkName = linkText; | 
  | 61 | 0 |                          link.linkToKey = linkedPanelKey; | 
  | 62 | 0 |                          links.add(link); | 
  | 63 |  |                           | 
  | 64 | 0 |                          KSButton linkWidget = new KSButton(linkText, ButtonStyle.DEFAULT_ANCHOR); | 
  | 65 | 0 |                          linkWidget.addClickHandler(new ClickHandler(){ | 
  | 66 |  |   | 
  | 67 |  |                                  @Override | 
  | 68 |  |                                  public void onClick(ClickEvent event) { | 
  | 69 | 0 |                                          Widget newPanel = panels.get(linkedPanelKey); | 
  | 70 | 0 |                                          container.setWidget(newPanel); | 
  | 71 | 0 |                                  } | 
  | 72 |  |                          }); | 
  | 73 |  |   | 
  | 74 | 0 |                          linkPanel.add(linkWidget); | 
  | 75 | 0 |                          return linkWidget; | 
  | 76 |  |                  } | 
  | 77 |  |          } | 
  | 78 |  |   | 
  | 79 | 0 |          public LinkPanel(Enum<?> defaultPanelKey, Widget content){ | 
  | 80 | 0 |                  PanelInfo info = new PanelInfo(defaultPanelKey, content); | 
  | 81 | 0 |                  panels.put(defaultPanelKey, info); | 
  | 82 | 0 |                  container.setWidget(info); | 
  | 83 | 0 |                  this.initWidget(container); | 
  | 84 | 0 |          } | 
  | 85 |  |   | 
  | 86 |  |          public void addPanel(Enum<?> panelKey, Widget content){ | 
  | 87 | 0 |                  PanelInfo info = new PanelInfo(panelKey, content); | 
  | 88 | 0 |                  panels.put(panelKey, info); | 
  | 89 | 0 |          } | 
  | 90 |  |   | 
  | 91 |  |          public KSButton addLinkToPanel(Enum<?> panelKey, String linkText, Enum<?> linkedPanelKey){ | 
  | 92 | 0 |                  PanelInfo info = panels.get(panelKey); | 
  | 93 | 0 |                  return info.addLink(linkText, linkedPanelKey); | 
  | 94 |  |          } | 
  | 95 |  |  } |