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.ecm.webui.component.admin.UIECMAdminPortlet;
21  import org.exoplatform.webui.application.WebuiRequestContext;
22  import org.exoplatform.webui.config.annotation.ComponentConfig;
23  import org.exoplatform.webui.config.annotation.EventConfig;
24  import org.exoplatform.webui.core.UIComponent;
25  import org.exoplatform.webui.core.UIPopupContainer;
26  import org.exoplatform.webui.core.UIPopupWindow;
27  import org.exoplatform.webui.event.Event;
28  import org.exoplatform.webui.event.EventListener;
29  import org.exoplatform.webui.ext.manager.UIAbstractManager;
30  
31  /**
32   * Created by The eXo Platform SARL
33   * Author : Dang Van Minh
34   *          minh.dang@exoplatform.com
35   * Jan 22, 2013
36   * 9:47:27 AM  
37   */
38  @ComponentConfig(template = "system:/groovy/webui/core/UITabPane_New.gtmpl", 
39  events = { @EventConfig(listeners = UICLVTemplatesManager.SelectTabActionListener.class) })
40  public class UICLVTemplatesManager extends UIAbstractManager{
41  
42    public static final String NEW_TEMPLATE = "CLVTemplatePopup" ;
43    public static final String EDIT_CLV_TEMPLATE = "EditCLVTemplatePopup" ;
44    public static final String CONTENT_TEMPLATE_ID = "ContentTemplateContainer";
45    public static final String CATE_TEMPLATE_ID = "CateTemplateContainer";
46    public static final String PAGE_TEMPLATE_ID = "PageTemplateContainer";
47    public static final String CATE_TEMPLATE_LIST_ID = "CateTemplateList";
48    public static final String PAGE_TEMPLATE_LIST_ID  = "PageTemplateList";
49    public static final String CONTENT_TEMPLATE_TYPE = "contents";
50    public static final String CATEGORY_TEMPLATE_TYPE = "category";
51    public static final String PAGINATOR_TEMPLATE_TYPE = "paginators";
52    
53    private String selectedTabId = "ContentTemplateContainer";
54  
55    public UICLVTemplatesManager() throws Exception {
56      UICLVTemplateContainer uiContentTemp = addChild(UICLVTemplateContainer.class, null, CONTENT_TEMPLATE_ID) ;
57      uiContentTemp.getChild(UICLVTemplateList.class).setTemplateFilter(CONTENT_TEMPLATE_TYPE);
58      
59      UICLVTemplateContainer uiCateTemp = addChild(UICLVTemplateContainer.class, null, CATE_TEMPLATE_ID) ;
60      uiCateTemp.getChild(UICLVTemplateList.class).setTemplateFilter(CATEGORY_TEMPLATE_TYPE);
61      uiCateTemp.getChild(UICLVTemplateList.class).setId(CATE_TEMPLATE_LIST_ID);
62      
63      UICLVTemplateContainer uiPageTemp = addChild(UICLVTemplateContainer.class, null, PAGE_TEMPLATE_ID) ;
64      uiPageTemp.getChild(UICLVTemplateList.class).setTemplateFilter(PAGINATOR_TEMPLATE_TYPE);
65      uiPageTemp.getChild(UICLVTemplateList.class).setId(PAGE_TEMPLATE_LIST_ID);
66      
67      setSelectedTab(CONTENT_TEMPLATE_ID);
68    }
69    
70    @Override
71    public void refresh() throws Exception {
72      UICLVTemplateContainer templateContainer = ((UICLVTemplateContainer)getChildById(CONTENT_TEMPLATE_ID));
73      templateContainer.update();
74      templateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().setId(CONTENT_TEMPLATE_ID + "PageIterator");
75      templateContainer.getChild(UICLVTemplateList.class).refresh(
76              templateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().getCurrentPage());
77      
78      UICLVTemplateContainer templateCateContainer = ((UICLVTemplateContainer)getChildById(CATE_TEMPLATE_ID));
79      templateCateContainer.update();
80      templateCateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().setId(CATE_TEMPLATE_ID + "PageIterator");
81      templateCateContainer.getChild(UICLVTemplateList.class).refresh(
82              templateCateContainer.getChild(UICLVTemplateList.class).getUIPageIterator().getCurrentPage());
83      
84      UICLVTemplateContainer templatePageContainer = ((UICLVTemplateContainer)getChildById(PAGE_TEMPLATE_ID));
85      templatePageContainer.update();
86      templatePageContainer.getChild(UICLVTemplateList.class).getUIPageIterator().setId(PAGE_TEMPLATE_ID + "PageIterator");
87      templatePageContainer.getChild(UICLVTemplateList.class).refresh(
88              templatePageContainer.getChild(UICLVTemplateList.class).getUIPageIterator().getCurrentPage());
89    }
90  
91    public String getSelectedTabId()
92    {
93       return selectedTabId;
94    }  
95    
96    public void setSelectedTab(String renderTabId)
97    {
98       selectedTabId = renderTabId;
99    }
100 
101   public void setSelectedTab(int index)
102   {
103      selectedTabId = getChild(index - 1).getId();
104   }  
105   
106   public boolean isEditingTemplate() {
107     UIECMAdminPortlet adminPortlet = this.getAncestorOfType(UIECMAdminPortlet.class);
108     UIPopupContainer popupContainer = adminPortlet.getChild(UIPopupContainer.class);
109     UIPopupWindow uiPopup = popupContainer.getChild(UIPopupWindow.class);
110     uiPopup.setId(EDIT_CLV_TEMPLATE);
111     return (uiPopup != null && uiPopup.isShow() && uiPopup.isRendered());
112   }
113   
114   static public class SelectTabActionListener extends EventListener<UICLVTemplatesManager>
115   {
116     public void execute(Event<UICLVTemplatesManager> event) throws Exception
117     {
118        WebuiRequestContext context = event.getRequestContext();
119        String renderTab = context.getRequestParameter(UIComponent.OBJECTID);
120        if (renderTab == null)
121           return;
122        event.getSource().setSelectedTab(renderTab);
123        WebuiRequestContext parentContext = (WebuiRequestContext)context.getParentAppRequestContext();
124        if (parentContext != null)
125        {
126           parentContext.setResponseComplete(true);
127        }
128        else
129        {
130           context.setResponseComplete(true);
131        }
132     }
133   } 
134 
135 }