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.admin.metadata;
18  
19  import javax.jcr.nodetype.NodeType;
20  
21  import org.exoplatform.services.jcr.core.ExtendedPropertyType;
22  import org.exoplatform.webui.application.WebuiRequestContext;
23  import org.exoplatform.webui.config.annotation.ComponentConfig;
24  import org.exoplatform.webui.config.annotation.EventConfig;
25  import org.exoplatform.webui.core.UIComponent;
26  import org.exoplatform.webui.core.UIContainer;
27  import org.exoplatform.webui.event.Event;
28  import org.exoplatform.webui.event.EventListener;
29  
30  /**
31   * Created by The eXo Platform SARL
32   * Author : Dang Van Minh
33   *          minh.dang@exoplatform.com
34   * Sep 20, 2006
35   * 8:59:13 AM
36   */
37  @ComponentConfig(
38                   template = "app:/groovy/webui/component/admin/metadata/UIMetadataView.gtmpl",
39                   events = { 
40                       @EventConfig(listeners = UIMetadataView.CancelActionListener.class),
41                       @EventConfig(listeners = UIMetadataView.SelectTabActionListener.class) 
42                   })
43  public class UIMetadataView extends UIContainer{
44  
45    private NodeType metadataType_  ;
46  
47    private String selectedTabId = METADATA_VIEW;
48  
49    static public final String METADATA_VIEW = "Metadata";
50    static public final String ELEMENT_VIEW = "Element";
51  
52    public String getSelectedTabId()
53    {
54      return selectedTabId;
55    }
56  
57    public void setSelectedTab(String renderTabId)
58    {
59      selectedTabId = renderTabId;
60    }
61  
62    public void setSelectedTab(int index)
63    {
64      selectedTabId = ((UIComponent)getChild(index - 1)).getId();
65    }
66  
67    public UIMetadataView() throws Exception {
68    }
69  
70    public void  setMetadata(NodeType nodetype) { metadataType_ = nodetype ; }
71    public NodeType getMetadata() { return metadataType_ ; }
72  
73    public String resolveType(int type) { return ExtendedPropertyType.nameFromValue(type); }
74  
75    static public class CancelActionListener extends EventListener<UIMetadataView> {
76      public void execute(Event<UIMetadataView> event) throws Exception {
77        UIMetadataView uiView = event.getSource() ;
78        UIMetadataManager uiManager = uiView.getAncestorOfType(UIMetadataManager.class) ;
79        uiManager.removeChildById(UIMetadataManager.VIEW_METADATA_POPUP) ;
80        event.getRequestContext().addUIComponentToUpdateByAjax(uiManager) ;
81      }
82    }
83  
84    static public class SelectTabActionListener extends EventListener<UIMetadataView>
85    {
86      public void execute(Event<UIMetadataView> event) throws Exception
87      {
88        WebuiRequestContext context = event.getRequestContext();
89        String renderTab = context.getRequestParameter(UIComponent.OBJECTID);
90        if (renderTab == null)
91          return;
92        event.getSource().setSelectedTab(renderTab);
93        WebuiRequestContext parentContext = (WebuiRequestContext)context.getParentAppRequestContext();
94        if (parentContext != null)
95        {
96          parentContext.setResponseComplete(true);
97        }
98        else
99        {
100         context.setResponseComplete(true);
101       }
102     }
103   } 
104 }