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.unlock;
18  
19  import java.util.List;
20  
21  import org.exoplatform.commons.utils.LazyPageList;
22  import org.exoplatform.commons.utils.ListAccess;
23  import org.exoplatform.commons.utils.ListAccessImpl;
24  import org.exoplatform.ecm.webui.core.UIPagingGridDecorator;
25  import org.exoplatform.services.cms.lock.LockService;
26  import org.exoplatform.webui.config.annotation.ComponentConfig;
27  import org.exoplatform.webui.config.annotation.EventConfig;
28  import org.exoplatform.webui.event.Event;
29  import org.exoplatform.webui.event.EventListener;
30  
31  /**
32   * Created by The eXo Platform SARL
33   * Author : Dang Van Minh
34   *          minh.dang@exoplatform.com
35   * Dec 29, 2006
36   * 11:30:17 AM
37   */
38  @ComponentConfig(
39      template = "app:/groovy/webui/component/admin/unlock/UILockList.gtmpl",
40      events = {
41          @EventConfig(listeners = UILockList.DeleteLockActionListener.class)
42      }
43  )
44  public class UILockList extends UIPagingGridDecorator {
45    final static public String[] ACTIONS = {};
46  
47    final static public String   ST_EDIT = "EditUnLockForm";
48  
49    public UILockList() throws Exception {
50      getUIPageIterator().setId("LockListIterator");
51    }
52  
53    public String[] getActions() {
54      return ACTIONS;
55    }
56  
57    public void refresh(int currentPage) throws Exception {
58      ListAccess<String> groupsAndUsersForLockList = new ListAccessImpl<String>(String.class,
59                                                                                getAllGroupsOrUsersForLock());
60      LazyPageList<String> pageList = new LazyPageList<String>(groupsAndUsersForLockList,
61                                                               getUIPageIterator().getItemsPerPage());
62      getUIPageIterator().setPageList(pageList);
63      if (currentPage > getUIPageIterator().getAvailablePage())
64        getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage());
65      else
66        getUIPageIterator().setCurrentPage(currentPage);
67    }
68  
69    public List getGroupsOrUsersForLock() throws Exception {
70      return getUIPageIterator().getCurrentPageData();
71    }
72  
73    public List<String> getAllGroupsOrUsersForLock() throws Exception {
74      LockService lockService = getApplicationComponent(LockService.class);
75  
76      return lockService.getAllGroupsOrUsersForLock();
77    }
78  
79    static public class DeleteLockActionListener extends EventListener<UILockList> {
80      public void execute(Event<UILockList> event) throws Exception {
81        UIUnLockManager uiUnLockManager = event.getSource().getParent();
82        String settingLock = event.getRequestContext().getRequestParameter(OBJECTID);
83        LockService lockService = uiUnLockManager.getApplicationComponent(LockService.class);
84        lockService.removeGroupsOrUsersForLock(settingLock);
85        UILockList uiLockList = uiUnLockManager.getChild(UILockList.class);
86        uiLockList.refresh(uiLockList.getUIPageIterator().getCurrentPage());
87        event.getRequestContext().addUIComponentToUpdateByAjax(uiUnLockManager);
88      }
89    }
90  }