View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 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: 32667 $ ($Author: gjoseph $)
51   */
52  public class GroupsTreeConfiguration 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(false);
62  
63          tree.setIcon(ItemType.GROUP.getSystemName(), Tree.ICONDOCROOT + "group.gif"); //$NON-NLS-1$
64          tree.setIconOndblclick("mgnlTreeMenuOpenDialog(" //$NON-NLS-1$
65              + tree.getJavascriptTree()
66              + ",'.magnolia/dialogs/groupedit.html');"); //$NON-NLS-1$
67          tree.addItemType(ItemType.GROUP);
68  
69          final Messages msgs = getMessages();
70          TreeColumn column0 = TreeColumn.createLabelColumn(tree, msgs.get("tree.groups.name"), !browseMode);
71          column0.setWidth(2);
72  
73          TreeColumn column1 = TreeColumn.createNodeDataColumn(tree, msgs.get("tree.groups.fullname"), "title", !browseMode);
74          column1.setWidth(2);
75  
76          TreeColumn columnIcons = TreeColumn.createActivationColumn(tree, msgs.get("tree.groups.status"));        
77  
78          TreeColumn column2 = TreeColumn.createMetaDataColumn(tree, msgs.get("tree.groups.date"), MetaData.LAST_MODIFIED, "yyyy-MM-dd, HH:mm");
79          column2.setWidth(2);
80  
81          tree.addColumn(column0);
82          if (!browseMode) {
83              tree.addColumn(column1);
84              if (isAdminInstance() || hasAnyActiveSubscriber()) {
85                  tree.addColumn(columnIcons);
86              }
87              tree.addColumn(column2);
88          }
89      }
90  
91      /**
92       * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
93       * boolean, javax.servlet.http.HttpServletRequest)
94       */
95      public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) {
96          final Messages msgs = getMessages();
97  
98          ContextMenuItem menuOpen = new ContextMenuItem("edit");
99          menuOpen.setLabel(msgs.get("tree.groups.menu.edit")); //$NON-NLS-1$
100         menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/group.gif"); //$NON-NLS-1$
101         menuOpen.setOnclick("mgnlTreeMenuOpenDialog(" //$NON-NLS-1$
102             + tree.getJavascriptTree()
103             + ",'.magnolia/dialogs/groupedit.html');"); //$NON-NLS-1$
104         menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
105             + tree.getJavascriptTree()
106             + ")"); //$NON-NLS-1$
107 
108         ContextMenuItem menuNewPage = new ContextMenuItem("new");
109         menuNewPage.setLabel(msgs.get("tree.groups.menu.new")); //$NON-NLS-1$
110         menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/group_add.gif"); //$NON-NLS-1$
111         menuNewPage.setOnclick(tree.getJavascriptTree() + ".createRootNode('" //$NON-NLS-1$
112             + ItemType.GROUP.getSystemName()
113             + "');"); //$NON-NLS-1$
114 
115         ContextMenuItem menuDelete = new ContextMenuItem("delete");
116         menuDelete.setLabel(msgs.get("tree.groups.menu.delete")); //$NON-NLS-1$
117         menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); //$NON-NLS-1$
118         menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
119         menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
120             + tree.getJavascriptTree()
121             + ")"); //$NON-NLS-1$
122 
123         ContextMenuItem menuMove = new ContextMenuItem("move");
124         menuMove.setLabel(msgs.get("tree.groups.menu.move")); //$NON-NLS-1$
125         menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
126         menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
127         menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
128             + tree.getJavascriptTree()
129             + ")"); //$NON-NLS-1$
130 
131         ContextMenuItem menuCopy = new ContextMenuItem("copy");
132         menuCopy.setLabel(msgs.get("tree.groups.menu.copy")); //$NON-NLS-1$
133         menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
134         menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
135         menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
136             + tree.getJavascriptTree()
137             + ")"); //$NON-NLS-1$
138 
139         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
140         menuActivateExcl.setLabel(msgs.get("tree.groups.menu.activate")); //$NON-NLS-1$
141         menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
142         menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
143         menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
144             + tree.getJavascriptTree()
145             + ")"); //$NON-NLS-1$
146 
147         ContextMenuItem menuDeactivate = new ContextMenuItem("deactivate");
148         menuDeactivate.setLabel(msgs.get("tree.groups.menu.deactivate")); //$NON-NLS-1$
149         menuDeactivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
150         menuDeactivate.setOnclick(tree.getJavascriptTree() + ".deactivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
151         menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
152             + tree.getJavascriptTree()
153             + ")"); //$NON-NLS-1$
154 
155         if (!hasAnyActiveSubscriber()) {
156             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
157             menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
158         }
159 
160         if (!browseMode) {
161             tree.addMenuItem(menuOpen);
162             tree.addMenuItem(menuNewPage);
163 
164             tree.addMenuItem(null); // line
165             tree.addMenuItem(menuDelete);
166 
167             tree.addMenuItem(null); // line
168             tree.addMenuItem(menuActivateExcl);
169             tree.addMenuItem(menuDeactivate);
170         }
171         else {
172             tree.addMenuItem(ContextMenuItem.getRefreshMenuItem(tree, msgs, request));            
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 request) {
181         tree.addFunctionBarItemFromContextMenu("edit");
182         tree.addFunctionBarItemFromContextMenu("new");
183         tree.addFunctionBarItem(null);
184         tree.addFunctionBarItemFromContextMenu("activate");
185         tree.addFunctionBarItemFromContextMenu("deactivate");
186         tree.addFunctionBarItem(null);
187         tree.addFunctionBarItem(FunctionBarItem.getRefreshFunctionBarItem(tree, getMessages(), request));
188     }
189 
190 }