KickJava   Java API By Example, From Geeks To Geeks.

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


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 UsersTreeConfiguration 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         // context path is already added by Tree
48
tree.setIcon(ItemType.USER.getSystemName(), Tree.ICONDOCROOT + "pawn_glass_yellow.gif"); //$NON-NLS-1$
49
tree.setIconOndblclick("mgnlTreeMenuOpenDialog(" + tree.getJavascriptTree() //$NON-NLS-1$
50
// + ",'.magnolia/adminCentral/users/dialog.html');");
51
+ ",'.magnolia/dialogs/useredit.html');"); //$NON-NLS-1$
52
tree.addItemType(ItemType.USER);
53
54         TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request);
55         column0.setIsLabel(true);
56         column0.setHtmlEdit();
57         column0.setTitle(msgs.get("tree.users.name")); //$NON-NLS-1$
58
column0.setWidth(2);
59
60         TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request);
61         column1.setName("title"); //$NON-NLS-1$
62
column1.setHtmlEdit();
63         column1.setTitle(msgs.get("tree.users.fullname")); //$NON-NLS-1$
64
column1.setWidth(2);
65
66         TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request);
67         columnIcons.setCssClass(StringUtils.EMPTY);
68         columnIcons.setWidth(1);
69         columnIcons.setIsIcons(true);
70         columnIcons.setIconsActivation(true);
71
72         TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request);
73         column2.setName(MetaData.LAST_MODIFIED);
74         column2.setIsMeta(true);
75         column2.setDateFormat("yyyy-MM-dd, HH:mm"); //$NON-NLS-1$
76
column2.setTitle(msgs.get("tree.users.date")); //$NON-NLS-1$
77
column2.setWidth(2);
78
79         tree.addColumn(column0);
80
81         if (!browseMode) {
82             tree.addColumn(column1);
83             if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) {
84                 tree.addColumn(columnIcons);
85             }
86             tree.addColumn(column2);
87         }
88     }
89
90     /**
91      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
92      * boolean, javax.servlet.http.HttpServletRequest)
93      */

94     public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest JavaDoc request) {
95         Messages msgs = MessagesManager.getMessages();
96
97         ContextMenuItem menuOpen = new ContextMenuItem("edit");
98         menuOpen.setLabel(msgs.get("tree.users.menu.edit")); //$NON-NLS-1$
99
menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/pawn_glass_yellow.gif"); //$NON-NLS-1$
100
menuOpen.setOnclick("mgnlTreeMenuOpenDialog(" //$NON-NLS-1$
101
+ tree.getJavascriptTree()
102             + ",'.magnolia/dialogs/useredit.html');"); //$NON-NLS-1$
103
menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
104
+ tree.getJavascriptTree()
105             + ")"); //$NON-NLS-1$
106

107         ContextMenuItem menuNew = new ContextMenuItem("new");
108         menuNew.setLabel(msgs.get("tree.users.menu.new")); //$NON-NLS-1$
109
menuNew.setIcon(request.getContextPath() + "/.resources/icons/16/pawn_glass_yellow_add.gif"); //$NON-NLS-1$
110
menuNew.setOnclick(tree.getJavascriptTree() + ".createRootNode('" //$NON-NLS-1$
111
+ ItemType.USER.getSystemName()
112             + "');"); //$NON-NLS-1$
113

114         ContextMenuItem menuDelete = new ContextMenuItem("delete");
115         menuDelete.setLabel(msgs.get("tree.users.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

122         ContextMenuItem menuMove = new ContextMenuItem("move");
123         menuMove.setLabel(msgs.get("tree.users.menu.move")); //$NON-NLS-1$
124
menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
125
menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
126
menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
127
+ tree.getJavascriptTree()
128             + ")"); //$NON-NLS-1$
129

130         ContextMenuItem menuCopy = new ContextMenuItem("copy");
131         menuCopy.setLabel(msgs.get("tree.users.menu.copy")); //$NON-NLS-1$
132
menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
133
menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
134
menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
135
+ tree.getJavascriptTree()
136             + ")"); //$NON-NLS-1$
137

138         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
139         menuActivateExcl.setLabel(msgs.get("tree.users.menu.activate")); //$NON-NLS-1$
140
menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
141
menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
142
menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
143
+ tree.getJavascriptTree()
144             + ")"); //$NON-NLS-1$
145

146         ContextMenuItem menuDeActivate = new ContextMenuItem("deactivate");
147         menuDeActivate.setLabel(msgs.get("tree.users.menu.deactivate")); //$NON-NLS-1$
148
menuDeActivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
149
menuDeActivate.setOnclick(tree.getJavascriptTree() + ".deActivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
150
menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
151
+ tree.getJavascriptTree()
152             + ")"); //$NON-NLS-1$
153

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

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