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.IsNotEditingDocumentFilter;
29  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter;
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(
48      events = {
49          @EventConfig(listeners = PublicationApproveContentAction.PublicationApproveContentActionListener.class)
50      }
51  )
52  public class PublicationApproveContentAction extends UIComponent {
53  
54    private static final List<UIExtensionFilter> FILTERS = Arrays.asList(
55        new UIExtensionFilter[] {
56            new CanAddNodeFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(), new CanApproveFilter(), new IsNotEditingDocumentFilter()});
57  
58    @UIExtensionFilters
59    public List<UIExtensionFilter> getFilters() {
60      return FILTERS;
61    }
62  
63    public static class PublicationApproveContentActionListener
64                                                               extends
65                                                               UIActionBarActionListener<PublicationApproveContentAction> {
66  
67      @Override
68      protected void processEvent(Event<PublicationApproveContentAction> event) throws Exception {
69        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
70        PublicationService publicationService = WCMCoreUtils.getService(PublicationService.class);
71        Node node = uiExplorer.getCurrentNode();
72          HashMap<String,String> context = new HashMap<String,String>();
73  
74          publicationService.changeState(node, "approved", context);
75  
76        UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
77        event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer);
78        event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer);
79  
80      }
81    }
82  }