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.metadata;
18  
19  import javax.jcr.nodetype.NodeType;
20  
21  import org.exoplatform.ecm.webui.selector.UIAnyPermission;
22  import org.exoplatform.ecm.webui.selector.UIPermissionSelector;
23  import org.exoplatform.services.jcr.RepositoryService;
24  import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
25  import org.exoplatform.webui.application.WebuiRequestContext;
26  import org.exoplatform.webui.config.annotation.ComponentConfig;
27  import org.exoplatform.webui.core.UIBreadcumbs;
28  import org.exoplatform.webui.core.UIPopupWindow;
29  import org.exoplatform.webui.core.UITree;
30  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
31  import org.exoplatform.webui.ext.manager.UIAbstractManager;
32  
33  /**
34   * Created by The eXo Platform SARL
35   * Author : Dang Van Minh
36   *          minh.dang@exoplatform.com
37   * Sep 19, 2006
38   * 11:45:11 AM
39   */
40  @ComponentConfig(lifecycle = UIContainerLifecycle.class)
41  public class UIMetadataManager extends UIAbstractManager {
42  
43    final static public String METADATA_POPUP = "MetadataPopupEdit" ;
44    final static public String VIEW_METADATA_POPUP = "ViewMetadataPopup" ;
45    final static public String PERMISSION_POPUP = "MetataPermissionPopup" ;
46  
47    public UIMetadataManager() throws Exception {
48      addChild(UIMetadataList.class, null, null) ;
49    }
50  
51    public void processRender(WebuiRequestContext context) throws Exception { 
52      super.processRender(context);
53      refresh();
54    }
55  
56    public void refresh() throws Exception {
57      update();
58    }
59  
60    public void update() throws Exception {
61      getChild(UIMetadataList.class).refresh(1);
62    }
63    public void initPopup() throws Exception {
64      removeChildById(METADATA_POPUP) ;
65      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, METADATA_POPUP);
66      uiPopup.setShowMask(true);
67      uiPopup.setWindowSize(650, 330);
68      UIMetadataForm uiMetaForm = createUIComponent(UIMetadataForm.class, null, null) ;
69      uiPopup.setUIComponent(uiMetaForm) ;
70      uiPopup.setRendered(true);
71      uiPopup.setShow(true) ;
72      uiPopup.setResizable(true) ;
73    }
74  
75    public void initViewPopup(String metadataName) throws Exception {
76      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, VIEW_METADATA_POPUP);
77      uiPopup.setShowMask(true);
78      uiPopup.setShow(true) ;
79      uiPopup.setWindowSize(600, 300);
80      uiPopup.setRendered(true);
81      RepositoryService repositoryService = getApplicationComponent(RepositoryService.class) ;
82      ExtendedNodeTypeManager ntManager = repositoryService.getCurrentRepository().getNodeTypeManager() ;
83      NodeType nodeType = ntManager.getNodeType(metadataName) ;
84      UIMetadataView uiView = uiPopup.createUIComponent(UIMetadataView.class, null, null) ;
85      uiView.setMetadata(nodeType) ;
86      uiPopup.setUIComponent(uiView) ;
87      uiPopup.setResizable(true) ;
88    }
89  
90    public void initPopupPermission(String membership) throws Exception {
91      removeChildById(PERMISSION_POPUP) ;
92      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, PERMISSION_POPUP);
93      uiPopup.setShowMask(true);
94      uiPopup.setWindowSize(560, 300);
95      UIPermissionSelector uiECMPermission =
96          createUIComponent(UIPermissionSelector.class, null, "MetadataPermission") ;
97      uiECMPermission.getChild(UIAnyPermission.class).setId("UIMetadataAnyPermission");
98      uiECMPermission.getChild(UIBreadcumbs.class).setId("MetadataBreadcumbGroupSelector");
99      uiECMPermission.getChild(UITree.class).setId("UIMetadataTreeGroupSelector");
100 
101     uiECMPermission.setSelectedMembership(true);
102     if(membership != null && membership.indexOf(":/") > -1) {
103       String[] arrMember = membership.split(":/") ;
104       uiECMPermission.setCurrentPermission("/" + arrMember[1]) ;
105     }
106     uiPopup.setUIComponent(uiECMPermission);
107     UIMetadataForm uiForm = findFirstComponentOfType(UIMetadataForm.class) ;
108     uiECMPermission.setSourceComponent(uiForm, null) ;
109     uiPopup.setRendered(true) ;
110     uiPopup.setShow(true) ;
111   }
112 }