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  package org.exoplatform.wcm.webui.selector.account;
18  
19  import org.exoplatform.ecm.webui.selector.UISelectable;
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.config.annotation.EventConfig;
22  import org.exoplatform.webui.core.UIContainer;
23  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
24  import org.exoplatform.webui.event.Event;
25  import org.exoplatform.webui.event.EventListener;
26  import org.exoplatform.webui.organization.account.UIUserSelector;
27  
28  /**
29   * Created by The eXo Platform SAS
30   * Author : Phan Le Thanh Chuong
31   *          chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
32   * Nov 1, 2009
33   */
34  @ComponentConfig (
35    lifecycle = UIContainerLifecycle.class,
36    events = {
37      @EventConfig(listeners = UIUserContainer.AddUserActionListener.class)
38    }
39  )
40  public class UIUserContainer extends UIContainer {
41  
42    private UISelectable selectable;
43  
44    private String sourceComponent;
45  
46    public UISelectable getSelectable() {
47      return selectable;
48    }
49  
50    public void setSelectable(UISelectable selectable) {
51      this.selectable = selectable;
52    }
53  
54    public String getSourceComponent() {
55      return sourceComponent;
56    }
57  
58    public void setSourceComponent(String sourceComponent) {
59      this.sourceComponent = sourceComponent;
60    }
61  
62    public UIUserContainer() throws Exception {
63      UIUserSelector userSelector = addChild(UIUserSelector.class, null, null);
64      userSelector.setMulti(false);
65      userSelector.setShowSearchUser(true);
66      userSelector.setShowSearch(true);
67    }
68  
69   public static class AddUserActionListener extends EventListener<UIUserContainer> {
70     public void execute(Event<UIUserContainer> event) throws Exception {
71       UIUserContainer userContainer = event.getSource();
72       UIUserSelector userSelector = userContainer.getChild(UIUserSelector.class);
73       userContainer.getSelectable().doSelect(userContainer.getSourceComponent(), userSelector.getSelectedUsers());
74     }
75   }
76  }