KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > trees > WebsiteTreeConfiguration


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.admininterface.trees;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.beans.config.Server;
17 import info.magnolia.cms.beans.config.Subscriber;
18 import info.magnolia.cms.beans.config.Template;
19 import info.magnolia.cms.beans.config.TemplateManager;
20 import info.magnolia.cms.core.ItemType;
21 import info.magnolia.cms.core.MetaData;
22 import info.magnolia.cms.gui.control.ContextMenu;
23 import info.magnolia.cms.gui.control.ContextMenuItem;
24 import info.magnolia.cms.gui.control.FunctionBarItem;
25 import info.magnolia.cms.gui.control.Select;
26 import info.magnolia.cms.gui.control.Tree;
27 import info.magnolia.cms.gui.control.TreeColumn;
28 import info.magnolia.cms.i18n.Messages;
29 import info.magnolia.cms.i18n.MessagesManager;
30 import info.magnolia.cms.i18n.MessagesUtil;
31 import info.magnolia.cms.i18n.TemplateMessagesUtil;
32 import info.magnolia.context.MgnlContext;
33 import info.magnolia.module.admininterface.AdminTreeConfiguration;
34
35 import java.util.Iterator JavaDoc;
36
37 import javax.servlet.http.HttpServletRequest JavaDoc;
38
39 import org.apache.commons.lang.StringUtils;
40
41
42 /**
43  * @author Philipp Bracher
44  * @version $Revision: 6341 $ ($Author: philipp $)
45  */

46 public class WebsiteTreeConfiguration implements AdminTreeConfiguration {
47
48     /**
49      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareTree(info.magnolia.cms.gui.control.Tree,
50      * boolean, javax.servlet.http.HttpServletRequest)
51      */

52     public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
53         Messages msgs = MessagesManager.getMessages();
54
55         tree.setIconOndblclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); //$NON-NLS-1$ //$NON-NLS-2$
56

57         tree.addItemType(ItemType.CONTENT);
58
59         TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request);
60         column0.setIsLabel(true);
61         column0.setTitle(msgs.get("tree.web.page"));
62         column0.setWidth(3);
63         column0.setHtmlEdit();
64
65         TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request);
66         columnIcons.setCssClass(StringUtils.EMPTY);
67         columnIcons.setWidth(1);
68         columnIcons.setIsIcons(true);
69         columnIcons.setIconsActivation(true);
70         columnIcons.setIconsPermission(true);
71
72         TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request);
73         column1.setName("title"); //$NON-NLS-1$
74
column1.setTitle(msgs.get("tree.web.title")); //$NON-NLS-1$
75
column1.setWidth(2);
76         column1.setHtmlEdit();
77
78         TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request);
79         column2.setName(MetaData.TEMPLATE);
80         column2.setIsMeta(true);
81         column2.setWidth(2);
82         column2.setTitle(msgs.get("tree.web.template")); //$NON-NLS-1$
83
// must render this column specially
84
column2.setHtmlRenderer(new TemplateTreeColumnHtmlRenderer());
85
86         Select templateSelect = new Select();
87         templateSelect.setName(tree.getJavascriptTree() + TreeColumn.EDIT_NAMEADDITION);
88         templateSelect.setSaveInfo(false);
89         templateSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT);
90
91         // we must pass the displayValue to this function
92
// templateSelect.setEvent("onblur", tree.getJavascriptTree() + TreeColumn.EDIT_JSSAVE);
93
// templateSelect.setEvent("onchange", tree.getJavascriptTree() + TreeColumn.EDIT_JSSAVE);
94
templateSelect.setEvent("onblur", tree.getJavascriptTree() //$NON-NLS-1$
95
+ ".saveNodeData(this.value,this.options[this.selectedIndex].text)"); //$NON-NLS-1$
96
templateSelect.setEvent("onchange", tree.getJavascriptTree() //$NON-NLS-1$
97
+ ".saveNodeData(this.value,this.options[this.selectedIndex].text)"); //$NON-NLS-1$
98

99         Iterator JavaDoc templates = TemplateManager.getInstance().getAvailableTemplates(
100             MgnlContext.getAccessManager(ContentRepository.CONFIG));
101         Messages templateMsgs = TemplateMessagesUtil.getMessages();
102         while (templates.hasNext()) {
103             Template template = (Template) templates.next();
104             String JavaDoc title = template.getTitle();
105             title = templateMsgs.getWithDefault(title, title);
106             title = MessagesUtil.javaScriptString(title);
107             templateSelect.setOptions(title, template.getName());
108         }
109         column2.setHtmlEdit(templateSelect.getHtml());
110
111         // todo: key/value -> column2.addKeyValue("sampleBasic","Samples: Basic Template");
112
// todo: preselection (set on createPage)
113
TreeColumn column3 = new TreeColumn(tree.getJavascriptTree(), request);
114         column3.setName(MetaData.LAST_MODIFIED);
115         // column3.setName(MetaData.SEQUENCE_POS);
116
column3.setIsMeta(true);
117         column3.setDateFormat("yy-MM-dd, HH:mm"); //$NON-NLS-1$
118
column3.setWidth(2);
119         column3.setTitle(msgs.get("tree.web.date")); //$NON-NLS-1$
120

121         tree.addColumn(column0);
122
123         if (!browseMode) {
124             tree.addColumn(column1);
125             if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) {
126                 tree.addColumn(columnIcons);
127             }
128             tree.addColumn(column2);
129             tree.addColumn(column3);
130         }
131
132     }
133
134     /**
135      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
136      * boolean, javax.servlet.http.HttpServletRequest)
137      */

138     public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
139         Messages msgs = MessagesManager.getMessages();
140         ContextMenuItem menuOpen = new ContextMenuItem("open");
141         menuOpen.setLabel(msgs.get("tree.web.menu.open")); //$NON-NLS-1$
142
menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth.gif"); //$NON-NLS-1$
143
menuOpen.setOnclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); //$NON-NLS-1$ //$NON-NLS-2$
144
menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
145
+ tree.getJavascriptTree()
146             + ")"); //$NON-NLS-1$
147

148         ContextMenuItem menuNewPage = new ContextMenuItem("new");
149         menuNewPage.setLabel(msgs.get("tree.web.menu.new")); //$NON-NLS-1$
150
menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth_add.gif"); //$NON-NLS-1$
151

152         menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); //$NON-NLS-1$ //$NON-NLS-2$
153
menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
154
+ tree.getJavascriptTree()
155             + ")"); //$NON-NLS-1$
156

157         ContextMenuItem menuDelete = new ContextMenuItem("delete");
158         menuDelete.setLabel(msgs.get("tree.web.menu.delete")); //$NON-NLS-1$
159
menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); //$NON-NLS-1$
160
menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
161
menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
162
+ tree.getJavascriptTree()
163             + ")"); //$NON-NLS-1$
164
menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
165
+ tree.getJavascriptTree()
166             + ")"); //$NON-NLS-1$
167

168         ContextMenuItem menuMove = new ContextMenuItem("move");
169         menuMove.setLabel(msgs.get("tree.web.menu.move")); //$NON-NLS-1$
170
menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
171
menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
172
menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
173
+ tree.getJavascriptTree()
174             + ")"); //$NON-NLS-1$
175
menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
176
+ tree.getJavascriptTree()
177             + ")"); //$NON-NLS-1$
178

179         ContextMenuItem menuCopy = new ContextMenuItem("copy");
180         menuCopy.setLabel(msgs.get("tree.web.menu.copy")); //$NON-NLS-1$
181
menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
182
menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
183
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
184
+ tree.getJavascriptTree()
185             + ")"); //$NON-NLS-1$
186

187         ContextMenuItem menuVersions = new ContextMenuItem("versions");
188         menuVersions.setLabel(msgs.get("versions")); //$NON-NLS-1$
189
menuVersions.setIcon(request.getContextPath() + "/.resources/icons/16/elements1.gif"); //$NON-NLS-1$
190
menuVersions.setOnclick("mgnl.admininterface.WebsiteTree.showVersions(" + tree.getJavascriptTree() + ");"); //$NON-NLS-1$ //$NON-NLS-2$
191
menuVersions.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
192
+ tree.getJavascriptTree()
193             + ")"); //$NON-NLS-1$
194

195         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
196         menuActivateExcl.setLabel(msgs.get("tree.web.menu.activate")); //$NON-NLS-1$
197
menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
198

199         menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
200
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
201
+ tree.getJavascriptTree()
202             + ")"); //$NON-NLS-1$
203
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
204
+ tree.getJavascriptTree()
205             + ")"); //$NON-NLS-1$
206

207         ContextMenuItem menuActivateIncl = new ContextMenuItem("activateInclSubs");
208         menuActivateIncl.setLabel(msgs.get("tree.web.menu.activateInclSubs")); //$NON-NLS-1$
209
menuActivateIncl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green_double.gif"); //$NON-NLS-1$
210
menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); //$NON-NLS-1$ //$NON-NLS-2$
211
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
212
+ tree.getJavascriptTree()
213             + ")"); //$NON-NLS-1$
214
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
215
+ tree.getJavascriptTree()
216             + ")"); //$NON-NLS-1$
217

218         ContextMenuItem menuDeActivate = new ContextMenuItem("deactivate");
219         menuDeActivate.setLabel(msgs.get("tree.web.menu.deactivate")); //$NON-NLS-1$
220
menuDeActivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
221
menuDeActivate.setOnclick(tree.getJavascriptTree() + ".deActivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
222
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
223
+ tree.getJavascriptTree()
224             + ")"); //$NON-NLS-1$
225
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
226
+ tree.getJavascriptTree()
227             + ")"); //$NON-NLS-1$
228

229         ContextMenuItem menuExport = new ContextMenuItem("export");
230         menuExport.setLabel(msgs.get("tree.menu.export")); //$NON-NLS-1$
231
menuExport.setIcon(request.getContextPath() + "/.resources/icons/16/export1.gif"); //$NON-NLS-1$
232
menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); //$NON-NLS-1$
233

234         ContextMenuItem menuImport = new ContextMenuItem("import");
235         menuImport.setLabel(msgs.get("tree.menu.import")); //$NON-NLS-1$
236
menuImport.setIcon(request.getContextPath() + "/.resources/icons/16/import2.gif"); //$NON-NLS-1$
237
menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); //$NON-NLS-1$
238

239         // is there a subscriber?
240
if (!Subscriber.isSubscribersEnabled()) {
241             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
242
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
243
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
244
}
245
246         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
247
+ tree.getJavascriptTree()
248             + ")"); //$NON-NLS-1$
249

250         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
251
+ tree.getJavascriptTree()
252             + ")"); //$NON-NLS-1$
253

254         if (!browseMode) {
255             tree.addMenuItem(menuOpen);
256             tree.addMenuItem(menuNewPage);
257
258             tree.addSeparator();
259             tree.addMenuItem(menuDelete);
260
261             tree.addSeparator();
262             tree.addMenuItem(menuMove);
263             tree.addMenuItem(menuCopy);
264
265             tree.addSeparator();
266             tree.addMenuItem(menuVersions);
267
268             tree.addSeparator();
269             tree.addMenuItem(menuActivateExcl);
270             tree.addMenuItem(menuActivateIncl);
271             tree.addMenuItem(menuDeActivate);
272
273             tree.addSeparator();
274             tree.addMenuItem(menuExport);
275             tree.addMenuItem(menuImport);
276         }
277         else {
278             ContextMenuItem menuRefresh = new ContextMenuItem("refresh");
279             menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
280
menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); //$NON-NLS-1$
281
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
282
tree.addMenuItem(menuRefresh);
283         }
284
285     }
286
287     /**
288      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareFunctionBar(info.magnolia.cms.gui.control.Tree,
289      * boolean, javax.servlet.http.HttpServletRequest)
290      */

291     public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
292         Messages msgs = MessagesManager.getMessages();
293         ContextMenu cm = tree.getMenu();
294         ContextMenuItem cmItem = cm.getMenuItemByName("open");
295         if (cmItem != null) {
296             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
297         }
298         cmItem = cm.getMenuItemByName("new");
299         if (cmItem != null) {
300             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
301         }
302         // null is separator :)
303
tree.addFunctionBarItem(null);
304         cmItem = cm.getMenuItemByName("activate");
305         if (cmItem != null) {
306             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
307         }
308         cmItem = cm.getMenuItemByName("deactivate");
309         if (cmItem != null) {
310             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
311         }
312         // null is separator :)
313
tree.addFunctionBarItem(null);
314
315         ContextMenuItem menuRefresh = new ContextMenuItem("refresh");
316         menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
317
menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); //$NON-NLS-1$
318
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
319
tree.addFunctionBarItem(new FunctionBarItem(menuRefresh));
320
321         tree.getFunctionBar().setSearchable(true);
322         tree.getFunctionBar().setOnSearchFunction("mgnl.admininterface.WebsiteTree.search");
323     }
324
325 }
326
Popular Tags