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 org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace;
20  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
21  import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
22  import org.exoplatform.ecm.webui.component.explorer.control.filter.*;
23  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
24  import org.exoplatform.ecm.webui.component.explorer.versions.UIActivateVersion;
25  import org.exoplatform.ecm.webui.component.explorer.versions.UIVersionInfo;
26  import org.exoplatform.ecm.webui.utils.Utils;
27  import org.exoplatform.webui.config.annotation.ComponentConfig;
28  import org.exoplatform.webui.config.annotation.EventConfig;
29  import org.exoplatform.webui.core.UIComponent;
30  import org.exoplatform.webui.core.UIPopupContainer;
31  import org.exoplatform.webui.event.Event;
32  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
33  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
34  
35  import javax.jcr.Node;
36  import java.util.Arrays;
37  import java.util.List;
38  
39  /**
40   * Created by The eXo Platform SAS
41   * Author : eXoPlatform
42   *          nicolas.filotto@exoplatform.com
43   * 6 mai 2009
44   */
45  @ComponentConfig(
46       events = {
47         @EventConfig(listeners = ManageVersionsActionComponent.ManageVersionsActionListener.class)
48       }
49   )
50  public class ManageVersionsActionComponent extends UIComponent {
51  
52    private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {
53        new IsNotRootNodeFilter("UIActionBar.msg.cannot-enable-version-rootnode"),
54        new CanSetPropertyFilter(), new IsNotLockedFilter(), new CanEnableVersionFilter(),
55        new IsNotEditingDocumentFilter(), new IsNotFolderFilter(), new IsNotIgnoreVersionNodeFilter()
56        }
57    );
58  
59    @UIExtensionFilters
60    public List<UIExtensionFilter> getFilters() {
61      return FILTERS;
62    }
63  
64    public static class ManageVersionsActionListener extends UIActionBarActionListener<ManageVersionsActionComponent> {
65      public void processEvent(Event<ManageVersionsActionComponent> event) throws Exception {
66        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
67        UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
68        Node currentNode = uiExplorer.getCurrentNode();
69        uiExplorer.setIsHidePopup(false);
70        if (currentNode.canAddMixin(Utils.MIX_VERSIONABLE)) {
71          UIPopupContainer.activate(UIActivateVersion.class, 400);
72          event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer);
73        } else if (currentNode.isNodeType(Utils.MIX_VERSIONABLE)) {
74          UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
75          UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
76          UIVersionInfo uiVersionInfo = uiDocumentWorkspace.getChild(UIVersionInfo.class);
77          uiVersionInfo.setCurrentNode(currentNode);
78          uiVersionInfo.setRootOwner(currentNode.getProperty("exo:lastModifier").getString());
79          uiVersionInfo.activate();
80          uiDocumentWorkspace.setRenderedChild(UIVersionInfo.class);
81          event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentWorkspace);
82        }
83      }
84    }
85  }