1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
38
39
40
41
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 }