001    package org.hackystat.projectbrowser.page.popupwindow;
002    
003    import org.apache.wicket.ResourceReference;
004    import org.apache.wicket.ajax.AjaxRequestTarget;
005    import org.apache.wicket.ajax.markup.html.AjaxLink;
006    import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
007    import org.apache.wicket.markup.html.basic.Label;
008    import org.apache.wicket.markup.html.image.Image;
009    import org.apache.wicket.markup.html.panel.Panel;
010    
011    /**
012     * A panel that contains a popup window.
013     * @author Shaoxuan Zhang
014     */
015    public class PopupWindowPanel extends Panel {
016      /** Support serialization. */
017      private static final long serialVersionUID = 1L;
018      /** The modal window inside this panel. */
019      private final ModalWindow modalWindow;
020    
021      /**
022       * Create the pop up window link as a question mark.
023       * 
024       * @param id the wicket component id.
025       * @param title the title of the popup window.
026       */
027      public PopupWindowPanel(String id, String title) {
028        this(id, title, "");
029      }
030      
031      /**
032       * Create the pop up window link as the given link label.
033       * 
034       * @param id the wicket component id.
035       * @param title the title of the popup window.
036       * @param linkLabel the link label.
037       */
038      public PopupWindowPanel(String id, String title, String linkLabel) {
039        super(id);
040        modalWindow = new ModalWindow("modalWindow");
041        add(modalWindow);
042    
043        modalWindow.setCookieName("modalWindow");
044        modalWindow.setTitle(title);
045    
046        modalWindow.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
047          /** Support serialization. */
048          private static final long serialVersionUID = 1L;
049            public boolean onCloseButtonClicked(AjaxRequestTarget target) {
050                return true;
051            }
052        });
053        
054        AjaxLink link = new AjaxLink("showModalWindow") {
055          /** Support serialization. */
056          private static final long serialVersionUID = 1L;
057            @Override
058            public void onClick(AjaxRequestTarget target) {
059              modalWindow.show(target);
060            }
061        };
062        
063        link.add(new Label("linkLabel", linkLabel)); 
064        
065        Image img = new Image("icon", new ResourceReference(PopupWindowPanel.class, "question.gif"));
066        img.setVisible(linkLabel.length() == 0);
067        link.add(img);
068        
069        add(link);
070      }
071    
072      /**
073       * @return the modalWindow
074       */
075      public ModalWindow getModalWindow() {
076        return modalWindow;
077      }
078    
079    }