View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.admininterface.trees;
35  
36  import info.magnolia.cms.core.ItemType;
37  import info.magnolia.cms.core.MetaData;
38  import info.magnolia.cms.gui.control.ContextMenuItem;
39  import info.magnolia.cms.gui.control.FunctionBarItem;
40  import info.magnolia.cms.gui.control.Tree;
41  import info.magnolia.cms.gui.control.TreeColumn;
42  import info.magnolia.cms.i18n.Messages;
43  import info.magnolia.cms.util.NodeNameComparator;
44  import info.magnolia.module.admininterface.AbstractTreeConfiguration;
45  
46  import javax.servlet.http.HttpServletRequest;
47  
48  /**
49   * @author Philipp Bracher
50   * @version $Revision: 48984 $ ($Author: ochytil $)
51   */
52  public class UsersTreeConfiguration extends AbstractTreeConfiguration {
53  
54      /**
55       * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareTree(info.magnolia.cms.gui.control.Tree,
56       * boolean, javax.servlet.http.HttpServletRequest)
57       */
58      public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest request) {
59          tree.setSortComparator(new NodeNameComparator());
60  
61          tree.setDrawShifter(true); // users can be in folders
62  
63          // context path is already added by Tree
64          tree.setIcon(ItemType.USER.getSystemName(), Tree.ICONDOCROOT + "pawn_glass_yellow.gif"); //$NON-NLS-1$
65          tree.setIconOndblclick("mgnlTreeMenuOpenDialog(" + tree.getJavascriptTree() //$NON-NLS-1$
66              // + ",'.magnolia/adminCentral/users/dialog.html');");
67              + ",'.magnolia/dialogs/useredit.html');"); //$NON-NLS-1$
68          tree.addItemType(ItemType.USER);
69          // TODO : MAGNOLIA-2372/MAGNOLIA-2407 - let's show the nt:folder nodes as well for now, they might have been created by public-user-registration for example
70          tree.addItemType("nt:folder", Tree.ICONDOCROOT + "folder_inactive.gif");
71          tree.addItemType(ItemType.NT_FOLDER, Tree.ICONDOCROOT + "folder.gif");
72  
73          final Messages msgs = getMessages();
74          TreeColumn column0 = TreeColumn.createLabelColumn(tree, msgs.get("tree.users.name"), !browseMode);
75          column0.setWidth(2);
76  
77          TreeColumn column1 = TreeColumn.createNodeDataColumn(tree, msgs.get("tree.users.fullname"), "title", !browseMode);
78          column1.setWidth(2);
79  
80          TreeColumn columnIcons = TreeColumn.createActivationColumn(tree, msgs.get("tree.users.status"));
81  
82          TreeColumn column2 = TreeColumn.createMetaDataColumn(tree, msgs.get("tree.users.date"), MetaData.LAST_MODIFIED, "yyyy-MM-dd, HH:mm");
83          column2.setWidth(2);
84  
85          tree.addColumn(column0);
86          if (!browseMode) {
87              tree.addColumn(column1);
88              if (isAdminInstance() || hasAnyActiveSubscriber()) {
89                  tree.addColumn(columnIcons);
90              }
91              tree.addColumn(column2);
92          }
93      }
94  
95      /**
96       * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
97       * boolean, javax.servlet.http.HttpServletRequest)
98       */
99      public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) {
100         final Messages msgs = getMessages();
101 
102         // might be usefull ;-)
103         ContextMenuItem menuNewFolder = new ContextMenuItem("newFolder");
104         menuNewFolder.setLabel(msgs.get("tree.users.menu.newFolder")); //$NON-NLS-1$
105         menuNewFolder.setIcon(request.getContextPath() + "/.resources/icons/16/folder_add.gif"); //$NON-NLS-1$
106         menuNewFolder.setOnclick(tree.getJavascriptTree() + ".createNode('"
107             + ItemType.NT_FOLDER + "');"); //$NON-NLS-1$
108         
109         menuNewFolder.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotItemType(" //$NON-NLS-1$
110             + tree.getJavascriptTree()
111             + ", '" + ItemType.USER.getSystemName() + "')"); //$NON-NLS-1$
112 
113 
114         ContextMenuItem menuOpen = new ContextMenuItem("edit");
115         menuOpen.setLabel(msgs.get("tree.users.menu.edit")); //$NON-NLS-1$
116         menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/pawn_glass_yellow.gif"); //$NON-NLS-1$
117         menuOpen.setOnclick("mgnlTreeMenuOpenDialog(" //$NON-NLS-1$
118             + tree.getJavascriptTree()
119             + ",'.magnolia/dialogs/useredit.html');"); //$NON-NLS-1$
120         menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedItemType(" //$NON-NLS-1$
121             + tree.getJavascriptTree()
122             + ",'mgnl:user')"); //$NON-NLS-1$
123 
124         ContextMenuItem menuNew = new ContextMenuItem("new");
125         menuNew.setLabel(msgs.get("tree.users.menu.new")); //$NON-NLS-1$
126         menuNew.setIcon(request.getContextPath() + "/.resources/icons/16/pawn_glass_yellow_add.gif"); //$NON-NLS-1$
127         menuNew.setOnclick(tree.getJavascriptTree() + ".createNode('" //$NON-NLS-1$
128             + ItemType.USER.getSystemName()
129             + "');"); //$NON-NLS-1$
130         menuNew.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotItemType(" //$NON-NLS-1$
131                 + tree.getJavascriptTree() + ","
132                 + "'" + ItemType.USER.getSystemName() + "'" 
133                 + ")"); //$NON-NLS-1$
134 
135         ContextMenuItem menuDelete = new ContextMenuItem("delete");
136         menuDelete.setLabel(msgs.get("tree.users.menu.delete")); //$NON-NLS-1$
137         menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); //$NON-NLS-1$
138         menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
139         menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
140             + tree.getJavascriptTree()
141             + ")"); //$NON-NLS-1$
142 
143         ContextMenuItem menuMove = new ContextMenuItem("move");
144         menuMove.setLabel(msgs.get("tree.users.menu.move")); //$NON-NLS-1$
145         menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
146         menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
147         menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
148             + tree.getJavascriptTree()
149             + ")"); //$NON-NLS-1$
150 
151         ContextMenuItem menuCopy = new ContextMenuItem("copy");
152         menuCopy.setLabel(msgs.get("tree.users.menu.copy")); //$NON-NLS-1$
153         menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
154         menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
155         menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
156             + tree.getJavascriptTree()
157             + ")"); //$NON-NLS-1$
158 
159         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
160         menuActivateExcl.setLabel(msgs.get("tree.users.menu.activate")); //$NON-NLS-1$
161         menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
162         menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
163         menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
164             + tree.getJavascriptTree()
165             + ")"); //$NON-NLS-1$
166 
167         ContextMenuItem menuDeactivate = new ContextMenuItem("deactivate");
168         menuDeactivate.setLabel(msgs.get("tree.users.menu.deactivate")); //$NON-NLS-1$
169         menuDeactivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
170         menuDeactivate.setOnclick(tree.getJavascriptTree() + ".deactivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
171         menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
172             + tree.getJavascriptTree()
173             + ")"); //$NON-NLS-1$
174 
175         if (!hasAnyActiveSubscriber()) {
176             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
177             menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
178         }
179 
180         if (!browseMode) {
181             tree.addMenuItem(menuOpen);
182             if(!tree.getRootPath().equals("/system")){
183                 tree.addMenuItem(menuNew);
184                 tree.addMenuItem(menuNewFolder);
185                 tree.addMenuItem(null); // line
186                 tree.addMenuItem(menuDelete);
187             }
188             tree.addMenuItem(null); // line
189             tree.addMenuItem(menuActivateExcl);
190             tree.addMenuItem(menuDeactivate);
191         }
192         else {
193             tree.addMenuItem(ContextMenuItem.getRefreshMenuItem(tree, msgs, request));
194         }
195     }
196 
197     /**
198      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareFunctionBar(info.magnolia.cms.gui.control.Tree,
199      * boolean, javax.servlet.http.HttpServletRequest)
200      */
201     public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) {
202         tree.addFunctionBarItemFromContextMenu("edit");
203         if(!tree.getRootPath().equals("/system")){
204             tree.addFunctionBarItemFromContextMenu("new");
205             tree.addFunctionBarItemFromContextMenu("newFolder");
206         }
207         tree.addFunctionBarItem(null);
208         tree.addFunctionBarItemFromContextMenu("activate");
209         tree.addFunctionBarItemFromContextMenu("deactivate");
210         tree.addFunctionBarItem(null);
211 
212         tree.addFunctionBarItem(FunctionBarItem.getRefreshFunctionBarItem(tree, getMessages(), request));
213     }
214 
215 }