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.Select;
41  import info.magnolia.cms.gui.control.Tree;
42  import info.magnolia.cms.gui.control.TreeColumn;
43  import info.magnolia.cms.i18n.Messages;
44  import info.magnolia.module.admininterface.AbstractTreeConfiguration;
45  
46  import javax.jcr.PropertyType;
47  import javax.servlet.http.HttpServletRequest;
48  
49  import org.apache.commons.lang.StringUtils;
50  
51  
52  /**
53   * @author Philipp Bracher
54   * @version $Revision: 32667 $ ($Author: gjoseph $)
55   */
56  public class ConfigTreeConfiguration extends AbstractTreeConfiguration {
57  
58      /**
59       * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareTree(info.magnolia.cms.gui.control.Tree,
60       * boolean, javax.servlet.http.HttpServletRequest)
61       */
62      public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest request) {
63          final Messages msgs = getMessages();
64  
65          tree.setIconPage(Tree.ICONDOCROOT + "folder_cubes.gif"); //$NON-NLS-1$
66  
67          tree.addItemType(ItemType.CONTENT.getSystemName());
68          tree.addItemType(ItemType.CONTENTNODE.getSystemName());
69          tree.addItemType(Tree.ITEM_TYPE_NODEDATA);
70          TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request);
71          column0.setHtmlEdit();
72          column0.setIsLabel(true);
73          column0.setWidth(3);
74  
75          TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request);
76          column1.setName(StringUtils.EMPTY);
77          column1.setTitle(msgs.get("tree.config.value")); //$NON-NLS-1$
78          column1.setIsNodeDataValue(true);
79          column1.setWidth(3);
80          column1.setHtmlEdit();
81  
82          TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request);
83          column2.setName(StringUtils.EMPTY);
84          column2.setTitle(msgs.get("tree.config.type")); //$NON-NLS-1$
85          column2.setIsNodeDataType(true);
86          column2.setWidth(1);
87          Select typeSelect = new Select();
88          typeSelect.setName(tree.getJavascriptTree() + TreeColumn.EDIT_NAMEADDITION);
89          typeSelect.setSaveInfo(false);
90          typeSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT);
91          typeSelect.setEvent(
92              "onblur", tree.getJavascriptTree() + ".saveNodeData(this.value,this.options[this.selectedIndex].text)"); //$NON-NLS-1$
93          typeSelect.setOptions(PropertyType.TYPENAME_STRING, Integer.toString(PropertyType.STRING));
94          typeSelect.setOptions(PropertyType.TYPENAME_BOOLEAN, Integer.toString(PropertyType.BOOLEAN));
95          typeSelect.setOptions(PropertyType.TYPENAME_LONG, Integer.toString(PropertyType.LONG));
96          typeSelect.setOptions(PropertyType.TYPENAME_DOUBLE, Integer.toString(PropertyType.DOUBLE));
97          // todo: typeSelect.setOptions(PropertyType.TYPENAME_DATE,Integer.toString(PropertyType.DATE));
98          column2.setHtmlEdit(typeSelect.getHtml());
99  
100         TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request);
101         columnIcons.setCssClass(StringUtils.EMPTY);
102         columnIcons.setTitle(msgs.get("tree.config.status")); //$NON-NLS-1$
103         columnIcons.setWidth(1);
104         columnIcons.setIsIcons(true);
105         columnIcons.setIconsActivation(true);
106         columnIcons.setIconsPermission(true);
107 
108         TreeColumn column4 = new TreeColumn(tree.getJavascriptTree(), request);
109         column4.setName(MetaData.LAST_MODIFIED);
110         column4.setIsMeta(true);
111         column4.setDateFormat("yy-MM-dd, HH:mm"); //$NON-NLS-1$
112         column4.setWidth(2);
113         column4.setTitle(msgs.get("tree.config.date")); //$NON-NLS-1$
114 
115         tree.addColumn(column0);
116 
117         if (!browseMode) {
118             tree.addColumn(column1);
119             tree.addColumn(column2);
120 
121             if (isAdminInstance() || hasAnyActiveSubscriber()) {
122                 tree.addColumn(columnIcons);
123             }
124             tree.addColumn(column4);
125         }
126     }
127 
128     /**
129      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
130      * boolean, javax.servlet.http.HttpServletRequest)
131      */
132     public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) {
133         final Messages msgs = getMessages();
134 
135         ContextMenuItem menuNewPage = new ContextMenuItem("newFolder");
136         menuNewPage.setLabel(msgs.get("tree.config.menu.newFolder")); //$NON-NLS-1$
137         menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/folder_cubes.gif"); //$NON-NLS-1$
138         menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); //$NON-NLS-1$ //$NON-NLS-2$
139         menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
140             + tree.getJavascriptTree()
141             + ")"); //$NON-NLS-1$
142         menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotContentNode(" //$NON-NLS-1$
143             + tree.getJavascriptTree()
144             + ")"); //$NON-NLS-1$
145 
146         ContextMenuItem menuNewContentNode = new ContextMenuItem("newNode");
147         menuNewContentNode.setLabel(msgs.get("tree.config.menu.newNode")); //$NON-NLS-1$
148         menuNewContentNode.setIcon(request.getContextPath() + "/.resources/icons/16/cubes.gif"); //$NON-NLS-1$
149         menuNewContentNode.setOnclick(tree.getJavascriptTree() + ".createNode('" //$NON-NLS-1$
150             + ItemType.CONTENTNODE.getSystemName()
151             + "');"); //$NON-NLS-1$
152         menuNewContentNode.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
153             + tree.getJavascriptTree()
154             + ")"); //$NON-NLS-1$
155 
156         ContextMenuItem menuNewNodeData = new ContextMenuItem("newData");
157         menuNewNodeData.setLabel(msgs.get("tree.config.menu.newNodeData")); //$NON-NLS-1$
158         menuNewNodeData.setIcon(request.getContextPath() + "/.resources/icons/16/cube_green.gif"); //$NON-NLS-1$
159         menuNewNodeData.setOnclick(tree.getJavascriptTree() + ".createNode('" + Tree.ITEM_TYPE_NODEDATA + "');"); //$NON-NLS-1$ //$NON-NLS-2$
160         menuNewNodeData.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
161             + tree.getJavascriptTree()
162             + ")"); //$NON-NLS-1$
163 
164         ContextMenuItem menuDelete = new ContextMenuItem("delete");
165         menuDelete.setLabel(msgs.get("tree.config.menu.delete")); //$NON-NLS-1$
166         menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); //$NON-NLS-1$
167         menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); //$NON-NLS-1$
168         menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
169             + tree.getJavascriptTree()
170             + ")"); //$NON-NLS-1$
171 
172         ContextMenuItem menuCopy = new ContextMenuItem("copy");
173         menuCopy.setLabel(msgs.get("tree.config.menu.copy")); //$NON-NLS-1$
174         menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
175         menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
176             + tree.getJavascriptTree()
177             + ")"); //$NON-NLS-1$
178         menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
179             + tree.getJavascriptTree()
180             + ")"); //$NON-NLS-1$
181         menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
182 
183         ContextMenuItem menuCut = new ContextMenuItem("move");
184         menuCut.setLabel(msgs.get("tree.config.menu.move")); //$NON-NLS-1$
185         menuCut.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
186         menuCut
187             .addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
188         menuCut.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
189             + tree.getJavascriptTree()
190             + ")"); //$NON-NLS-1$
191         menuCut.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
192 
193         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
194         menuActivateExcl.setLabel(msgs.get("tree.config.menu.activate")); //$NON-NLS-1$
195         menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
196         menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
197         menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
198             + tree.getJavascriptTree()
199             + ")"); //$NON-NLS-1$
200         menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
201             + tree.getJavascriptTree()
202             + ")"); //$NON-NLS-1$
203 
204         ContextMenuItem menuActivateIncl = new ContextMenuItem("activateInclSubs");
205         menuActivateIncl.setLabel(msgs.get("tree.config.menu.activateInclSubs")); //$NON-NLS-1$
206         menuActivateIncl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green_double.gif"); //$NON-NLS-1$
207         menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); //$NON-NLS-1$ //$NON-NLS-2$
208         menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
209             + tree.getJavascriptTree()
210             + ")"); //$NON-NLS-1$
211         menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
212             + tree.getJavascriptTree()
213             + ")"); //$NON-NLS-1$
214 
215         ContextMenuItem menuDeactivate = new ContextMenuItem("deactivate");
216         menuDeactivate.setLabel(msgs.get("tree.config.menu.deactivate")); //$NON-NLS-1$
217         menuDeactivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
218         menuDeactivate.setOnclick(tree.getJavascriptTree() + ".deactivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
219         menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
220             + tree.getJavascriptTree()
221             + ")"); //$NON-NLS-1$
222         menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
223             + tree.getJavascriptTree()
224             + ")"); //$NON-NLS-1$
225 
226         ContextMenuItem menuExport = new ContextMenuItem("export");
227         menuExport.setLabel(msgs.get("tree.menu.export")); //$NON-NLS-1$
228         menuExport.setIcon(request.getContextPath() + "/.resources/icons/16/export1.gif"); //$NON-NLS-1$
229         menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); //$NON-NLS-1$
230         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
231             + tree.getJavascriptTree()
232             + ")"); //$NON-NLS-1$
233 
234         ContextMenuItem menuImport = new ContextMenuItem("import");
235         menuImport.setLabel(msgs.get("tree.menu.import")); //$NON-NLS-1$
236         menuImport.setIcon(request.getContextPath() + "/.resources/icons/16/import2.gif"); //$NON-NLS-1$
237         menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); //$NON-NLS-1$
238         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" //$NON-NLS-1$
239             + tree.getJavascriptTree()
240             + ")"); //$NON-NLS-1$
241 
242         // is it possible to activate?
243         if (!hasAnyActiveSubscriber()) {
244             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
245             menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
246             menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
247         }
248 
249         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
250             + tree.getJavascriptTree()
251             + ")"); //$NON-NLS-1$
252 
253         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
254             + tree.getJavascriptTree()
255             + ")"); //$NON-NLS-1$
256 
257         if (!browseMode) {
258             tree.addMenuItem(menuNewPage);
259             tree.addMenuItem(menuNewContentNode);
260             tree.addMenuItem(menuNewNodeData);
261 
262             tree.addSeparator();
263             tree.addMenuItem(menuDelete);
264 
265             tree.addSeparator();
266             tree.addMenuItem(menuCut);
267             tree.addMenuItem(menuCopy);
268 
269             tree.addSeparator();
270             tree.addMenuItem(menuActivateExcl);
271             tree.addMenuItem(menuActivateIncl);
272             tree.addMenuItem(menuDeactivate);
273 
274             tree.addSeparator();
275             tree.addMenuItem(menuExport);
276             tree.addMenuItem(menuImport);
277         }
278         else {
279             tree.addMenuItem(ContextMenuItem.getRefreshMenuItem(tree, msgs, request));
280         }
281 
282     }
283 
284     /**
285      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareFunctionBar(info.magnolia.cms.gui.control.Tree,
286      * boolean, javax.servlet.http.HttpServletRequest)
287      */
288     public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) {
289         final Messages msgs = getMessages();
290         tree.addFunctionBarItemFromContextMenu("newFolder");
291         tree.addFunctionBarItemFromContextMenu("newNode");
292         tree.addFunctionBarItemFromContextMenu("newData");
293         // null is separator :)
294         tree.addFunctionBarItem(null);
295         tree.addFunctionBarItemFromContextMenu("activate");
296         tree.addFunctionBarItemFromContextMenu("deactivate");
297         // null is separator :)
298         tree.addFunctionBarItem(null);
299 
300         tree.addFunctionBarItem(FunctionBarItem.getRefreshFunctionBarItem(tree, msgs, request));
301     }
302 
303 }