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.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   * Created by The eXo Platform SARL
38   * Author : pham tuan
39   *          phamtuanchip@yahoo.de
40   * Oct 20, 2006
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  //      String nodePath = node.getPath();
84  //      String wsName = node.getSession().getWorkspace().getName();
85        UIApplication app = uiClipboard.getAncestorOfType(UIApplication.class);
86        try {
87          //PasteManageComponent.processPaste(selectedClipboard, wsName + ":" + nodePath, event);
88          PasteManageComponent.processPaste(selectedClipboard, node, event, uiExplorer);
89          //uiWorkingArea.processPaste(selectedClipboard, wsName + ":" + nodePath, event);
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