1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.component.explorer.sidebar;
18
19 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
20 import org.exoplatform.ecm.webui.component.explorer.rightclick.manager.PasteManageComponent;
21 import org.exoplatform.services.cms.clipboard.ClipboardService;
22 import org.exoplatform.services.cms.clipboard.jcr.model.ClipboardCommand;
23 import org.exoplatform.services.security.ConversationState;
24 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
25 import org.exoplatform.web.application.ApplicationMessage;
26 import org.exoplatform.webui.config.annotation.ComponentConfig;
27 import org.exoplatform.webui.config.annotation.EventConfig;
28 import org.exoplatform.webui.core.UIApplication;
29 import org.exoplatform.webui.core.UIComponent;
30 import org.exoplatform.webui.event.Event;
31 import org.exoplatform.webui.event.EventListener;
32
33 import javax.jcr.Node;
34 import javax.jcr.PathNotFoundException;
35 import java.util.LinkedList;
36
37
38
39
40
41
42 @ComponentConfig(
43 template = "app:/groovy/webui/component/explorer/sidebar/UIClipboard.gtmpl",
44 events = {
45 @EventConfig(listeners = UIClipboard.PasteActionListener.class),
46 @EventConfig(listeners = UIClipboard.DeleteActionListener.class),
47 @EventConfig(listeners = UIClipboard.ClearAllActionListener.class)
48 }
49 )
50
51 public class UIClipboard extends UIComponent {
52 final static public String[] CLIPBOARD_BEAN_FIELD = {"path"} ;
53 final static public String[] CLIPBOARD_ACTIONS = {"Paste", "Delete"} ;
54
55 private LinkedList<ClipboardCommand> clipboard_ ;
56
57 public UIClipboard() throws Exception {
58 }
59
60 public String[] getBeanFields() {
61 return CLIPBOARD_BEAN_FIELD ;
62 }
63
64 public String[] getBeanActions() {
65 return CLIPBOARD_ACTIONS ;
66 }
67
68 public LinkedList<ClipboardCommand> getClipboardData() throws Exception {
69 String userId = ConversationState.getCurrent().getIdentity().getUserId();
70 ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class);
71 clipboard_ = new LinkedList<ClipboardCommand>(clipboardService.getClipboardList(userId, false));
72 return clipboard_;
73 }
74
75 static public class PasteActionListener extends EventListener<UIClipboard> {
76 public void execute(Event<UIClipboard> event) throws Exception {
77 UIClipboard uiClipboard = event.getSource() ;
78 UIJCRExplorer uiExplorer = uiClipboard.getAncestorOfType(UIJCRExplorer.class);
79 String id = event.getRequestContext().getRequestParameter(OBJECTID) ;
80 int index = Integer.parseInt(id) ;
81 ClipboardCommand selectedClipboard = uiClipboard.clipboard_.get(index-1);
82 Node node = uiExplorer.getCurrentNode() ;
83
84
85 UIApplication app = uiClipboard.getAncestorOfType(UIApplication.class);
86 try {
87
88 PasteManageComponent.processPaste(selectedClipboard, node, event, uiExplorer);
89
90 if (PasteManageComponent.isIsRefresh()) {
91 uiExplorer.updateAjax(event);
92 }
93
94 } catch(PathNotFoundException path) {
95 app.addMessage(new ApplicationMessage("PathNotFoundException.msg", null, ApplicationMessage.WARNING)) ;
96
97 return ;
98 } catch (Exception e) {
99 app.addMessage(new ApplicationMessage("UIClipboard.msg.unable-pasted", null, ApplicationMessage.WARNING)) ;
100
101 return ;
102 }
103 }
104 }
105
106 static public class DeleteActionListener extends EventListener<UIClipboard> {
107 public void execute(Event<UIClipboard> event) throws Exception{
108 UIClipboard uiClipboard = event.getSource() ;
109 String itemIndex = event.getRequestContext().getRequestParameter(OBJECTID) ;
110 ClipboardCommand command = uiClipboard.clipboard_.remove(Integer.parseInt(itemIndex)-1);
111 String userId = ConversationState.getCurrent().getIdentity().getUserId();
112 ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class);
113 clipboardService.removeClipboardCommand(userId, command);
114 }
115 }
116
117 static public class ClearAllActionListener extends EventListener<UIClipboard> {
118 public void execute(Event<UIClipboard> event) {
119 UIClipboard uiClipboard = event.getSource() ;
120 uiClipboard.clipboard_.clear() ;
121
122 String userId = ConversationState.getCurrent().getIdentity().getUserId();
123 ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class);
124 clipboardService.clearClipboardList(userId, false);
125 }
126 }
127 }
128