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;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.exoplatform.ecm.webui.component.explorer.optionblocks.UIOptionBlockPanel;
23  import org.exoplatform.services.cms.templates.TemplateService;
24  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
25  import org.exoplatform.webui.config.annotation.ComponentConfig;
26  import org.exoplatform.webui.config.annotation.EventConfig;
27  import org.exoplatform.webui.core.UIComponent;
28  import org.exoplatform.webui.core.UIContainer;
29  import org.exoplatform.webui.event.Event;
30  import org.exoplatform.webui.event.EventListener;
31  import org.exoplatform.webui.ext.UIExtension;
32  import org.exoplatform.webui.ext.UIExtensionManager;
33  import javax.jcr.Node;
34  
35  /**
36   * Created by The eXo Platform SARL
37   * Author : Dang Van Minh
38   *          minh.dang@exoplatform.com
39   * Oct 15, 2007 10:05:43 AM
40   */
41  @ComponentConfig(
42                    template = "app:/groovy/webui/component/explorer/UIDocumentTabPane.gtmpl",
43        events = {
44                  @EventConfig(listeners = UIDocumentContainer.ChangeTabActionListener.class)
45                }
46  )
47  public class UIDocumentContainer extends UIContainer {
48  
49    private String OPTION_BLOCK_EXTENSION_TYPE = "org.exoplatform.ecm.dms.UIOptionBlockPanel";
50    private List<UIComponent> listExtenstion = new ArrayList<UIComponent>();
51    private boolean isDisplayOptionPanel = false;
52  
53    public UIDocumentContainer() throws Exception {
54      addChild(UIDocumentWithTree.class, null, null) ;
55      addChild(UIDocumentInfo.class, null, null) ;
56      this.initOptionBlockPanel();
57    }
58  
59    public boolean isShowViewFile() throws Exception {
60      return getAncestorOfType(UIJCRExplorer.class).isShowViewFile() ;
61    }
62  
63    public boolean isJcrEnable() {
64      return getAncestorOfType(UIJCRExplorer.class).getPreference().isJcrEnable() ;
65    }
66  
67    public boolean isDocumentNode() {
68      try {
69        Node currentNode = this.getAncestorOfType(UIJCRExplorer.class).getCurrentNode();
70        TemplateService templateService = WCMCoreUtils.getService(TemplateService.class);
71        List<String> documentNodeTypes = templateService.getAllDocumentNodeTypes();
72        if(documentNodeTypes.contains(currentNode.getPrimaryNodeType().getName())) return true;
73        return false;
74      } catch(Exception ex) {
75        return false;
76      }
77    }
78  
79    public static class ChangeTabActionListener  extends EventListener<UIDocumentContainer> {
80      public void execute(Event<UIDocumentContainer> event) throws Exception {
81        UIDocumentContainer uiDocumentContainer = event.getSource();
82        String selectedTabName = event.getRequestContext().getRequestParameter(OBJECTID);
83        UIDocumentWithTree uiDocTree = uiDocumentContainer.getChild(UIDocumentWithTree.class);
84        uiDocTree.setRendered(uiDocTree.getId().equals(selectedTabName));
85  
86        UIDocumentInfo uiDocInfo = uiDocumentContainer.getChildById(UIDocumentInfo.class.getSimpleName());
87        uiDocInfo.setRendered(uiDocInfo.getId().equals(selectedTabName));
88  
89        UIJCRExplorer uiExplorer = uiDocumentContainer.getAncestorOfType(UIJCRExplorer.class);
90        uiExplorer.setShowDocumentViewForFile(uiDocInfo.getId().equals(selectedTabName));
91        event.getRequestContext().addUIComponentToUpdateByAjax(uiDocumentContainer);
92        uiExplorer.updateAjax(event);
93      }
94    }
95    /*
96    *
97    * This method get Option Block Panel extenstion and add it into this
98    *
99    * */
100    public void addOptionBlockPanel() throws Exception {
101 
102      UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class);
103       List<UIExtension> extensions = manager.getUIExtensions(OPTION_BLOCK_EXTENSION_TYPE);
104 
105       for (UIExtension extension : extensions) {
106         UIComponent uicomp = manager.addUIExtension(extension, null, this);
107         uicomp.setRendered(false);
108         listExtenstion.add(uicomp);
109       }
110    }
111    /*
112     * This method checks and returns true if the Option Block Panel is configured to display, else it returns false
113     * */
114    public boolean isHasOptionBlockPanel() {
115      UIExtensionManager manager = getApplicationComponent(UIExtensionManager.class);
116       List<UIExtension> extensions = manager.getUIExtensions(OPTION_BLOCK_EXTENSION_TYPE);
117       if(extensions != null) {
118         return true;
119       }
120      return false;
121    }
122 
123    public void setDisplayOptionBlockPanel(boolean display) {
124      for(UIComponent uicomp : listExtenstion) {
125        uicomp.setRendered(display);
126      }
127      isDisplayOptionPanel = display;
128    }
129 
130    public boolean isDisplayOptionBlockPanel() {
131      return isDisplayOptionPanel;
132    }
133 
134    public void initOptionBlockPanel() throws Exception {
135      if(isHasOptionBlockPanel()) {
136        addOptionBlockPanel();
137        UIOptionBlockPanel optionBlockPanel = this.getChild(UIOptionBlockPanel.class);
138 
139        if(optionBlockPanel.isHasOptionBlockExtension()) {
140          optionBlockPanel.addOptionBlockExtension();
141          setDisplayOptionBlockPanel(true);
142        }
143      }
144    }
145 }