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.sidebar;
18  
19  import java.util.Set;
20  
21  import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer;
22  import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo;
23  import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace;
24  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
25  import org.exoplatform.ecm.webui.component.explorer.search.UISearchResult;
26  import org.exoplatform.webui.config.annotation.ComponentConfig;
27  import org.exoplatform.webui.config.annotation.EventConfig;
28  import org.exoplatform.webui.core.UIPageIterator;
29  import org.exoplatform.webui.event.Event;
30  import org.exoplatform.webui.event.EventListener;
31  
32  /**
33   * Created by The eXo Platform SAS
34   * Author : Hoa Pham
35   *          hoa.pham@exoplatform.com
36   * Sep 26, 2007
37   */
38  @ComponentConfig(
39      template =  "app:/groovy/webui/component/explorer/sidebar/UITreeNodePageIterator.gtmpl",
40      events = @EventConfig(listeners = UITreeNodePageIterator.ShowPageActionListener.class )
41  )
42  public class UITreeNodePageIterator extends UIPageIterator {
43    private String selectedPath_ ;
44  
45    public UITreeNodePageIterator() {
46    }
47  
48    public String getSelectedPath() { return selectedPath_ ; }
49    public void setSelectedPath(String path) { this.selectedPath_ = path ; }
50    static  public class ShowPageActionListener extends EventListener<UITreeNodePageIterator> {
51      public void execute(Event<UITreeNodePageIterator> event) throws Exception {
52        UITreeNodePageIterator uiPageIterator = event.getSource() ;
53        int page = Integer.parseInt(event.getRequestContext().getRequestParameter(OBJECTID)) ;
54        if(uiPageIterator.getAvailablePage() < page) page = uiPageIterator.getAvailablePage();	    
55        uiPageIterator.setCurrentPage(page) ;
56        if(uiPageIterator.getParent() == null) return ;
57        UIJCRExplorer uiExplorer = uiPageIterator.getAncestorOfType(UIJCRExplorer.class);
58        event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer);
59        UIDocumentWorkspace uiDocumentWorkspace = uiExplorer.findFirstComponentOfType(UIDocumentWorkspace.class) ;
60        UISearchResult uiSearchResult = uiDocumentWorkspace.getChild(UISearchResult.class) ;
61        if(uiSearchResult.isRendered()) return ;
62        UIDocumentContainer uiDocumentContainer = uiDocumentWorkspace.getChild(UIDocumentContainer.class);
63        UIDocumentInfo uiDocumentInfo = null ;
64        if(uiExplorer.isShowViewFile()) {
65          uiDocumentInfo = uiDocumentContainer.getChildById("UIDocumentWithTree") ;
66        } else {
67          Set<String> allItemByTypeFilterMap = uiExplorer.getAllItemByTypeFilterMap();
68          if (allItemByTypeFilterMap.size() > 0)
69            uiDocumentInfo = uiDocumentContainer.getChildById("UIDocumentWithTree");
70          else
71            uiDocumentInfo = uiDocumentContainer.getChildById("UIDocumentInfo");
72        }
73  
74        if (uiDocumentInfo == null) return;
75  
76        String currentPath = uiExplorer.getCurrentNode().getPath();
77        if(!currentPath.equalsIgnoreCase(uiPageIterator.getSelectedPath())) return ;
78  
79        UIPageIterator iterator = uiDocumentInfo.getContentPageIterator();
80        if(iterator.getAvailablePage() >= page) iterator.setCurrentPage(page);
81  
82        if (uiDocumentWorkspace.isRendered() && uiDocumentContainer.isRendered() && uiDocumentInfo.isRendered()) {
83          event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentInfo);
84        }
85      }
86    }
87  }