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.symlink;
18  
19  import javax.jcr.Item;
20  import javax.jcr.Node;
21  
22  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
23  import org.exoplatform.services.log.ExoLogger;
24  import org.exoplatform.services.log.Log;
25  import org.exoplatform.services.wcm.core.NodeLocation;
26  import org.exoplatform.webui.config.annotation.ComponentConfig;
27  import org.exoplatform.webui.config.annotation.EventConfig;
28  import org.exoplatform.webui.core.UIContainer;
29  import org.exoplatform.webui.event.Event;
30  import org.exoplatform.webui.event.EventListener;
31  
32  /**
33   * Created by The eXo Platform SARL
34   * Author : Dang Van Minh
35   *          minh.dang@exoplatform.com
36   * May 25, 2007 8:59:34 AM
37   */
38  @ComponentConfig(
39      template = "app:/groovy/webui/component/explorer/UITabPaneWithAction.gtmpl",
40      events = {
41          @EventConfig(listeners = UISymLinkContainer.CloseActionListener.class)
42      }
43  )
44  public class UISymLinkContainer extends UIContainer {
45  
46    private static final Log LOG = ExoLogger.getLogger(UISymLinkContainer.class.getName());
47    
48    private NodeLocation uploadedNode_ ;
49  
50    public UISymLinkContainer() throws Exception {
51    }
52  
53    public String[] getActions() {return new String[] {"AddMetadata","Close"} ;}
54  
55    public Node getEditNode(String nodeType) throws Exception {
56      Node uploadedNode = getUploadedNode();
57      try {
58        Item primaryItem = uploadedNode.getPrimaryItem() ;
59        if(primaryItem == null || !primaryItem.isNode()) return uploadedNode;
60        if(primaryItem != null && primaryItem.isNode()) {
61          Node primaryNode = (Node) primaryItem ;
62          if(primaryNode.isNodeType(nodeType)) return primaryNode ;
63        }
64      } catch(Exception e) {
65        if (LOG.isWarnEnabled()) {
66          LOG.warn(e.getMessage());
67        }
68      }
69      return uploadedNode;
70    }
71  
72    public void setUploadedNode(Node node) throws Exception { 
73      uploadedNode_ = NodeLocation.getNodeLocationByNode(node); 
74    }
75    public Node getUploadedNode() { 
76      return NodeLocation.getNodeByLocation(uploadedNode_); 
77    }
78  
79    static public class CloseActionListener extends EventListener<UISymLinkContainer> {
80      public void execute(Event<UISymLinkContainer> event) throws Exception {
81        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
82        uiExplorer.cancelAction() ;
83      }
84    }
85  }