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