View Javadoc
1   /*
2    * Copyright (C) 2003-2010 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.rightclick.action;
18  
19  import java.util.regex.Matcher;
20  
21  import javax.jcr.AccessDeniedException;
22  import javax.jcr.Node;
23  import javax.jcr.PathNotFoundException;
24  import javax.jcr.Session;
25  
26  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
27  import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
28  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIWorkingAreaActionListener;
29  import org.exoplatform.ecm.webui.component.explorer.rightclick.viewinfor.UIViewInfoManager;
30  import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
31  import org.exoplatform.web.application.ApplicationMessage;
32  import org.exoplatform.webui.config.annotation.ComponentConfig;
33  import org.exoplatform.webui.config.annotation.EventConfig;
34  import org.exoplatform.webui.core.UIApplication;
35  import org.exoplatform.webui.core.UIPopupContainer;
36  import org.exoplatform.webui.event.Event;
37  import org.exoplatform.webui.ext.manager.UIAbstractManager;
38  import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
39  
40  /**
41   * Created by The eXo Platform SAS
42   * Author : eXoPlatform
43   *          exo@exoplatform.com
44   * Oct 29, 2010
45   */
46  @ComponentConfig(events = { @EventConfig(listeners = ViewInfoActionComponent.ViewInfoActionListener.class) })
47  public class ViewInfoActionComponent extends UIAbstractManagerComponent{
48  
49    /**
50     * @author hai_lethanh
51     * class used to handle event raised on ViewFileInfoActionComponent
52     */
53    public static class ViewInfoActionListener extends UIWorkingAreaActionListener<ViewInfoActionComponent> {
54  
55      @Override
56      protected void processEvent(Event<ViewInfoActionComponent> event) throws Exception {
57        ViewInfoActionComponent uicomp = event.getSource();
58        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
59        UIPopupContainer objUIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
60  
61        String nodePath = event.getRequestContext().getRequestParameter(OBJECTID);
62        Node selectedNode = null;
63        if (nodePath != null && nodePath.length() != 0) {
64          //get workspace & selected node path
65          Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(nodePath);
66          String wsName = null;
67          if (matcher.find()) {
68            wsName = matcher.group(1);
69            nodePath = matcher.group(2);
70          } else {
71            throw new IllegalArgumentException("The ObjectId is invalid '" + nodePath + "'");
72          }
73  
74          //get session
75          Session session = uiExplorer.getSessionByWorkspace(wsName);
76  
77          //get UIApplication
78          UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class);
79  
80          //get selected node
81          try {
82            // Use the method getNodeByPath because it is link aware
83            selectedNode = uiExplorer.getNodeByPath(nodePath, session);
84          } catch (PathNotFoundException path) {
85            uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.path-not-found-exception", null,
86                ApplicationMessage.WARNING));
87            
88            return;
89          } catch (AccessDeniedException ace) {
90            uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.null-exception", null,
91                ApplicationMessage.WARNING));
92            
93            return;
94          } catch (Exception e) {
95            JCRExceptionManager.process(uiApp, e);
96            return;
97          }
98        }
99  
100       if (selectedNode == null)  selectedNode = uiExplorer.getCurrentNode();
101 
102       //show popup
103       UIViewInfoManager uiViewInfoManager = uiExplorer.createUIComponent(UIViewInfoManager.class, null, null);
104       uiViewInfoManager.setSelectedNode(selectedNode);
105       objUIPopupContainer.activate(uiViewInfoManager, 600, 0);
106       event.getRequestContext().addUIComponentToUpdateByAjax(objUIPopupContainer);
107     }
108   }
109 
110   @Override
111   public Class<? extends UIAbstractManager> getUIAbstractManagerClass() {
112     return null;
113   }
114 
115 }