KickJava   Java API By Example, From Geeks To Geeks.

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


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.Tree;
23 import info.magnolia.cms.gui.control.TreeColumn;
24 import info.magnolia.cms.i18n.Messages;
25 import info.magnolia.cms.i18n.MessagesManager;
26 import info.magnolia.module.admininterface.AdminTreeConfiguration;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29
30 import org.apache.commons.lang.StringUtils;
31
32
33 /**
34  * @author Philipp Bracher
35  * @version $Revision: 6341 $ ($Author: philipp $)
36  */

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

43     public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
44         Messages msgs = MessagesManager.getMessages();
45
46         tree.setDrawShifter(false);
47
48         tree.setIcon(ItemType.ROLE.getSystemName(), Tree.ICONDOCROOT + "hat_white.gif"); //$NON-NLS-1$
49
tree.setIconOndblclick("mgnlTreeMenuOpenDialog(" //$NON-NLS-1$
50
+ tree.getJavascriptTree()
51             + ",'.magnolia/dialogs/roleedit.html');"); //$NON-NLS-1$
52
tree.addItemType(ItemType.ROLE);
53
54         TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request);
55         column0.setIsLabel(true);
56         if (Server.isAdmin()) {
57             column0.setHtmlEdit();
58         }
59         column0.setWidth(2);
60         column0.setTitle(msgs.get("tree.roles.name")); //$NON-NLS-1$
61
TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request);
62         column1.setName("title"); //$NON-NLS-1$
63
if (Server.isAdmin() && !browseMode) {
64             column1.setHtmlEdit();
65         }
66         column1.setWidth(2);
67         column1.setTitle(msgs.get("tree.roles.fullname")); //$NON-NLS-1$
68
TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request);
69         columnIcons.setCssClass(StringUtils.EMPTY);
70         columnIcons.setWidth(1);
71         columnIcons.setIsIcons(true);
72         columnIcons.setIconsActivation(true);
73         TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request);
74         column2.setName(MetaData.CREATION_DATE);
75         // column2.setName(MetaData.SEQUENCE_POS);
76
column2.setIsMeta(true);
77         column2.setDateFormat("yyyy-MM-dd, HH:mm"); //$NON-NLS-1$
78
column2.setTitle(msgs.get("tree.roles.date")); //$NON-NLS-1$
79
column2.setWidth(2);
80
81         tree.addColumn(column0);
82         if (!browseMode) {
83             tree.addColumn(column1);
84             if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) {
85                 tree.addColumn(columnIcons);
86             }
87             tree.addColumn(column2);
88         }
89
90     }
91
92     /**
93      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
94      * boolean, javax.servlet.http.HttpServletRequest)
95      */

96     public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
97         Messages msgs = MessagesManager.getMessages();
98
99         ContextMenuItem menuOpen = new ContextMenuItem("edit");
100         menuOpen.setLabel(msgs.get("tree.roles.menu.edit")); //$NON-NLS-1$
101
menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/hat_white.gif"); //$NON-NLS-1$
102
menuOpen.setOnclick("mgnlTreeMenuOpenDialog(" //$NON-NLS-1$
103
+ tree.getJavascriptTree()
104             + ",'.magnolia/dialogs/roleedit.html');"); //$NON-NLS-1$
105
menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
106
+ tree.getJavascriptTree()
107             + ")"); //$NON-NLS-1$
108
ContextMenuItem menuNewPage = new ContextMenuItem("new");
109         menuNewPage.setLabel(msgs.get("tree.roles.menu.new")); //$NON-NLS-1$
110
menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/hat_white_add.gif"); //$NON-NLS-1$
111
menuNewPage.setOnclick(tree.getJavascriptTree() + ".createRootNode('" //$NON-NLS-1$
112
+ ItemType.ROLE.getSystemName()
113             + "');"); //$NON-NLS-1$
114
ContextMenuItem menuDelete = new ContextMenuItem("delete");
115         menuDelete.setLabel(msgs.get("tree.roles.menu.delete")); //$NON-NLS-1$
116
menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); //$NON-NLS-1$
117
menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
118
menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
119
+ tree.getJavascriptTree()
120             + ")"); //$NON-NLS-1$
121
ContextMenuItem menuMove = new ContextMenuItem("move");
122         menuMove.setLabel(msgs.get("tree.roles.menu.move")); //$NON-NLS-1$
123
menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
124
menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
125
menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
126
+ tree.getJavascriptTree()
127             + ")"); //$NON-NLS-1$
128
ContextMenuItem menuCopy = new ContextMenuItem("copy");
129         menuCopy.setLabel(msgs.get("tree.roles.menu.copy")); //$NON-NLS-1$
130
menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
131
menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
132
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
133
+ tree.getJavascriptTree()
134             + ")"); //$NON-NLS-1$
135

136         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
137         menuActivateExcl.setLabel(msgs.get("tree.roles.menu.activate")); //$NON-NLS-1$
138
menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
139
menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
140
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
141
+ tree.getJavascriptTree()
142             + ")"); //$NON-NLS-1$
143
ContextMenuItem menuDeActivate = new ContextMenuItem("deactivate");
144         menuDeActivate.setLabel(msgs.get("tree.roles.menu.deactivate")); //$NON-NLS-1$
145
menuDeActivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
146
menuDeActivate.setOnclick(tree.getJavascriptTree() + ".deActivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
147
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
148
+ tree.getJavascriptTree()
149             + ")"); //$NON-NLS-1$
150

151         if (!Subscriber.isSubscribersEnabled()) {
152             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
153
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
154
}
155
156         if (!browseMode) {
157             tree.addMenuItem(menuOpen);
158             tree.addMenuItem(menuNewPage);
159
160             tree.addMenuItem(null); // line
161
tree.addMenuItem(menuDelete);
162
163             tree.addMenuItem(null); // line
164
tree.addMenuItem(menuActivateExcl);
165             tree.addMenuItem(menuDeActivate);
166         }
167         else {
168             ContextMenuItem menuRefresh = new ContextMenuItem("refresh");
169             menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
170
menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); //$NON-NLS-1$
171
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
172
tree.addMenuItem(menuRefresh);
173         }
174     }
175
176     /**
177      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareFunctionBar(info.magnolia.cms.gui.control.Tree,
178      * boolean, javax.servlet.http.HttpServletRequest)
179      */

180     public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
181         Messages msgs = MessagesManager.getMessages();
182         ContextMenu cm = tree.getMenu();
183         ContextMenuItem cmItem = cm.getMenuItemByName("edit");
184         if (cmItem != null) {
185             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
186         }
187         cmItem = cm.getMenuItemByName("new");
188         if (cmItem != null) {
189             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
190         }
191         // null is separator :)
192
tree.addFunctionBarItem(null);
193         cmItem = cm.getMenuItemByName("activate");
194         if (cmItem != null) {
195             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
196         }
197         cmItem = cm.getMenuItemByName("deactivate");
198         if (cmItem != null) {
199             tree.addFunctionBarItem(new FunctionBarItem(cmItem));
200         }
201         tree.addFunctionBarItem(null);
202         ContextMenuItem menuRefresh = new ContextMenuItem("refresh");
203         menuRefresh.setLabel(msgs.get("tree.menu.refresh")); //$NON-NLS-1$
204
menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); //$NON-NLS-1$
205
menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); //$NON-NLS-1$
206
tree.addFunctionBarItem(new FunctionBarItem(menuRefresh));
207     }
208
209 }
210
Popular Tags