KickJava   Java API By Example, From Geeks To Geeks.

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


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

40 public class AdminTreeConfig extends AdminTreeMVCHandler {
41
42     /**
43      * @param name
44      * @param request
45      * @param response
46      */

47     public AdminTreeConfig(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
48         super(name, request, response);
49     }
50
51     protected void prepareTree(Tree tree, HttpServletRequest JavaDoc request) {
52         Messages msgs = MessagesManager.getMessages(request);
53
54         tree.setIconPage(Tree.ICONDOCROOT + "folder_cubes.gif"); //$NON-NLS-1$
55

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

99         tree.addColumn(column0);
100
101         if (!this.isBrowseMode()) {
102             tree.addColumn(column1);
103             tree.addColumn(column2);
104             if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) {
105                 tree.addColumn(columnIcons);
106             }
107             tree.addColumn(column4);
108         }
109     }
110
111     /**
112      * @param tree
113      * @param request
114      * @param msgs
115      */

116     protected void prepareContextMenu(Tree tree, HttpServletRequest JavaDoc request) {
117         Messages msgs = MessagesManager.getMessages(request);
118
119         ContextMenuItem menuNewPage = new ContextMenuItem();
120         menuNewPage.setLabel("<img SRC=\"" //$NON-NLS-1$
121
+ request.getContextPath()
122             + new Icon().getSrc(Icon.PAGE, Icon.SIZE_SMALL)
123             + "\"> <span style=\"position:relative;top:-3px;\">" //$NON-NLS-1$
124
+ msgs.get("tree.config.menu.newFolder") //$NON-NLS-1$
125
+ "</span>"); //$NON-NLS-1$
126
menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); //$NON-NLS-1$ //$NON-NLS-2$
127
menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
128
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
129
menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotContentNode(" //$NON-NLS-1$
130
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
131

132         ContextMenuItem menuNewContentNode = new ContextMenuItem();
133         menuNewContentNode.setLabel("<img SRC=\"" //$NON-NLS-1$
134
+ request.getContextPath()
135             + new Icon().getSrc(Icon.CONTENTNODE, Icon.SIZE_SMALL)
136             + "\"> <span style=\"position:relative;top:-3px\">" //$NON-NLS-1$
137
+ msgs.get("tree.config.menu.newNode") //$NON-NLS-1$
138
+ "</span>"); //$NON-NLS-1$
139
menuNewContentNode.setOnclick(tree.getJavascriptTree() + ".createNode('" //$NON-NLS-1$
140
+ ItemType.CONTENTNODE.getSystemName() + "');"); //$NON-NLS-1$
141
menuNewContentNode.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
142
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
143

144         ContextMenuItem menuNewNodeData = new ContextMenuItem();
145         menuNewNodeData.setLabel("<img SRC=\"" //$NON-NLS-1$
146
+ request.getContextPath()
147             + new Icon().getSrc(Icon.NODEDATA, Icon.SIZE_SMALL)
148             + "\"> <span style=\"position:relative;top:-3px;\">" //$NON-NLS-1$
149
+ msgs.get("tree.config.menu.newNodeData") //$NON-NLS-1$
150
+ "</span>"); //$NON-NLS-1$
151
menuNewNodeData.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.NT_NODEDATA + "');"); //$NON-NLS-1$ //$NON-NLS-2$
152
menuNewNodeData.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
153
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
154

155         ContextMenuItem menuDelete = new ContextMenuItem();
156         menuDelete.setLabel(msgs.get("tree.config.menu.delete")); //$NON-NLS-1$
157
menuDelete.setIcon(request.getContextPath() + "/admindocroot/icons/16/delete2.gif"); //$NON-NLS-1$
158
menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
159
menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
160
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
161

162         ContextMenuItem menuCopy = new ContextMenuItem();
163         menuCopy.setLabel(msgs.get("tree.config.menu.copy")); //$NON-NLS-1$
164
menuCopy.setIcon(request.getContextPath() + "/admindocroot/icons/16/copy.gif"); //$NON-NLS-1$
165
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
166
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
167
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
168
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
169
menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
170

171         ContextMenuItem menuCut = new ContextMenuItem();
172         menuCut.setLabel(msgs.get("tree.config.menu.move")); //$NON-NLS-1$
173
menuCut.setIcon(request.getContextPath() + "/admindocroot/icons/16/up_down.gif"); //$NON-NLS-1$
174
menuCut
175             .addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
176
menuCut.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
177
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
178
menuCut.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
179

180         ContextMenuItem menuActivateExcl = new ContextMenuItem();
181         menuActivateExcl.setLabel(msgs.get("tree.config.menu.activate")); //$NON-NLS-1$
182
menuActivateExcl.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
183
menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
184
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
185
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
186
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
187
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
188

189         ContextMenuItem menuActivateIncl = new ContextMenuItem();
190         menuActivateIncl.setLabel(msgs.get("tree.config.menu.activateInclSubs")); //$NON-NLS-1$
191
menuActivateIncl.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
192
menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); //$NON-NLS-1$ //$NON-NLS-2$
193
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
194
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
195
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
196
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
197

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

207         ContextMenuItem menuRefresh = new ContextMenuItem();
208         menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
209
menuRefresh.setIcon(request.getContextPath() + "/admindocroot/icons/16/refresh.gif"); //$NON-NLS-1$
210
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
211

212         ContextMenuItem menuExport = new ContextMenuItem();
213         menuExport.setLabel(msgs.get("tree.menu.export")); //$NON-NLS-1$
214
menuExport.setIcon(request.getContextPath() + "/admindocroot/icons/16/export.gif"); //$NON-NLS-1$
215
menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); //$NON-NLS-1$
216
menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
217
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
218
menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
219
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
220

221         ContextMenuItem menuImport = new ContextMenuItem();
222         menuImport.setLabel(msgs.get("tree.menu.import")); //$NON-NLS-1$
223
menuImport.setIcon(request.getContextPath() + "/admindocroot/icons/16/import1.gif"); //$NON-NLS-1$
224
menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); //$NON-NLS-1$
225
menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
226
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
227
menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
228
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
229

230         // is it possible to activate?
231
if (!Subscriber.isSubscribersEnabled()) {
232             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
233
menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
234
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
235
}
236
237         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
238
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
239

240         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
241
+ tree.getJavascriptTree() + ")"); //$NON-NLS-1$
242

243         if (!this.isBrowseMode()) {
244             tree.addMenuItem(menuNewPage);
245             tree.addMenuItem(menuNewContentNode);
246             tree.addMenuItem(menuNewNodeData);
247
248             tree.addSeparator();
249             tree.addMenuItem(menuDelete);
250
251             tree.addSeparator();
252             tree.addMenuItem(menuCut);
253             tree.addMenuItem(menuCopy);
254
255             tree.addSeparator();
256             tree.addMenuItem(menuActivateExcl);
257             tree.addMenuItem(menuActivateIncl);
258             tree.addMenuItem(menuDeActivate);
259
260             tree.addSeparator();
261             tree.addMenuItem(menuExport);
262             tree.addMenuItem(menuImport);
263
264             tree.addSeparator();
265         }
266         tree.addMenuItem(menuRefresh);
267     }
268
269 }
Popular Tags