KickJava   Java API By Example, From Geeks To Geeks.

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


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.Server;
16 import info.magnolia.cms.beans.config.Subscriber;
17 import info.magnolia.cms.core.ItemType;
18 import info.magnolia.cms.core.MetaData;
19 import info.magnolia.cms.gui.control.ContextMenu;
20 import info.magnolia.cms.gui.control.ContextMenuItem;
21 import info.magnolia.cms.gui.control.FunctionBarItem;
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.module.admininterface.AdminTreeConfiguration;
28
29 import javax.jcr.PropertyType;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31
32 import org.apache.commons.lang.StringUtils;
33
34
35 /**
36  * @author Philipp Bracher
37  * @version $Revision: 6341 $ ($Author: philipp $)
38  */

39 public class ConfigTreeConfiguration implements AdminTreeConfiguration {
40
41     /**
42      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareTree(info.magnolia.cms.gui.control.Tree,
43      * boolean, javax.servlet.http.HttpServletRequest)
44      */

45     public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
46         Messages msgs = MessagesManager.getMessages();
47
48         tree.setIconPage(Tree.ICONDOCROOT + "folder_cubes.gif"); //$NON-NLS-1$
49

50         tree.addItemType(ItemType.CONTENT.getSystemName());
51         tree.addItemType(ItemType.CONTENTNODE.getSystemName());
52         tree.addItemType(Tree.ITEM_TYPE_NODEDATA);
53         TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request);
54         column0.setWidth(1);
55         column0.setHtmlEdit();
56         column0.setIsLabel(true);
57         column0.setWidth(3);
58         TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request);
59         column1.setName(StringUtils.EMPTY);
60         column1.setTitle(msgs.get("tree.config.value")); //$NON-NLS-1$
61
column1.setIsNodeDataValue(true);
62         column1.setWidth(2);
63         column1.setHtmlEdit();
64         TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request);
65         column2.setName(StringUtils.EMPTY);
66         column2.setTitle(msgs.get("tree.config.type")); //$NON-NLS-1$
67
column2.setIsNodeDataType(true);
68         column2.setWidth(2);
69         Select typeSelect = new Select();
70         typeSelect.setName(tree.getJavascriptTree() + TreeColumn.EDIT_NAMEADDITION);
71         typeSelect.setSaveInfo(false);
72         typeSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT);
73         typeSelect.setEvent(
74             "onblur", tree.getJavascriptTree() + ".saveNodeData(this.value,this.options[this.selectedIndex].text)"); //$NON-NLS-1$
75
typeSelect.setOptions(PropertyType.TYPENAME_STRING, Integer.toString(PropertyType.STRING));
76         typeSelect.setOptions(PropertyType.TYPENAME_BOOLEAN, Integer.toString(PropertyType.BOOLEAN));
77         typeSelect.setOptions(PropertyType.TYPENAME_LONG, Integer.toString(PropertyType.LONG));
78         typeSelect.setOptions(PropertyType.TYPENAME_DOUBLE, Integer.toString(PropertyType.DOUBLE));
79         // todo: typeSelect.setOptions(PropertyType.TYPENAME_DATE,Integer.toString(PropertyType.DATE));
80
column2.setHtmlEdit(typeSelect.getHtml());
81         TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request);
82         columnIcons.setCssClass(StringUtils.EMPTY);
83         columnIcons.setWidth(1);
84         columnIcons.setIsIcons(true);
85         columnIcons.setIconsActivation(true);
86         columnIcons.setIconsPermission(true);
87         TreeColumn column4 = new TreeColumn(tree.getJavascriptTree(), request);
88         column4.setName(MetaData.LAST_MODIFIED);
89         column4.setIsMeta(true);
90         column4.setDateFormat("yy-MM-dd, HH:mm"); //$NON-NLS-1$
91
column4.setWidth(2);
92         column4.setTitle(msgs.get("tree.config.date")); //$NON-NLS-1$
93

94         tree.addColumn(column0);
95
96         if (!browseMode) {
97             tree.addColumn(column1);
98             tree.addColumn(column2);
99             if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) {
100                 tree.addColumn(columnIcons);
101             }
102             tree.addColumn(column4);
103         }
104     }
105
106     /**
107      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
108      * boolean, javax.servlet.http.HttpServletRequest)
109      */

110     public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
111         Messages msgs = MessagesManager.getMessages();
112
113         ContextMenuItem menuNewPage = new ContextMenuItem("newFolder");
114         menuNewPage.setLabel(msgs.get("tree.config.menu.newFolder")); //$NON-NLS-1$
115
menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/folder_cubes.gif"); //$NON-NLS-1$
116
menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); //$NON-NLS-1$ //$NON-NLS-2$
117
menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
118
+ tree.getJavascriptTree()
119             + ")"); //$NON-NLS-1$
120
menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotContentNode(" //$NON-NLS-1$
121
+ tree.getJavascriptTree()
122             + ")"); //$NON-NLS-1$
123

124         ContextMenuItem menuNewContentNode = new ContextMenuItem("newNode");
125         menuNewContentNode.setLabel(msgs.get("tree.config.menu.newNode")); //$NON-NLS-1$
126
menuNewContentNode.setIcon(request.getContextPath() + "/.resources/icons/16/cubes.gif"); //$NON-NLS-1$
127
menuNewContentNode.setOnclick(tree.getJavascriptTree() + ".createNode('" //$NON-NLS-1$
128
+ ItemType.CONTENTNODE.getSystemName()
129             + "');"); //$NON-NLS-1$
130
menuNewContentNode.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
131
+ tree.getJavascriptTree()
132             + ")"); //$NON-NLS-1$
133

134         ContextMenuItem menuNewNodeData = new ContextMenuItem("newData");
135         menuNewNodeData.setLabel(msgs.get("tree.config.menu.newNodeData")); //$NON-NLS-1$
136
menuNewNodeData.setIcon(request.getContextPath() + "/.resources/icons/16/cube_green.gif"); //$NON-NLS-1$
137
menuNewNodeData.setOnclick(tree.getJavascriptTree() + ".createNode('" + Tree.ITEM_TYPE_NODEDATA + "');"); //$NON-NLS-1$ //$NON-NLS-2$
138
menuNewNodeData.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
139
+ tree.getJavascriptTree()
140             + ")"); //$NON-NLS-1$
141

142         ContextMenuItem menuDelete = new ContextMenuItem("delete");
143         menuDelete.setLabel(msgs.get("tree.config.menu.delete")); //$NON-NLS-1$
144
menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); //$NON-NLS-1$
145
menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
146
menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
147
+ tree.getJavascriptTree()
148             + ")"); //$NON-NLS-1$
149

150         ContextMenuItem menuCopy = new ContextMenuItem("copy");
151         menuCopy.setLabel(msgs.get("tree.config.menu.copy")); //$NON-NLS-1$
152
menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
153
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
154
+ tree.getJavascriptTree()
155             + ")"); //$NON-NLS-1$
156
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
157
+ tree.getJavascriptTree()
158             + ")"); //$NON-NLS-1$
159
menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
160

161         ContextMenuItem menuCut = new ContextMenuItem("move");
162         menuCut.setLabel(msgs.get("tree.config.menu.move")); //$NON-NLS-1$
163
menuCut.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
164
menuCut
165             .addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
166
menuCut.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
167
+ tree.getJavascriptTree()
168             + ")"); //$NON-NLS-1$
169
menuCut.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
170

171         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
172         menuActivateExcl.setLabel(msgs.get("tree.config.menu.activate")); //$NON-NLS-1$
173
menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
174
menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
175
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
176
+ tree.getJavascriptTree()
177             + ")"); //$NON-NLS-1$
178
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
179
+ tree.getJavascriptTree()
180             + ")"); //$NON-NLS-1$
181

182         ContextMenuItem menuActivateIncl = new ContextMenuItem("activateInclSubs");
183         menuActivateIncl.setLabel(msgs.get("tree.config.menu.activateInclSubs")); //$NON-NLS-1$
184
menuActivateIncl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green_double.gif"); //$NON-NLS-1$
185
menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); //$NON-NLS-1$ //$NON-NLS-2$
186
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
187
+ tree.getJavascriptTree()
188             + ")"); //$NON-NLS-1$
189
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
190
+ tree.getJavascriptTree()
191             + ")"); //$NON-NLS-1$
192

193         ContextMenuItem menuDeActivate = new ContextMenuItem("deactivate");
194         menuDeActivate.setLabel(msgs.get("tree.config.menu.deactivate")); //$NON-NLS-1$
195
menuDeActivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
196
menuDeActivate.setOnclick(tree.getJavascriptTree() + ".deActivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
197
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
198
+ tree.getJavascriptTree()
199             + ")"); //$NON-NLS-1$
200
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
201
+ tree.getJavascriptTree()
202             + ")"); //$NON-NLS-1$
203

204         ContextMenuItem menuExport = new ContextMenuItem("export");
205         menuExport.setLabel(msgs.get("tree.menu.export")); //$NON-NLS-1$
206
menuExport.setIcon(request.getContextPath() + "/.resources/icons/16/export1.gif"); //$NON-NLS-1$
207
menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); //$NON-NLS-1$
208
menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
209
+ tree.getJavascriptTree()
210             + ")"); //$NON-NLS-1$
211

212         ContextMenuItem menuImport = new ContextMenuItem("import");
213         menuImport.setLabel(msgs.get("tree.menu.import")); //$NON-NLS-1$
214
menuImport.setIcon(request.getContextPath() + "/.resources/icons/16/import2.gif"); //$NON-NLS-1$
215
menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); //$NON-NLS-1$
216
menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
217
+ tree.getJavascriptTree()
218             + ")"); //$NON-NLS-1$
219

220         // is it possible to activate?
221
if (!Subscriber.isSubscribersEnabled()) {
222             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
223
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
224
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
225
}
226
227         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
228
+ tree.getJavascriptTree()
229             + ")"); //$NON-NLS-1$
230

231         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
232
+ tree.getJavascriptTree()
233             + ")"); //$NON-NLS-1$
234

235         if (!browseMode) {
236             tree.addMenuItem(menuNewPage);
237             tree.addMenuItem(menuNewContentNode);
238             tree.addMenuItem(menuNewNodeData);
239
240             tree.addSeparator();
241             tree.addMenuItem(menuDelete);
242
243             tree.addSeparator();
244             tree.addMenuItem(menuCut);
245             tree.addMenuItem(menuCopy);
246
247             tree.addSeparator();
248             tree.addMenuItem(menuActivateExcl);
249             tree.addMenuItem(menuActivateIncl);
250             tree.addMenuItem(menuDeActivate);
251
252             tree.addSeparator();
253             tree.addMenuItem(menuExport);
254             tree.addMenuItem(menuImport);
255         }
256         else {
257             ContextMenuItem menuRefresh = new ContextMenuItem("refresh");
258             menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
259
menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); //$NON-NLS-1$
260
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
261
tree.addMenuItem(menuRefresh);
262         }
263
264     }
265
266     /**
267      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareFunctionBar(info.magnolia.cms.gui.control.Tree,
268      * boolean, javax.servlet.http.HttpServletRequest)
269      */

270     public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
271         Messages msgs = MessagesManager.getMessages();
272         ContextMenu cm = tree.getMenu();
273         ContextMenuItem cmItem = cm.getMenuItemByName("newFolder");
274         if (cmItem != null) {
275             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
276         }
277         cmItem = cm.getMenuItemByName("newNode");
278         if (cmItem != null) {
279             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
280         }
281         cmItem = cm.getMenuItemByName("newData");
282         if (cmItem != null) {
283             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
284         }
285         // null is separator :)
286
tree.addFunctionBarItem(null);
287         cmItem = cm.getMenuItemByName("activate");
288         if (cmItem != null) {
289             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
290         }
291         cmItem = cm.getMenuItemByName("deactivate");
292         if (cmItem != null) {
293             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
294         }
295         // null is separator :)
296
tree.addFunctionBarItem(null);
297
298         ContextMenuItem menuRefresh = new ContextMenuItem("refresh");
299         menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
300
menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); //$NON-NLS-1$
301
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
302
tree.addFunctionBarItem(new FunctionBarItem(menuRefresh));
303     }
304
305 }
306
Popular Tags