View Javadoc
1   /*
2    * Copyright (C) 2003-2009 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.control.action;
18  
19  import javax.jcr.Node;
20  
21  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
22  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
23  import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIPropertiesManager;
24  import org.exoplatform.ecm.webui.component.explorer.popup.admin.UIPropertyForm;
25  import org.exoplatform.ecm.webui.utils.PermissionUtil;
26  import org.exoplatform.ecm.webui.utils.Utils;
27  import org.exoplatform.services.log.ExoLogger;
28  import org.exoplatform.services.log.Log;
29  import org.exoplatform.webui.config.annotation.ComponentConfig;
30  import org.exoplatform.webui.config.annotation.EventConfig;
31  import org.exoplatform.webui.core.UIComponent;
32  import org.exoplatform.webui.core.UIPopupContainer;
33  import org.exoplatform.webui.event.Event;
34  
35  /**
36   * Created by The eXo Platform SAS
37   * Author : eXoPlatform
38   *          nicolas.filotto@exoplatform.com
39   * 6 mai 2009
40   */
41  @ComponentConfig(
42       events = {
43         @EventConfig(listeners = ViewPropertiesActionComponent.ViewPropertiesActionListener.class)
44       }
45   )
46  public class ViewPropertiesActionComponent extends UIComponent {
47  
48    private static final Log         LOG            = ExoLogger.getLogger(ViewPropertiesActionComponent.class.getName());
49    
50    public static class ViewPropertiesActionListener extends UIActionBarActionListener<ViewPropertiesActionComponent> {
51      public void processEvent(Event<ViewPropertiesActionComponent> event) throws Exception {
52        UIJCRExplorer uiJCRExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
53        Node node = uiJCRExplorer.getCurrentNode();
54        UIPropertiesManager uiPropertiesManager =
55          uiJCRExplorer.createUIComponent(UIPropertiesManager.class, null, null);      
56        try {
57          if (node.isNodeType(Utils.NT_UNSTRUCTURED)) {
58            UIPropertyForm uiForm = uiPropertiesManager.getChild(UIPropertyForm.class);
59            uiForm.init(node);
60            uiForm.getUIFormSelectBox(UIPropertyForm.FIELD_NAMESPACE)
61                  .setOptions(uiForm.getNamespaces());
62          } else {
63            if (org.exoplatform.services.cms.impl.Utils.getProperties(node) != null
64                && org.exoplatform.services.cms.impl.Utils.getProperties(node).size() > 0) {
65              UIPropertyForm uiForm = uiPropertiesManager.getChild(UIPropertyForm.class);
66              uiForm.init(node);
67              uiForm.getUIFormSelectBox(UIPropertyForm.PROPERTY_SELECT)
68                    .setOptions(uiForm.renderProperties(node));
69            }
70          }
71          if (uiJCRExplorer.nodeIsLocked(node)) {
72            uiPropertiesManager.setLockForm(true);
73          } else {
74            uiPropertiesManager.setLockForm(!PermissionUtil.canSetProperty(node));
75          }
76        } catch (NullPointerException npe) {
77          if (LOG.isWarnEnabled()) {
78            LOG.warn(npe.getMessage());
79          }
80        } 
81        
82        UIPopupContainer UIPopupContainer = uiJCRExplorer.getChild(UIPopupContainer.class);
83        UIPopupContainer.activate(uiPropertiesManager, 700, 0);
84        event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer);
85      }
86    }
87  }