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