View Javadoc
1   /*
2    * Copyright (C) 2003-2007 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.versions;
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.utils.Utils;
23  import org.exoplatform.web.application.ApplicationMessage;
24  import org.exoplatform.webui.config.annotation.ComponentConfig;
25  import org.exoplatform.webui.config.annotation.EventConfig;
26  import org.exoplatform.webui.core.UIApplication;
27  import org.exoplatform.webui.core.UIContainer;
28  import org.exoplatform.webui.core.UIPopupComponent;
29  import org.exoplatform.webui.core.UIPopupContainer;
30  import org.exoplatform.webui.event.Event;
31  import org.exoplatform.webui.event.EventListener;
32  
33  import javax.jcr.AccessDeniedException;
34  import javax.jcr.Node;
35  
36  /**
37   * Created by The eXo Platform SARL
38   * Author : trongtt
39   *          trongtt@gmail.com
40   * Oct 16, 2006
41   * 14:07:15
42   */
43  
44  @ComponentConfig(
45      type = UIActivateVersion.class,
46      template = "app:/groovy/webui/component/explorer/versions/UIActivateVersion.gtmpl",
47      events = {
48          @EventConfig(listeners = UIActivateVersion.EnableVersionActionListener.class),
49          @EventConfig(listeners = UIActivateVersion.CancelActionListener.class)
50      }
51  )
52  
53  public class UIActivateVersion extends UIContainer implements UIPopupComponent {
54  
55    public UIActivateVersion() throws Exception {}
56  
57    public void activate() {}
58    public void deActivate() {}
59  
60    static public class EnableVersionActionListener extends EventListener<UIActivateVersion> {
61      public void execute(Event<UIActivateVersion> event) throws Exception {
62        UIActivateVersion uiActivateVersion = event.getSource();
63        UIJCRExplorer uiExplorer = uiActivateVersion.getAncestorOfType(UIJCRExplorer.class) ;
64        Node currentNode = uiExplorer.getCurrentNode() ;
65        uiExplorer.addLockToken(currentNode);
66        try {
67          currentNode.addMixin(Utils.MIX_VERSIONABLE);
68          currentNode.save() ;
69          UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
70          UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
71          UIVersionInfo uiVersionInfo = uiDocumentWorkspace.getChild(UIVersionInfo.class);
72          uiVersionInfo.setCurrentNode(currentNode);
73          uiVersionInfo.setRootOwner(currentNode.getProperty("exo:lastModifier").getString());
74          uiVersionInfo.activate();
75          uiDocumentWorkspace.setRenderedChild(UIVersionInfo.class);
76          UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
77          UIPopupContainer.deActivate();
78          event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer);
79        }
80        catch (AccessDeniedException ex) {
81          UIApplication uiApp = uiExplorer.getAncestorOfType(UIApplication.class);
82          uiApp.addMessage(new ApplicationMessage("UIActivateVersion.msg.access-denied",null,ApplicationMessage.WARNING)) ;
83        }
84      }
85    }
86  
87    static  public class CancelActionListener extends EventListener<UIActivateVersion> {
88      public void execute(Event<UIActivateVersion> event) throws Exception {
89        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ;
90        uiExplorer.cancelAction() ;
91      }
92    }
93  }