View Javadoc
1   /***************************************************************************
2    * Copyright (C) 2003-2009 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   **************************************************************************/
18  package org.exoplatform.ecm.webui.component.admin.templates.clv;
19  
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.config.annotation.ComponentConfigs;
22  import org.exoplatform.webui.config.annotation.EventConfig;
23  import org.exoplatform.webui.core.UIComponent;
24  import org.exoplatform.webui.core.UIContainer;
25  import org.exoplatform.webui.core.UIPopupWindow;
26  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
27  import org.exoplatform.webui.event.Event;
28  import org.exoplatform.webui.event.EventListener;
29  
30  /**
31   * Created by The eXo Platform SARL
32   * Author : Dang Van Minh
33   *          minh.dang@exoplatform.com
34   * Jan 22, 2013
35   * 9:55:37 AM  
36   */
37  @ComponentConfigs( {
38    @ComponentConfig(lifecycle = UIContainerLifecycle.class),           
39    @ComponentConfig(
40            type = UIPopupWindow.class, id="UICLVTemplateContainer", template = "system:/groovy/webui/core/UIPopupWindow.gtmpl", 
41            events = @EventConfig(listeners = UICLVTemplateContainer.CloseActionListener.class))})
42  
43  public class UICLVTemplateContainer  extends UIContainer  {
44    
45    public UICLVTemplateContainer() throws Exception {
46      addChild(UICLVTemplateList.class, null, null);
47    }
48  
49    public void initPopup(UIComponent uiComponent, String popupId) throws Exception {
50      removeChildById(popupId) ;    
51      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ;
52      uiPopup.setShowMask(true);    
53      uiPopup.setWindowSize(600,300) ;
54      uiPopup.setUIComponent(uiComponent) ;
55      uiPopup.setShow(true) ;
56      uiPopup.setResizable(true) ;
57    }
58    
59    public void update() throws Exception {
60      UICLVTemplateList uiTemplateList = getChild(UICLVTemplateList.class);
61      uiTemplateList.refresh(uiTemplateList.getUIPageIterator().getCurrentPage());
62    }  
63    
64    public static class CloseActionListener extends EventListener<UIPopupWindow> {
65      public void execute(Event<UIPopupWindow> event) throws Exception {
66        UICLVTemplatesManager uiTemplateManager = event.getSource().getAncestorOfType(UICLVTemplatesManager.class) ;
67        UICLVTemplateContainer uiTemplateContainer = uiTemplateManager.getChildById(uiTemplateManager.getSelectedTabId());
68        UIPopupWindow uiPopupWindow = uiTemplateContainer.getChild(UIPopupWindow.class) ;
69        uiPopupWindow.setRendered(false) ;
70        event.getRequestContext().addUIComponentToUpdateByAjax(uiTemplateManager) ;
71      }
72    }
73  }