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.drives;
18  
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.List;
22  
23  import javax.jcr.RepositoryException;
24  
25  import org.exoplatform.ecm.webui.component.admin.UIECMAdminPortlet;
26  import org.exoplatform.ecm.webui.selector.UIAnyPermission;
27  import org.exoplatform.ecm.webui.selector.UIPermissionSelector;
28  import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector;
29  import org.exoplatform.ecm.webui.utils.Utils;
30  import org.exoplatform.services.jcr.RepositoryService;
31  import org.exoplatform.services.jcr.core.ManageableRepository;
32  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
33  import org.exoplatform.webui.config.annotation.ComponentConfig;
34  import org.exoplatform.webui.core.UIBreadcumbs;
35  import org.exoplatform.webui.core.UIPopupWindow;
36  import org.exoplatform.webui.core.UITree;
37  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
38  import org.exoplatform.webui.ext.manager.UIAbstractManager;
39  
40  /**
41   * Created by The eXo Platform SARL
42   * Author : Tran The Trong
43   *          trongtt@exoplatform.com
44   * Sep 19, 2006
45   * 11:45:11 AM
46   */
47  @ComponentConfig(lifecycle = UIContainerLifecycle.class)
48  public class UIDriveManager extends UIAbstractManager {
49  
50    public UIDriveManager() throws Exception {
51      addChild(UIDriveList.class, null, null) ;
52    }
53  
54    public void refresh() throws Exception  {
55      update();
56    }
57  
58    public void update() throws Exception  {
59      UIDriveList uiDriveList = getChild(UIDriveList.class);
60      uiDriveList.refresh(1);
61    }
62    public void initPopup(String id) throws Exception {
63      UIDriveForm uiDriveForm ;
64      UIPopupWindow uiPopup = getChildById(id) ;
65      if(uiPopup == null) {
66        uiPopup = addChild(UIPopupWindow.class, null, id) ;
67        uiPopup.setShowMask(true);
68        uiPopup.setWindowSize(590,420) ;
69        uiDriveForm = createUIComponent(UIDriveForm.class, null, null) ;
70      } else {
71        uiDriveForm = uiPopup.findFirstComponentOfType(UIDriveForm.class) ;
72        uiPopup.setRendered(true) ;
73      }
74      uiPopup.setUIComponent(uiDriveForm) ;
75      uiPopup.setShow(true) ;
76      uiPopup.setResizable(true) ;
77    }
78  
79    public void initPopupPermission(String membership) throws Exception {
80      removeChildById(UIDriveForm.POPUP_DRIVEPERMISSION) ;
81      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, UIDriveForm.POPUP_DRIVEPERMISSION);
82      uiPopup.setShowMask(true);
83      uiPopup.setWindowSize(580, 300);
84      UIPermissionSelector uiECMPermission =
85        createUIComponent(UIPermissionSelector.class, null, "UIDrivePermissionSelector") ;
86      uiECMPermission.setSelectedMembership(true);
87      uiECMPermission.getChild(UIAnyPermission.class).setId("UIMDriveAnyPermission");
88      uiECMPermission.getChild(UIBreadcumbs.class).setId("DriveBreadcumbGroupSelector");
89      uiECMPermission.getChild(UITree.class).setId("UIDriveTreeGroupSelector");
90      if(membership != null && membership.indexOf(":/") > -1) {
91        String[] arrMember = membership.split(":/") ;
92        uiECMPermission.setCurrentPermission("/" + arrMember[1]) ;
93      }
94      uiPopup.setUIComponent(uiECMPermission);
95      UIDriveForm uiDriveForm = findFirstComponentOfType(UIDriveForm.class) ;
96      uiECMPermission.setSourceComponent(uiDriveForm, new String[] {UIDriveInputSet.FIELD_PERMISSION}) ;
97      uiPopup.setShow(true) ;
98    }
99  
100   public void initPopupNodeTypeSelector(String nodeTypes) throws Exception {
101     removeChildById(UIDriveForm.POPUP_NODETYPE_SELECTOR) ;
102     UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, UIDriveForm.POPUP_NODETYPE_SELECTOR);
103     uiPopup.setShowMask(true);
104     uiPopup.setWindowSize(580, 300);
105     uiPopup.setResizable(true);
106     UINodeTypeSelector uiNodeTypeSelector =
107       createUIComponent(UINodeTypeSelector.class, null, null) ;
108     uiNodeTypeSelector.setRepositoryName(getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository());
109     List<String> nodeList = new ArrayList<String>();
110     if (nodeTypes != null) {
111       if(nodeTypes.indexOf(",") > -1) {
112       nodeList = Arrays.asList(nodeTypes.split(","));
113       } else {
114        nodeList.add(nodeTypes);
115       }
116     }
117     uiNodeTypeSelector.init(1, nodeList);
118     uiPopup.setUIComponent(uiNodeTypeSelector);
119     UIDriveForm uiDriveForm = findFirstComponentOfType(UIDriveForm.class) ;
120     uiNodeTypeSelector.setSourceComponent(uiDriveForm, new String[] {UIDriveInputSet.FIELD_ALLOW_NODETYPES_ON_TREE}) ;
121     uiPopup.setShow(true) ;
122   }
123 
124   private String getSystemWorkspaceName() throws RepositoryException {
125     RepositoryService repositoryService = getApplicationComponent(RepositoryService.class);
126     ManageableRepository manageableRepository = repositoryService.getCurrentRepository();
127     return manageableRepository.getConfiguration().getSystemWorkspaceName();
128   }
129 
130   public void initPopupJCRBrowser(String workspace, boolean isDisable) throws Exception {
131     removeChildById("JCRBrowser") ;
132     removeChildById("JCRBrowserAssets") ;
133     String repository = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository() ;
134     UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "JCRBrowser");
135     uiPopup.setShowMask(true);
136     uiPopup.setWindowSize(610, 300);
137     UIOneNodePathSelector uiOneNodePathSelector =
138       createUIComponent(UIOneNodePathSelector.class, null, null);
139     uiOneNodePathSelector.setIsDisable(workspace, isDisable) ;
140     uiOneNodePathSelector.setShowRootPathSelect(true) ;
141     uiOneNodePathSelector.setRootNodeLocation(repository, workspace, "/");
142     if(WCMCoreUtils.isAnonim()) {
143       uiOneNodePathSelector.init(WCMCoreUtils.createAnonimProvider()) ;
144     } else {
145       uiOneNodePathSelector.init(WCMCoreUtils.getSystemSessionProvider()) ;
146     }
147     uiPopup.setUIComponent(uiOneNodePathSelector);
148     UIDriveForm uiDriveForm = findFirstComponentOfType(UIDriveForm.class) ;
149     uiOneNodePathSelector.setSourceComponent(uiDriveForm, new String[] {UIDriveInputSet.FIELD_HOMEPATH}) ;
150     uiPopup.setShow(true) ;
151   }
152 
153   public void initPopupJCRBrowserAssets(String workspace) throws Exception {
154     removeChildById("JCRBrowserAssets") ;
155     removeChildById("JCRBrowser") ;
156     UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, "JCRBrowserAssets");
157     uiPopup.setShowMask(true);
158     uiPopup.setWindowSize(610, 300);
159     UIOneNodePathSelector uiOneNodePathSelector =
160       createUIComponent(UIOneNodePathSelector.class, null, null);
161     UIDriveForm uiDriveForm = findFirstComponentOfType(UIDriveForm.class) ;
162     String repository = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository() ;
163     uiOneNodePathSelector.setAcceptedNodeTypesInPathPanel(new String[] {Utils.NT_FILE}) ;
164     uiOneNodePathSelector.setAcceptedNodeTypesInTree(new String[] {Utils.NT_UNSTRUCTURED, Utils.NT_FOLDER});
165     uiOneNodePathSelector.setAcceptedMimeTypes(new String[] {"image/jpeg", "image/gif", "image/png"}) ;
166     uiOneNodePathSelector.setRootNodeLocation(repository, workspace, "/");
167     if(WCMCoreUtils.isAnonim()) {
168       uiOneNodePathSelector.init(WCMCoreUtils.createAnonimProvider()) ;
169     } else {
170       uiOneNodePathSelector.init(WCMCoreUtils.getSystemSessionProvider()) ;
171     }
172     uiOneNodePathSelector.setSourceComponent(uiDriveForm, new String[] {UIDriveInputSet.FIELD_WORKSPACEICON}) ;
173     uiPopup.setUIComponent(uiOneNodePathSelector);
174     uiPopup.setShow(true) ;
175   }
176 }