1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
37
38
39
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
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
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 }