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.search;
18  
19  import org.exoplatform.services.log.ExoLogger;
20  import org.exoplatform.services.log.Log;
21  import org.exoplatform.webui.application.WebuiRequestContext;
22  import org.exoplatform.webui.config.annotation.ComponentConfig;
23  import org.exoplatform.webui.config.annotation.EventConfig;
24  import org.exoplatform.webui.core.UIComponent;
25  import org.exoplatform.webui.core.UIPageIterator;
26  import org.exoplatform.webui.core.UIPopupComponent;
27  import org.exoplatform.webui.core.UITabPane;
28  import org.exoplatform.webui.event.Event;
29  import org.exoplatform.webui.event.EventListener;
30  
31  /**
32   * Created by The eXo Platform SARL
33   * Author : le bien thuy
34   *          lebienthuyt@gmail.com
35   * Oct 2, 2006
36   * 10:08:51 AM
37   * Editor: pham tuan Oct 27, 2006
38   */
39  
40  @ComponentConfig(template = "system:/groovy/webui/core/UITabPane_New.gtmpl", 
41                   events = { @EventConfig(listeners = UIECMSearch.SelectTabActionListener.class) })
42  public class UIECMSearch extends UITabPane implements UIPopupComponent {
43  
44    private static final Log LOG = ExoLogger.getLogger(UIECMSearch.class.getName());
45  
46    static public String ADVANCED_RESULT = "AdvancedSearchResult" ;
47  
48    public UIECMSearch() throws Exception {
49      addChild(UIContentNameSearch.class,null,null);
50      setSelectedTab("UIContentNameSearch");
51      addChild(UISearchContainer.class, null, null) ;
52      addChild(UIJCRAdvancedSearch.class, null, null);
53      addChild(UISavedQuery.class, null, null);
54      UISearchResult uiSearchResult = addChild(UISearchResult.class, null, ADVANCED_RESULT);
55      UIPageIterator uiPageIterator = uiSearchResult.getChild(UIPageIterator.class) ;
56      uiPageIterator.setId("AdvanceSearchIterator") ;
57    }
58  
59    public void activate() {
60      try {
61        UIJCRAdvancedSearch advanceSearch = getChild(UIJCRAdvancedSearch.class);
62        advanceSearch.update(null);
63        UISavedQuery uiQuery = getChild(UISavedQuery.class);
64        uiQuery.updateGrid(1);
65      } catch (Exception e) {
66        if (LOG.isErrorEnabled()) {
67          LOG.error("Unexpected error!", e.getMessage());
68        }
69      }
70    }
71  
72    public void deActivate() {
73    }
74    
75    static public class SelectTabActionListener extends EventListener<UIECMSearch>
76    {
77       public void execute(Event<UIECMSearch> event) throws Exception
78       {
79          WebuiRequestContext context = event.getRequestContext();
80          String renderTab = context.getRequestParameter(UIComponent.OBJECTID);
81          if (renderTab == null)
82             return;
83          event.getSource().setSelectedTab(renderTab);
84          context.setResponseComplete(true);
85          context.addUIComponentToUpdateByAjax(event.getSource().getParent());
86       }
87    }
88  }