KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.ItemType;
20 import info.magnolia.cms.core.MetaData;
21 import info.magnolia.cms.gui.control.ContextMenuItem;
22 import info.magnolia.cms.gui.control.Select;
23 import info.magnolia.cms.gui.control.Tree;
24 import info.magnolia.cms.gui.control.TreeColumn;
25 import info.magnolia.cms.i18n.Messages;
26 import info.magnolia.cms.i18n.MessagesManager;
27 import info.magnolia.cms.i18n.TemplateMessagesUtil;
28 import info.magnolia.cms.security.SessionAccessControl;
29 import info.magnolia.module.admininterface.AdminTreeMVCHandler;
30
31 import java.util.Iterator JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 import org.apache.commons.lang.StringUtils;
37
38
39 /**
40  * Handles the tree rendering for the "website" repository.
41  * @author Fabrizio Giustina
42  * @version $Id: AdminTreeWebsite.java 685 2005-05-04 19:23:59Z philipp $
43  */

44 public class AdminTreeWebsite extends AdminTreeMVCHandler {
45
46     /**
47      * @param name
48      * @param request
49      * @param response
50      */

51     public AdminTreeWebsite(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
52         super(name, request, response);
53     }
54
55     protected String JavaDoc getRepository() {
56         return ContentRepository.WEBSITE;
57     }
58
59     /**
60      * @see info.magnolia.module.admininterface.AdminTree#prepareTree()
61      */

62     protected void prepareTree(Tree tree, HttpServletRequest JavaDoc request) {
63         Messages msgs = MessagesManager.getMessages(request);
64
65         tree.setIconOndblclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); //$NON-NLS-1$ //$NON-NLS-2$
66

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

109         Iterator JavaDoc templates = Template.getAvailableTemplates(SessionAccessControl.getAccessManager(
110             request,
111             ContentRepository.CONFIG));
112         while (templates.hasNext()) {
113             Template template = (Template) templates.next();
114             String JavaDoc title = template.getTitle();
115             title = TemplateMessagesUtil.get(request, title);
116             title = Messages.javaScriptString(title);
117             templateSelect.setOptions(title, template.getName());
118         }
119         if (Server.isAdmin()) {
120             column2.setHtmlEdit(templateSelect.getHtml());
121         }
122         // todo: key/value -> column2.addKeyValue("sampleBasic","Samples: Basic Template");
123
// todo: preselection (set on createPage)
124
TreeColumn column3 = new TreeColumn(tree.getJavascriptTree(), request);
125         column3.setName(MetaData.LAST_MODIFIED);
126         // column3.setName(MetaData.SEQUENCE_POS);
127
column3.setIsMeta(true);
128         column3.setDateFormat("yy-MM-dd, HH:mm"); //$NON-NLS-1$
129
column3.setWidth(2);
130         column3.setTitle(msgs.get("tree.web.date")); //$NON-NLS-1$
131

132         tree.addColumn(column0);
133
134         if (!this.isBrowseMode()) {
135             tree.addColumn(column1);
136             if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) {
137                 tree.addColumn(columnIcons);
138             }
139             tree.addColumn(column2);
140             tree.addColumn(column3);
141         }
142     }
143
144     /**
145      * @see info.magnolia.module.admininterface.AdminTreeMVCHandler#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
146      * javax.servlet.http.HttpServletRequest)
147      */

148     protected void prepareContextMenu(Tree tree, HttpServletRequest JavaDoc request) {
149         Messages msgs = MessagesManager.getMessages(request);
150         ContextMenuItem menuOpen = new ContextMenuItem();
151         menuOpen.setLabel(msgs.get("tree.web.menu.open")); //$NON-NLS-1$
152
menuOpen.setIcon(request.getContextPath() + "/admindocroot/icons/16/document_plain_earth.gif"); //$NON-NLS-1$
153
menuOpen.setOnclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); //$NON-NLS-1$ //$NON-NLS-2$
154
menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
155
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
156

157         ContextMenuItem menuNewPage = new ContextMenuItem();
158         menuNewPage.setLabel(msgs.get("tree.web.menu.new")); //$NON-NLS-1$
159
menuNewPage.setIcon(request.getContextPath() + "/admindocroot/icons/16/document_plain_earth_add.gif"); //$NON-NLS-1$
160

161         menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); //$NON-NLS-1$ //$NON-NLS-2$
162
menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
163
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
164

165         ContextMenuItem menuDelete = new ContextMenuItem();
166         menuDelete.setLabel(msgs.get("tree.web.menu.delete")); //$NON-NLS-1$
167
menuDelete.setIcon(request.getContextPath() + "/admindocroot/icons/16/delete2.gif"); //$NON-NLS-1$
168
menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
169
menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
170
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
171
menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
172
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
173

174         ContextMenuItem menuMove = new ContextMenuItem();
175         menuMove.setLabel(msgs.get("tree.web.menu.move")); //$NON-NLS-1$
176
menuMove.setIcon(request.getContextPath() + "/admindocroot/icons/16/up_down.gif"); //$NON-NLS-1$
177
menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
178
menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
179
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
180
menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
181
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
182

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

190         ContextMenuItem menuActivateExcl = new ContextMenuItem();
191         menuActivateExcl.setLabel(msgs.get("tree.web.menu.activate")); //$NON-NLS-1$
192
menuActivateExcl.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
193

194         menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
195
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
196
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
197
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
198
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
199

200         ContextMenuItem menuActivateIncl = new ContextMenuItem();
201         menuActivateIncl.setLabel(msgs.get("tree.web.menu.activateInclSubs")); //$NON-NLS-1$
202
menuActivateIncl.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
203
menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); //$NON-NLS-1$ //$NON-NLS-2$
204
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
205
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
206
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
207
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
208

209         ContextMenuItem menuDeActivate = new ContextMenuItem();
210         menuDeActivate.setLabel(msgs.get("tree.web.menu.deactivate")); //$NON-NLS-1$
211
menuDeActivate.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
212
menuDeActivate.setOnclick(tree.getJavascriptTree() + ".deActivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
213
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
214
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
215
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
216
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
217

218         ContextMenuItem menuRefresh = new ContextMenuItem();
219         menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
220
menuRefresh.setIcon(request.getContextPath() + "/admindocroot/icons/16/refresh.gif"); //$NON-NLS-1$
221
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
222

223         ContextMenuItem menuExport = new ContextMenuItem();
224         menuExport.setLabel(msgs.get("tree.menu.export")); //$NON-NLS-1$
225
menuExport.setIcon(request.getContextPath() + "/admindocroot/icons/16/export.gif"); //$NON-NLS-1$
226
menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); //$NON-NLS-1$
227
menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
228
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
229
menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
230
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
231

232         ContextMenuItem menuImport = new ContextMenuItem();
233         menuImport.setLabel(msgs.get("tree.menu.import")); //$NON-NLS-1$
234
menuImport.setIcon(request.getContextPath() + "/admindocroot/icons/16/import1.gif"); //$NON-NLS-1$
235
menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); //$NON-NLS-1$
236
menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
237
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
238
menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
239
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
240

241         // those menuitems are not active on public side
242
if (!Server.isAdmin()) {
243             menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
244
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
245
menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
246
menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
247
menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
248
}
249
250         // is there a subscriber?
251
if (!Subscriber.isSubscribersEnabled()) {
252             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
253
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
254
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
255
}
256
257         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
258
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
259

260         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
261
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
262

263         if (!this.isBrowseMode()) {
264             tree.addMenuItem(menuOpen);
265             tree.addMenuItem(menuNewPage);
266
267             tree.addSeparator();
268             tree.addMenuItem(menuDelete);
269
270             tree.addSeparator();
271             tree.addMenuItem(menuMove);
272             tree.addMenuItem(menuCopy);
273
274             tree.addSeparator();
275             tree.addMenuItem(menuActivateExcl);
276             tree.addMenuItem(menuActivateIncl);
277             tree.addMenuItem(menuDeActivate);
278
279             tree.addSeparator();
280             tree.addMenuItem(menuExport);
281             tree.addMenuItem(menuImport);
282
283             tree.addSeparator();
284         }
285         tree.addMenuItem(menuRefresh);
286     }
287
288 }
Popular Tags