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.info;
19  
20  import org.exoplatform.ecm.permission.info.UIPermissionInputSet;
21  import org.exoplatform.webui.core.UIPopupComponent;
22  import org.exoplatform.webui.config.annotation.ComponentConfig;
23  import org.exoplatform.webui.config.annotation.EventConfig;
24  import org.exoplatform.webui.core.UIContainer;
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   * Dec 3, 2008
36   */
37  
38  @ComponentConfig(
39      lifecycle = UIContainerLifecycle.class,
40      events = {@EventConfig(listeners = UIUserContainer.AddUserActionListener.class)}
41  )
42  
43  public class UIUserContainer extends UIContainer implements UIPopupComponent  {
44  
45    public UIUserContainer() throws Exception {
46      UIUserSelector uiUserSelector = getChild(UIUserSelector.class);
47      if (uiUserSelector == null) {
48        uiUserSelector = addChild(UIUserSelector.class, null, null);
49      }
50      uiUserSelector.setMulti(false);
51      uiUserSelector.setShowSearchUser(true);
52      uiUserSelector.setShowSearch(true);
53    }
54  
55    public void activate() {
56  
57    }
58  
59    public void deActivate() {
60  
61    }
62  
63    static  public class AddUserActionListener extends EventListener<UIUserContainer> {
64      public void execute(Event<UIUserContainer> event) throws Exception {
65        UIUserContainer uiUserContainer = event.getSource();
66        UIUserSelector uiUserSelector = uiUserContainer.getChild(UIUserSelector.class);
67        UIPermissionManager uiParent = uiUserContainer.getAncestorOfType(UIPermissionManager.class);
68        UIPermissionForm uiPermissionForm = uiParent.getChild(UIPermissionForm.class);
69        uiPermissionForm.doSelect(UIPermissionInputSet.FIELD_USERORGROUP, uiUserSelector.getSelectedUsers());
70        UIPopupWindow uiPopup = uiParent.findComponentById("PopupUserSelector");
71        uiPopup.setShow(false);
72        event.getRequestContext().addUIComponentToUpdateByAjax(uiParent);
73      }
74    }
75  }