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.upload;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import javax.jcr.Item;
23  import javax.jcr.Node;
24  
25  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
26  import org.exoplatform.services.log.ExoLogger;
27  import org.exoplatform.services.log.Log;
28  import org.exoplatform.services.wcm.core.NodeLocation;
29  import org.exoplatform.webui.config.annotation.ComponentConfig;
30  import org.exoplatform.webui.config.annotation.EventConfig;
31  import org.exoplatform.webui.core.UIContainer;
32  import org.exoplatform.webui.event.Event;
33  import org.exoplatform.webui.event.EventListener;
34  
35  /**
36   * Created by The eXo Platform SARL
37   * Author : Dang Van Minh
38   *          minh.dang@exoplatform.com
39   * May 25, 2007 8:59:34 AM
40   */
41  @ComponentConfig(
42      template = "app:/groovy/webui/component/explorer/UITabPaneWithAction.gtmpl",
43      events = {
44          @EventConfig(listeners = UIUploadContainer.CloseActionListener.class),
45          @EventConfig(listeners = UIUploadContainer.AddMetadataActionListener.class)
46      }
47  )
48  public class UIUploadContainer extends UIContainer {
49  
50    private static final Log LOG = ExoLogger.getLogger(UIUploadContainer.class.getName());
51    
52    private NodeLocation uploadedNode_;
53    private List<NodeLocation> listUploadedNode_ = new ArrayList<NodeLocation>();
54    private String[] arrayActions = new String[] {"Close"};
55  
56    public UIUploadContainer() throws Exception {
57      addChild(UIUploadContent.class, null, null) ;
58    }
59  
60    public void setActions(String[] arrValueActions) {
61      arrayActions = arrValueActions ;
62    }
63  
64    public String[] getActions() {
65      return arrayActions;
66    }
67  
68    public Node getEditNode(String nodeType) throws Exception {
69      Node uploadNode = getUploadedNode();
70      try {
71        Item primaryItem = uploadNode.getPrimaryItem() ;
72        if (primaryItem == null || !primaryItem.isNode()) return uploadNode;
73        if (primaryItem != null && primaryItem.isNode()) {
74          Node primaryNode = (Node) primaryItem ;
75          if (primaryNode.isNodeType(nodeType)) return primaryNode ;
76        }
77      } catch(Exception e) {
78        if (LOG.isWarnEnabled()) {
79          LOG.warn(e.getMessage());
80        }
81      }
82      return uploadNode;
83    }
84  
85    public void setUploadedNode(Node node) throws Exception { 
86      uploadedNode_ = NodeLocation.getNodeLocationByNode(node); 
87    }
88    
89    public Node getUploadedNode() { 
90      return NodeLocation.getNodeByLocation(uploadedNode_); 
91    }
92  
93    public void setListUploadedNode(List<Node> listNode) throws Exception {
94      listUploadedNode_ = NodeLocation.getLocationsByNodeList(listNode);
95    }
96  
97    public List<Node> getListUploadedNode() {
98      return NodeLocation.getNodeListByLocationList(listUploadedNode_);
99    }
100 
101   static public class CloseActionListener extends EventListener<UIUploadContainer> {
102     public void execute(Event<UIUploadContainer> event) throws Exception {
103       UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class) ;
104       uiExplorer.cancelAction() ;
105     }
106   }
107 
108   static public class AddMetadataActionListener extends EventListener<UIUploadContainer> {
109     public void execute(Event<UIUploadContainer> event) throws Exception {
110       UIUploadManager uiUploadManager = event.getSource().getParent() ;
111       uiUploadManager.initMetadataPopup() ;
112       event.getRequestContext().addUIComponentToUpdateByAjax(uiUploadManager) ;
113     }
114   }
115 }