View Javadoc
1   /*
2    * Copyright (C) 2003-2008 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.wcm.webui.selector.content.one;
18  
19  import javax.jcr.Node;
20  
21  import org.exoplatform.ecm.utils.text.Text;
22  import org.exoplatform.ecm.webui.selector.UISelectable;
23  import org.exoplatform.services.wcm.core.NodeLocation;
24  import org.exoplatform.wcm.webui.Utils;
25  import org.exoplatform.wcm.webui.selector.content.UIContentBrowsePanel;
26  import org.exoplatform.web.application.ApplicationMessage;
27  import org.exoplatform.webui.config.annotation.ComponentConfig;
28  import org.exoplatform.webui.config.annotation.EventConfig;
29  import org.exoplatform.webui.core.lifecycle.Lifecycle;
30  import org.exoplatform.webui.event.Event;
31  import org.exoplatform.webui.event.EventListener;
32  
33  /**
34   * Created by The eXo Platform SAS.
35   *
36   * @author : Hoa.Pham hoa.pham@exoplatform.com Jun 23, 2008
37   */
38  @ComponentConfig(
39    lifecycle = Lifecycle.class,
40    template = "classpath:groovy/wcm/webui/selector/content/one/UIContentBrowsePanel.gtmpl",
41    events = {
42      @EventConfig(listeners = UIContentBrowsePanel.ChangeContentTypeActionListener.class),
43      @EventConfig(listeners = UIContentBrowsePanelOne.SelectActionListener.class)
44    }
45  )
46  public class UIContentBrowsePanelOne extends UIContentBrowsePanel{
47  
48    private String _initPath = "";
49    private String _initDrive = "";
50  
51    public void setInitPath(String initDrive, String initPath) {
52      this._initPath = initPath;
53      this._initDrive = initDrive;
54    }
55  
56    public String getInitDrive() { return this._initDrive; }
57    public String getInitPath() { return this._initPath; }
58  
59    public static class SelectActionListener extends EventListener<UIContentBrowsePanel> {
60      public void execute(Event<UIContentBrowsePanel> event) throws Exception {
61        UIContentBrowsePanel contentBrowsePanel = event.getSource();
62        String returnFieldName = contentBrowsePanel.getReturnFieldName();
63        String itemPath = event.getRequestContext().getRequestParameter(OBJECTID);
64        Node node = NodeLocation.getNodeByExpression(Text.escapeIllegalJcrChars(itemPath.substring(itemPath.indexOf(':') + 1)));
65        Node realNode = node;
66        if (node.isNodeType("exo:symlink")) {
67        String uuid = node.getProperty("exo:uuid").getString();
68        realNode = node.getSession().getNodeByUUID(uuid);
69        }
70        if(!realNode.isCheckedOut()){
71          Utils.createPopupMessage(contentBrowsePanel,
72                                   "UIContentBrowsePanelOne.msg.node-checkout",
73                                   null,
74                                   ApplicationMessage.WARNING);
75          return;
76        }
77        ((UISelectable) (contentBrowsePanel.getSourceComponent())).doSelect(returnFieldName,
78                                                                            event.getRequestContext()
79                                                                                 .getRequestParameter(OBJECTID));
80      }
81    }
82  }