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 public class LinkPanel extends Composite{
35
36 private Map<Enum<?>, PanelInfo> panels = new HashMap<Enum<?>, PanelInfo>();
37 private SimplePanel container = new SimplePanel();
38
39 private class PanelInfo extends Composite{
40 private VerticalFlowPanel layout = new VerticalFlowPanel();
41 private HorizontalBlockFlowPanel linkPanel = new HorizontalBlockFlowPanel();
42 private Enum<?> key;
43 private Widget content;
44 private List<NavLink> links = new ArrayList<NavLink>();
45 private class NavLink{
46 protected String linkName;
47 protected Enum<?> linkToKey;
48 }
49
50 public PanelInfo(Enum<?> key, Widget content){
51 this.key = key;
52 this.content = content;
53 layout.add(content);
54 layout.add(linkPanel);
55 this.initWidget(layout);
56 }
57
58 public KSButton addLink(String linkText, final Enum<?> linkedPanelKey){
59 NavLink link = new NavLink();
60 link.linkName = linkText;
61 link.linkToKey = linkedPanelKey;
62 links.add(link);
63
64 KSButton linkWidget = new KSButton(linkText, ButtonStyle.DEFAULT_ANCHOR);
65 linkWidget.addClickHandler(new ClickHandler(){
66
67 @Override
68 public void onClick(ClickEvent event) {
69 Widget newPanel = panels.get(linkedPanelKey);
70 container.setWidget(newPanel);
71 }
72 });
73
74 linkPanel.add(linkWidget);
75 return linkWidget;
76 }
77 }
78
79 public LinkPanel(Enum<?> defaultPanelKey, Widget content){
80 PanelInfo info = new PanelInfo(defaultPanelKey, content);
81 panels.put(defaultPanelKey, info);
82 container.setWidget(info);
83 this.initWidget(container);
84 }
85
86 public void addPanel(Enum<?> panelKey, Widget content){
87 PanelInfo info = new PanelInfo(panelKey, content);
88 panels.put(panelKey, info);
89 }
90
91 public KSButton addLinkToPanel(Enum<?> panelKey, String linkText, Enum<?> linkedPanelKey){
92 PanelInfo info = panels.get(panelKey);
93 return info.addLink(linkText, linkedPanelKey);
94 }
95 }