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.views;
18  
19  import java.util.ResourceBundle;
20  
21  import org.exoplatform.web.application.RequestContext;
22  import org.exoplatform.webui.config.annotation.ComponentConfig;
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  
28  /**
29   * Created by The eXo Platform SARL
30   * Author : Dang Van Minh
31   *          minh.dang@exoplatform.com
32   * Nov 23, 2006
33   * 2:09:18 PM
34   */
35  @ComponentConfig(lifecycle = UIContainerLifecycle.class)
36  public class UIViewContainer extends UIContainer {
37  
38    public UIViewContainer() throws Exception {
39      addChild(UIViewList.class, null, null) ;
40    }
41  
42    public void initPopup(String popupId, UIComponent uiComponent) throws Exception {
43      initPopup(popupId, uiComponent, 600, 300);
44    }  
45    
46    public void initPopup(String popupId, UIComponent uiComponent, int width, int height) throws Exception {
47      removeChildById(popupId) ;
48      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, popupId) ;
49      uiPopup.setShowMask(true);
50      uiPopup.setShowMask(true);
51      uiPopup.setWindowSize(width, height) ;
52      uiPopup.setUIComponent(uiComponent);
53      uiPopup.setShow(true) ;
54      uiPopup.setResizable(true);
55    }    
56  
57    public void update() throws Exception {
58      UIViewList uiViewList = getChild(UIViewList.class);
59      uiViewList.refresh(uiViewList.getUIPageIterator().getCurrentPage());
60    }
61    
62    public String getFriendlyPermission(String permission) throws Exception {
63      RequestContext context = RequestContext.getCurrentInstance();
64      ResourceBundle res = context.getApplicationResourceBundle();
65      String permissionLabel = res.getString(getId() + ".label.permission");
66      if(permission.indexOf(":") > -1) {
67        String[] arr = permission.split(":");
68        if(arr[0].equals("*")) {
69          permissionLabel = permissionLabel.replace("{0}", "Any");
70        } else {
71          permissionLabel = permissionLabel.replace("{0}", standardizeGroupName(arr[0]));
72        }
73        String groupName = arr[1];
74        groupName = groupName.substring(groupName.lastIndexOf("/")+1); 
75        permissionLabel = permissionLabel.replace("{1}", standardizeGroupName(groupName));
76      } else {
77        permissionLabel = standardizeGroupName(permission);
78      }
79      return permissionLabel;
80    }
81    
82    public String standardizeGroupName(String groupName) throws Exception {
83      groupName = groupName.replaceAll("-", " ");
84      char[] stringArray = groupName.toCharArray();
85      stringArray[0] = Character.toUpperCase(stringArray[0]);
86      groupName = new String(stringArray);
87      return groupName;
88    }
89  
90  }