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 org.exoplatform.ecm.permission.info.UIPermissionInputSet;
21  import org.exoplatform.webui.config.annotation.ComponentConfig;
22  import org.exoplatform.webui.config.annotation.EventConfig;
23  import org.exoplatform.webui.core.UIContainer;
24  import org.exoplatform.webui.core.UIPopupComponent;
25  import org.exoplatform.webui.core.UIPopupWindow;
26  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
27  import org.exoplatform.webui.event.Event;
28  import org.exoplatform.webui.event.EventListener;
29  import org.exoplatform.webui.organization.account.UIUserSelector;
30  
31  /**
32   * Created by The eXo Platform SARL
33   * Author : Hoang Van Hung
34   *          hunghvit@gmail.com
35   * Apr 17, 2009
36   */
37  
38  @ComponentConfig(
39      lifecycle = UIContainerLifecycle.class,
40      events = {@EventConfig(listeners = UIPermissionTreeSelectUser.AddUserActionListener.class)}
41  )
42  
43  public class UIPermissionTreeSelectUser extends UIContainer implements UIPopupComponent  {
44  
45    public static final String USER_SELECTOR_ID = "PermissionTreeSelectUser";
46  
47    public UIPermissionTreeSelectUser() throws Exception {
48      UIUserSelector uiUserSelector = getChildById(USER_SELECTOR_ID);
49      if (uiUserSelector == null) {
50        uiUserSelector = addChild(UIUserSelector.class, null, USER_SELECTOR_ID);
51      }
52      uiUserSelector.setMulti(false);
53      uiUserSelector.setShowSearchUser(true);
54      uiUserSelector.setShowSearch(true);
55    }
56  
57    public void activate() {
58  
59    }
60  
61    public void deActivate() {
62    }
63  
64    public static class AddUserActionListener extends EventListener<UIPermissionTreeSelectUser> {
65      public void execute(Event<UIPermissionTreeSelectUser> event) throws Exception {
66        UIPermissionTreeSelectUser uiUserContainer = event.getSource();
67        UIUserSelector uiUserSelector = uiUserContainer.getChildById(USER_SELECTOR_ID);
68        UIPermissionTreeManager uiParent = uiUserContainer.getAncestorOfType(UIPermissionTreeManager.class);
69        UIPermissionTreeForm uiPermissionForm = uiParent.getChild(UIPermissionTreeForm.class);
70        uiPermissionForm.doSelect(UIPermissionInputSet.FIELD_USERORGROUP, uiUserSelector.getSelectedUsers());
71        UIPopupWindow uiPopup = uiParent.findComponentById(UIPermissionTreeManager.POPUP_TAXONOMY_SELECT_USER);
72        uiPopup.setShow(false);
73        event.getRequestContext().addUIComponentToUpdateByAjax(uiParent);
74      }
75    }
76  }