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.extensions.ui;
18  
19  import java.util.Arrays;
20  import java.util.HashMap;
21  import java.util.List;
22  
23  import javax.jcr.Node;
24  
25  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
26  import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter;
27  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter;
28  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter;
29  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter;
30  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
31  import org.exoplatform.services.ecm.publication.PublicationService;
32  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
33  import org.exoplatform.webui.config.annotation.ComponentConfig;
34  import org.exoplatform.webui.config.annotation.EventConfig;
35  import org.exoplatform.webui.core.UIComponent;
36  import org.exoplatform.webui.core.UIPopupContainer;
37  import org.exoplatform.webui.event.Event;
38  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
39  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
40  
41  /**
42   * Created by The eXo Platform SAS
43   * Author : eXoPlatform
44   *          benjamin.paillereau@exoplatform.com
45   * 27 june 2010
46   */
47  @ComponentConfig(events = {
48      @EventConfig(listeners = PublicationRequestApprovalAction.PublicationRequestApprovalActionListener.class) })
49  public class PublicationRequestApprovalAction extends UIComponent {
50  
51    private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {
52        new CanAddNodeFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(),
53        new CanValidateFilter(), new IsNotEditingDocumentFilter()});
54  
55    @UIExtensionFilters
56    public List<UIExtensionFilter> getFilters() {
57      return FILTERS;
58    }
59  
60    public static class PublicationRequestApprovalActionListener
61                                                                extends
62                                                                UIActionBarActionListener<PublicationRequestApprovalAction> {
63  
64      @Override
65      protected void processEvent(Event<PublicationRequestApprovalAction> event) throws Exception {
66        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
67        PublicationService publicationService = WCMCoreUtils.getService(PublicationService.class);
68        Node node = uiExplorer.getCurrentNode();
69        HashMap<String, String> context = new HashMap<String, String>();
70  
71        publicationService.changeState(node, "pending", context);
72  
73        UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
74        event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer);
75        event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer);
76  
77      }
78    }
79  }