View Javadoc
1   /**
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   **/
17  package org.exoplatform.cs.common.webui;
18  
19  import org.exoplatform.webui.application.WebuiRequestContext;
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.core.UIComponent;
22  import org.exoplatform.webui.core.UIContainer;
23  import org.exoplatform.webui.core.UIPopupComponent;
24  import org.exoplatform.webui.core.UIPopupWindow;
25  import org.exoplatform.webui.core.lifecycle.Lifecycle;
26  
27  /**
28   * Created by The eXo Platform SARL 
29   * Author : hung.nguyen@exoplatform.com
30   * Aug 02, 2007 9:43:23 AM
31   */
32  @ComponentConfig( lifecycle = Lifecycle.class )
33  public class UIPopupAction extends UIContainer {
34    public UIPopupAction() throws Exception {
35      addChild(createUIComponent(UIPopupWindow.class, null, null).setRendered(false));
36    }
37  
38    public void processRender(WebuiRequestContext context) throws Exception {
39      context.getWriter().append("<span class=\"").append(getId()).append("\" id=\"").append(getId()).append("\">");
40      renderChildren(context) ;
41      context.getWriter().append("</span>");
42    }
43  
44    public <T extends UIComponent> T activate(Class<T> type, int width) throws Exception {
45      return activate(type, null, width, 0);
46    }
47  
48    public <T extends UIComponent> T activate(Class<T> type, String configId, int width, int height)
49        throws Exception {
50      T comp = createUIComponent(type, configId, null);
51      activate(comp, width, height);
52      return comp;
53    }
54  
55    public void activate(UIComponent uiComponent, int width, int height) throws Exception {
56      activate(uiComponent, width, height, true);
57    }
58  
59    public void activate(UIComponent uiComponent, int width, int height, boolean isResizeable)
60        throws Exception {
61      UIPopupWindow popup = getChild(UIPopupWindow.class);
62      popup.setUIComponent(uiComponent);
63      ((UIPopupComponent) uiComponent).activate();
64      popup.setWindowSize(width, height);
65      popup.setRendered(true);
66      popup.setShow(true);
67      popup.setResizable(isResizeable);
68    }
69  
70    public void deActivate() throws Exception {
71      UIPopupWindow popup = getChild(UIPopupWindow.class);
72      if (popup.getUIComponent() != null)
73        ((UIPopupComponent) popup.getUIComponent()).deActivate();
74      popup.setUIComponent(null);
75      popup.setRendered(false);
76    }
77  
78    public void cancelPopupAction() throws Exception {
79      deActivate();
80      WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
81      context.addUIComponentToUpdateByAjax(this);
82    }
83  }