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.ecm.webui.component.explorer.control.action;
18  
19  import java.util.Arrays;
20  import java.util.List;
21  
22  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
23  import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter;
24  import org.exoplatform.ecm.webui.component.explorer.control.filter.HasAllowedFolderTypeFilter;
25  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter;
26  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotCategoryFilter;
27  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter;
28  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter;
29  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter;
30  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotNtFileFilter;
31  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotTrashHomeNodeFilter;
32  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
33  import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIFolderForm;
34  import org.exoplatform.webui.config.annotation.ComponentConfig;
35  import org.exoplatform.webui.config.annotation.EventConfig;
36  import org.exoplatform.webui.core.UIComponent;
37  import org.exoplatform.webui.core.UIPopupContainer;
38  import org.exoplatform.webui.event.Event;
39  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
40  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
41  import org.exoplatform.webui.ext.manager.UIAbstractManager;
42  import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
43  
44  /**
45   * Created by The eXo Platform SAS
46   * Author : eXoPlatform
47   *          nicolas.filotto@exoplatform.com
48   * 5 mai 2009
49   */
50  @ComponentConfig(
51       events = {
52         @EventConfig(listeners = AddFolderActionComponent.AddFolderActionListener.class)
53       }
54   )
55  public class AddFolderActionComponent extends UIAbstractManagerComponent {
56  
57    private static final List<UIExtensionFilter> FILTERS =
58        Arrays.asList(new UIExtensionFilter[]{new IsNotNtFileFilter(),
59                                              new CanAddNodeFilter(),
60                                              new IsNotCategoryFilter(),
61                                              new IsNotLockedFilter(),
62                                              new IsCheckedOutFilter(),
63                                              new IsNotTrashHomeNodeFilter(),
64                                              new IsNotInTrashFilter(),
65                                              new IsNotEditingDocumentFilter(),
66                                              new HasAllowedFolderTypeFilter()});
67  
68    @UIExtensionFilters
69    public List<UIExtensionFilter> getFilters() {
70      return FILTERS;
71    }
72  
73    public static void addFolder(Event<? extends UIComponent> event, UIJCRExplorer uiExplorer) throws Exception {
74      UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
75      UIFolderForm folderForm = uiExplorer.createUIComponent(UIFolderForm.class, null, null);
76      UIPopupContainer.activate(folderForm, 420, 220, false);
77      event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer);
78    }
79  
80    public static class AddFolderActionListener extends UIActionBarActionListener<AddFolderActionComponent> {
81      public void processEvent(Event<AddFolderActionComponent> event) throws Exception {
82        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
83        addFolder(event, uiExplorer);
84      }
85    }
86  
87    @Override
88    public Class<? extends UIAbstractManager> getUIAbstractManagerClass() {
89      return null;
90    }
91  }