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.ecm.webui.component.admin.templates;
18  
19  import org.exoplatform.ecm.webui.selector.UIPermissionSelector;
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.config.annotation.ComponentConfigs;
22  import org.exoplatform.webui.core.UIComponent;
23  import org.exoplatform.webui.core.UIContainer;
24  import org.exoplatform.webui.core.UIPopupWindow;
25  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
26  import org.exoplatform.webui.event.Event;
27  import org.exoplatform.webui.event.EventListener;
28  
29  /**
30   * Created by The eXo Platform SARL
31   * Author : Dang Van Minh
32   *          minh.dang@exoplatform.com
33   * Nov 23, 2006
34   * 2:09:18 PM
35   */
36  @ComponentConfigs( {
37    @ComponentConfig(lifecycle = UIContainerLifecycle.class)	
38  })
39  
40  public class UITemplateContainer extends UIContainer {
41  
42    public UITemplateContainer() throws Exception {
43      addChild(UITemplateList.class, null, null) ;
44    }
45  
46    public void initPopup(UIComponent uiComponent, String popupId) throws Exception {
47      removeChildById(popupId) ;    
48      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ;
49      uiPopup.setShowMask(true);    
50      uiPopup.setWindowSize(600,300) ;
51      uiPopup.setUIComponent(uiComponent) ;
52      uiPopup.setShow(true) ;
53      uiPopup.setResizable(true) ;
54    }
55  
56    public void update() throws Exception {
57      UITemplateList uiTemplateList = getChild(UITemplateList.class);
58      uiTemplateList.refresh(uiTemplateList.getUIPageIterator().getCurrentPage());
59    }  
60  
61    public void initPopupPermission(String id, String membership) throws Exception {  	
62      String popupId = id.concat(UITemplateContent.TEMPLATE_PERMISSION);
63      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId);
64      uiPopup.setShowMask(true);
65      uiPopup.setWindowSize(560, 300);
66      UIPermissionSelector uiECMPermission = createUIComponent(UIPermissionSelector.class, null, null);
67      uiECMPermission.setSelectedMembership(true);
68      if (membership != null && membership.indexOf(":/") > -1) {
69        String[] arrMember = membership.split(":/");
70        uiECMPermission.setCurrentPermission("/" + arrMember[1]);
71      }
72      if (id.equals("AddNew")) {
73        UITemplateForm uiForm = findFirstComponentOfType(UITemplateForm.class);
74        uiECMPermission.setSourceComponent(uiForm, null);
75      } else {
76        UITemplateContent uiTemContent = findComponentById(id);
77        uiECMPermission.setSourceComponent(uiTemContent, null);
78      }
79      uiPopup.setUIComponent(uiECMPermission);
80      uiPopup.setRendered(true);
81      uiPopup.setShow(true);
82      uiPopup.setResizable(true);
83    }
84    public static class CloseActionListener extends EventListener<UIPopupWindow> {
85      public void execute(Event<UIPopupWindow> event) throws Exception {
86        UITemplatesManager uiManager = event.getSource().getAncestorOfType(UITemplatesManager.class) ;
87        UITemplateContainer uiTemplateContainer = uiManager.getChildById(uiManager.getSelectedTabId());
88        UIPopupWindow uiPopupWindow = uiTemplateContainer.getChild(UIPopupWindow.class) ;
89        uiPopupWindow.setRendered(false) ;
90        event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ;
91      }
92    }
93  }