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.UIDocumentContainer;
23  import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace;
24  import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea;
25  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
26  import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
27  import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter;
28  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter;
29  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter;
30  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter;
31  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter;
32  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotNtFileFilter;
33  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotTrashHomeNodeFilter;
34  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
35  import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentForm;
36  import org.exoplatform.ecm.webui.component.explorer.popup.actions.UIDocumentFormController;
37  import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult;
38  import org.exoplatform.web.application.ApplicationMessage;
39  import org.exoplatform.webui.application.WebuiRequestContext;
40  import org.exoplatform.webui.config.annotation.ComponentConfig;
41  import org.exoplatform.webui.config.annotation.EventConfig;
42  import org.exoplatform.webui.core.UIApplication;
43  import org.exoplatform.webui.core.UIComponent;
44  import org.exoplatform.webui.event.Event;
45  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
46  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
47  import org.exoplatform.webui.ext.manager.UIAbstractManager;
48  import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
49  
50  /**
51   * Created by The eXo Platform SAS
52   * Author : eXoPlatform
53   *          nicolas.filotto@exoplatform.com
54   * 6 mai 2009
55   */
56  @ComponentConfig(
57       events = {
58         @EventConfig(listeners = AddDocumentActionComponent.AddDocumentActionListener.class)
59       }
60   )
61  public class AddDocumentActionComponent extends UIAbstractManagerComponent {
62  
63    private static final List<UIExtensionFilter> FILTERS
64        = Arrays.asList(new UIExtensionFilter[]{new IsNotNtFileFilter(),
65                                                new CanAddNodeFilter(),
66                                                new IsNotLockedFilter(),
67                                                new IsCheckedOutFilter(),
68                                                new IsNotTrashHomeNodeFilter(),
69                                                new IsNotInTrashFilter(),
70                                                new IsNotEditingDocumentFilter()});
71  
72    @UIExtensionFilters
73    public static List<UIExtensionFilter> getFilters() {
74      return FILTERS;
75    }
76  
77    public static void addDocument(Event<? extends UIComponent> event,
78                            UIJCRExplorer uiExplorer,
79                            UIApplication uiApp,
80                            UIComponent uiComp,
81                            WebuiRequestContext context) throws Exception {
82      if (event != null)
83        context = event.getRequestContext();
84  
85      UIDocumentFormController uiController =
86        uiComp.createUIComponent(UIDocumentFormController.class, null, null);
87      uiController.setCurrentNode(uiExplorer.getCurrentNode());
88      uiController.setRepository(uiExplorer.getRepositoryName());
89      if(uiController.getListFileType().isEmpty()) {
90        uiApp.addMessage(new ApplicationMessage("UIActionBar.msg.empty-file-type", null,
91            ApplicationMessage.WARNING));
92        return;
93      }
94  //    uiExplorer.setPathBeforeEditing(uiExplorer.getCurrentPath());
95      uiController.init();
96  
97      UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
98      UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
99      if(!uiDocumentWorkspace.isRendered()) {
100       uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false);
101       uiWorkingArea.getChild(UIDocumentWorkspace.class).setRendered(true);
102     }
103     uiDocumentWorkspace.getChild(UIDocumentContainer.class).setRendered(false);
104     uiDocumentWorkspace.getChild(UISearchResult.class).setRendered(false);
105     UIDocumentFormController controller = uiDocumentWorkspace.removeChild(UIDocumentFormController.class);
106     if (controller != null) {
107       controller.getChild(UIDocumentForm.class).releaseLock();
108       controller.getChild(UIDocumentForm.class).clearRemovedNode();
109     }
110     uiDocumentWorkspace.addChild(uiController);
111     uiController.bindContentType();
112     uiController.setRendered(true);
113     context.addUIComponentToUpdateByAjax(uiWorkingArea);
114     if (event != null)
115       uiExplorer.updateAjax(event);
116   }
117 
118   public static class AddDocumentActionListener extends UIActionBarActionListener<AddDocumentActionComponent> {
119     public void processEvent(Event<AddDocumentActionComponent> event) throws Exception {
120       UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
121       UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class);
122       addDocument(event, uiExplorer, uiApp, event.getSource(), null);
123     }
124   }
125 
126   @Override
127   public Class<? extends UIAbstractManager> getUIAbstractManagerClass() {
128     return null;
129   }
130 }