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.taxonomy.tree.info;
19  
20  import javax.jcr.Node;
21  
22  import org.exoplatform.ecm.permission.info.UIPermissionInputSet;
23  import org.exoplatform.ecm.utils.lock.LockUtil;
24  import org.exoplatform.ecm.webui.core.UIPermissionManagerBase;
25  import org.exoplatform.ecm.webui.utils.PermissionUtil;
26  import org.exoplatform.ecm.webui.utils.Utils;
27  import org.exoplatform.webui.config.annotation.ComponentConfig;
28  import org.exoplatform.webui.core.UIComponent;
29  import org.exoplatform.webui.core.UIGrid;
30  import org.exoplatform.webui.core.UIPopupWindow;
31  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
32  import org.exoplatform.webui.event.Event;
33  import org.exoplatform.webui.event.EventListener;
34  import org.exoplatform.webui.organization.account.UIUserSelector;
35  
36  /**
37   * Created by The eXo Platform SARL
38   * Author : Hoang Van Hung
39   *          hunghvit@gmail.com
40   * Apr 17, 2009
41   */
42  
43  @ComponentConfig(lifecycle = UIContainerLifecycle.class)
44  public class UIPermissionTreeManager extends UIPermissionManagerBase {
45  
46    public static final String POPUP_TAXONOMY_SELECT_USER = "TaxoPopupUserSelector";
47  
48    public UIPermissionTreeManager() throws Exception {
49      addChild(UIPermissionTreeInfo.class, null, null);
50      addChild(UIPermissionTreeForm.class, null, null);
51    }
52  
53    public void initPopupPermission(UIComponent uiSelector) throws Exception {
54      removeChildById(UIPermissionTreeForm.POPUP_SELECT);
55      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, UIPermissionTreeForm.POPUP_SELECT);
56      uiPopup.setShowMask(true);
57      uiPopup.setWindowSize(560, 300);
58      uiPopup.setRendered(true);
59      uiPopup.setUIComponent(uiSelector);
60      uiPopup.setShow(true);
61      uiPopup.setResizable(true);
62    }
63  
64    public void initUserSelector() throws Exception {
65      UIPopupWindow uiPopup = getChildById(POPUP_TAXONOMY_SELECT_USER);
66      if (uiPopup == null) 
67        uiPopup = addChild(UIPopupWindow.class, null, POPUP_TAXONOMY_SELECT_USER);    
68      uiPopup.setShowMask(true);
69      uiPopup.setWindowSize(790, 400);
70      UIPermissionTreeSelectUser uiUserContainer = createUIComponent(UIPermissionTreeSelectUser.class, null, null);
71      uiPopup.setUIComponent(uiUserContainer);
72      uiPopup.setShow(true);
73      uiPopup.setResizable(true);
74    }
75  
76    public void update() throws Exception {
77      getChild(UIPermissionTreeInfo.class).updateGrid();
78    }
79  
80    public void checkPermissonInfo(Node node) throws Exception {
81      if (node.isLocked()) {
82        String lockToken = LockUtil.getLockToken(node);
83        if (lockToken != null)
84          node.getSession().addLockToken(lockToken);
85        if (!Utils.isLockTokenHolder(node)) {
86          getChild(UIPermissionTreeInfo.class).getChild(UIGrid.class).configure("usersOrGroups",
87              UIPermissionTreeInfo.PERMISSION_BEAN_FIELD, new String[] {});
88          getChild(UIPermissionTreeForm.class).setRendered(false);
89        }
90      } else {
91        if (!PermissionUtil.canChangePermission(node)) {
92          getChild(UIPermissionTreeInfo.class).getChild(UIGrid.class).configure("usersOrGroups",
93              UIPermissionTreeInfo.PERMISSION_BEAN_FIELD, new String[] {});
94          getChild(UIPermissionTreeForm.class).setRendered(false);
95        }
96      }
97    }
98  
99    public static class AddUserActionListener extends EventListener<UIUserSelector> {
100     public void execute(Event<UIUserSelector> event) throws Exception {
101       UIUserSelector uiForm = event.getSource();
102       UIPermissionTreeManager uiParent = uiForm.getAncestorOfType(UIPermissionTreeManager.class);
103       UIPermissionTreeForm uiPermissionForm = uiParent.getChild(UIPermissionTreeForm.class);
104       uiPermissionForm.doSelect(UIPermissionInputSet.FIELD_USERORGROUP, uiForm.getSelectedUsers());
105       UIPopupWindow uiPopup = uiParent.getChild(UIPopupWindow.class);
106       uiPopup.setUIComponent(null);
107       uiPopup.setShow(false);
108       event.getRequestContext().addUIComponentToUpdateByAjax(uiParent);
109     }
110   }
111 }