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.script;
18  
19  import org.exoplatform.webui.application.WebuiRequestContext;
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.config.annotation.EventConfig;
22  import org.exoplatform.webui.core.UIComponent;
23  import org.exoplatform.webui.core.UIPopupWindow;
24  import org.exoplatform.webui.event.Event;
25  import org.exoplatform.webui.event.EventListener;
26  import org.exoplatform.webui.ext.manager.UIAbstractManager;
27  
28  /**
29   * Created by The eXo Platform SARL
30   * Author : pham tuan
31   *          phamtuanchip@yahoo.de
32   * September 27, 2006
33   * 09:13:15 AM
34   */
35  @ComponentConfig(template = "app:/groovy/webui/component/admin/script/UIScriptManager.gtmpl",
36  events = { @EventConfig(listeners = UIScriptManager.SelectTabActionListener.class) })
37  
38  public class UIScriptManager extends UIAbstractManager {
39  
40    private String selectedTabId = "UIScriptContainer";
41  
42    final static public String POPUP_TEMPLATE_ID = "ScriptContainerPopup";
43    final static public String ACTION_TEMPLATE_ID = "UIActionScriptContainer";
44    final static public String INTERCEPTOR_TEMPLATE_ID = "UIInterceptorScriptContainer";
45    final static public String WIDGET_TEMPLATE_ID = "UIWidgetScriptContainer";
46  
47    final static public String ACTION_TEMPLATE_LIST_ID = "UIActionTemplateList";
48    final static public String INTERCEPTOR_TEMPLATE_LIST_ID  = "UIInterceptorTemplateList";
49    final static public String WIDGET_TEMPLATE_LIST_ID  = "UIWidgetTemplateList";
50  
51    public String getSelectedTabId()
52    {
53      return selectedTabId;
54    }
55  
56    public void setSelectedTab(String renderTabId)
57    {
58      selectedTabId = renderTabId;
59    }
60  
61    public void setSelectedTab(int index)
62    {
63      selectedTabId = getChild(index - 1).getId();
64    }
65  
66    public UIScriptManager() throws Exception {
67      UIScriptContainer uiActionTemp = addChild(UIScriptContainer.class, null, ACTION_TEMPLATE_ID) ;
68      uiActionTemp.getChild(UIScriptList.class).setTemplateFilter(UIScriptList.ACTION_SCRIPT_TYPE);
69  
70      UIScriptContainer uiInterceptorTemp = addChild(UIScriptContainer.class, null, INTERCEPTOR_TEMPLATE_ID) ;
71      uiInterceptorTemp.getChild(UIScriptList.class).setTemplateFilter(UIScriptList.INTERCEPTOR_SCRIPT_TYPE);
72  
73      UIScriptContainer uiWidgetTemp = addChild(UIScriptContainer.class, null, WIDGET_TEMPLATE_ID) ;
74      uiWidgetTemp.getChild(UIScriptList.class).setTemplateFilter(UIScriptList.WIDGET_SCRIPT_TYPE);
75  
76      UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null, POPUP_TEMPLATE_ID) ;    
77      setSelectedTab(ACTION_TEMPLATE_ID);
78    }
79  
80    public void initPopup(UIComponent uiComponent) throws Exception {
81      UIPopupWindow uiPopup = getChildById(POPUP_TEMPLATE_ID);
82      uiPopup.setRendered(true);
83      uiPopup.setShowMask(true);    
84      uiPopup.setWindowSize(600,270) ;
85      uiPopup.setUIComponent(uiComponent) ;
86      uiPopup.setShow(true) ;
87      uiPopup.setResizable(true) ;
88    }
89  
90    public void refresh()throws Exception {
91      UIScriptContainer actionContainer = ((UIScriptContainer)getChildById(ACTION_TEMPLATE_ID));
92      actionContainer.update();
93      actionContainer.getChild(UIScriptList.class).refresh(UIScriptList.ACTION_SCRIPT_TYPE, 1);
94  
95      UIScriptContainer interceptorContainer = ((UIScriptContainer)getChildById(INTERCEPTOR_TEMPLATE_ID));
96      interceptorContainer.update();
97      interceptorContainer.getChild(UIScriptList.class).refresh(UIScriptList.INTERCEPTOR_SCRIPT_TYPE, 1);
98  
99      UIScriptContainer widgetContainer = ((UIScriptContainer)getChildById(WIDGET_TEMPLATE_ID));
100     widgetContainer.update();
101     widgetContainer.getChild(UIScriptList.class).refresh(UIScriptList.WIDGET_SCRIPT_TYPE, 1);  	
102   }  
103 
104   static public class SelectTabActionListener extends EventListener<UIScriptManager>
105   {
106     public void execute(Event<UIScriptManager> event) throws Exception
107     {
108       WebuiRequestContext context = event.getRequestContext();
109       String renderTab = context.getRequestParameter(UIComponent.OBJECTID);
110       if (renderTab == null)
111         return;
112       event.getSource().setSelectedTab(renderTab);
113       WebuiRequestContext parentContext = (WebuiRequestContext)context.getParentAppRequestContext();
114       if (parentContext != null)
115       {
116         parentContext.setResponseComplete(true);
117       }
118       else
119       {
120         context.setResponseComplete(true);
121       }
122     }
123   } 
124 
125 }