001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.student.common.ui.client.widgets.search;
017    
018    import java.util.ArrayList;
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.kuali.student.common.ui.client.widgets.KSButton;
024    import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
025    import org.kuali.student.common.ui.client.widgets.layout.HorizontalBlockFlowPanel;
026    import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
027    
028    import com.google.gwt.event.dom.client.ClickEvent;
029    import com.google.gwt.event.dom.client.ClickHandler;
030    import com.google.gwt.user.client.ui.Composite;
031    import com.google.gwt.user.client.ui.SimplePanel;
032    import com.google.gwt.user.client.ui.Widget;
033    
034    public class LinkPanel extends Composite{
035    
036            private Map<Enum<?>, PanelInfo> panels = new HashMap<Enum<?>, PanelInfo>();
037            private SimplePanel container = new SimplePanel();
038    
039            private class PanelInfo extends Composite{
040                    private VerticalFlowPanel layout = new VerticalFlowPanel();
041                    private HorizontalBlockFlowPanel linkPanel = new HorizontalBlockFlowPanel();
042                    private Enum<?> key;
043                    private Widget content;
044                    private List<NavLink> links = new ArrayList<NavLink>();
045                    private class NavLink{
046                            protected String linkName;
047                            protected Enum<?> linkToKey;
048                    }
049    
050                    public PanelInfo(Enum<?> key, Widget content){
051                            this.key = key;
052                            this.content = content;
053                            layout.add(content);
054                            layout.add(linkPanel);
055                            this.initWidget(layout);
056                    }
057    
058                    public KSButton addLink(String linkText, final Enum<?> linkedPanelKey){
059                            NavLink link = new NavLink();
060                            link.linkName = linkText;
061                            link.linkToKey = linkedPanelKey;
062                            links.add(link);
063                            //KSLabel linkWidget = new KSLabel(linkText);
064                            KSButton linkWidget = new KSButton(linkText, ButtonStyle.DEFAULT_ANCHOR);
065                            linkWidget.addClickHandler(new ClickHandler(){
066    
067                                    @Override
068                                    public void onClick(ClickEvent event) {
069                                            Widget newPanel = panels.get(linkedPanelKey);
070                                            container.setWidget(newPanel);
071                                    }
072                            });
073    
074                            linkPanel.add(linkWidget);
075                            return linkWidget;
076                    }
077            }
078    
079            public LinkPanel(Enum<?> defaultPanelKey, Widget content){
080                    PanelInfo info = new PanelInfo(defaultPanelKey, content);
081                    panels.put(defaultPanelKey, info);
082                    container.setWidget(info);
083                    this.initWidget(container);
084            }
085    
086            public void addPanel(Enum<?> panelKey, Widget content){
087                    PanelInfo info = new PanelInfo(panelKey, content);
088                    panels.put(panelKey, info);
089            }
090    
091            public KSButton addLinkToPanel(Enum<?> panelKey, String linkText, Enum<?> linkedPanelKey){
092                    PanelInfo info = panels.get(panelKey);
093                    return info.addLink(linkText, linkedPanelKey);
094            }
095    }