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.module.admininterface.AbstractTreeConfiguration;
44  
45  import javax.servlet.http.HttpServletRequest;
46  
47  
48  /**
49   * @author Philipp Bracher
50   * @version $Revision: 41137 $ ($Author: gjoseph $)
51   */
52  public class WebsiteTreeConfiguration 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(final Tree tree, boolean browseMode, HttpServletRequest request) {
59          final Messages msgs = getMessages();
60  
61          tree.setIconOndblclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");");
62  
63          tree.addItemType(ItemType.CONTENT);
64          tree.addIcon(ItemType.DELETED_NODE_MIXIN, "/.resources/icons/16/document_deleted.gif");
65  
66          TreeColumn column0 = TreeColumn.createLabelColumn(tree, msgs.get("tree.web.page"), true);
67          column0.setWidth(3);
68  
69          TreeColumn columnIcons = TreeColumn.createActivationColumn(tree, msgs.get("tree.web.status"));
70          columnIcons.setIconsPermission(true);
71  
72          TreeColumn column1 = TreeColumn.createNodeDataColumn(tree, msgs.get("tree.web.title"), "title", true);
73          column1.setWidth(2);
74  
75          TreeColumn column2 = new TemplateColumn(tree.getJavascriptTree(), request);
76          column2.setName(MetaData.TEMPLATE);
77          column2.setIsMeta(true);
78          column2.setWidth(2);
79          column2.setTitle(msgs.get("tree.web.template")); //$NON-NLS-1$
80          // must render this column specially
81          column2.setHtmlRenderer(new TemplateTreeColumnHtmlRenderer());
82  
83          // todo: key/value -> column2.addKeyValue("sampleBasic","Samples: Basic Template");
84          // todo: preselection (set on createPage)
85  
86          TreeColumn column3 = TreeColumn.createMetaDataColumn(tree, msgs.get("tree.web.date"), MetaData.LAST_MODIFIED, "yy-MM-dd, HH:mm");
87          column3.setWidth(2);
88  
89          tree.addColumn(column0);
90  
91          if (!browseMode) {
92              tree.addColumn(column1);
93              if (isAdminInstance() || hasAnyActiveSubscriber()) {
94                  tree.addColumn(columnIcons);
95              }
96              tree.addColumn(column2);
97              tree.addColumn(column3);
98          }
99  
100     }
101 
102     /**
103      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareContextMenu(info.magnolia.cms.gui.control.Tree,
104      * boolean, javax.servlet.http.HttpServletRequest)
105      */
106     public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) {
107         final Messages msgs = getMessages();
108         ContextMenuItem menuOpen = new ContextMenuItem("open");
109         menuOpen.setLabel(msgs.get("tree.web.menu.open")); //$NON-NLS-1$
110         menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth.gif"); //$NON-NLS-1$
111         menuOpen.setOnclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); //$NON-NLS-1$ //$NON-NLS-2$
112         menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
113                 + tree.getJavascriptTree()
114                 + ")"); //$NON-NLS-1$
115 
116         ContextMenuItem menuNewPage = new ContextMenuItem("new");
117         menuNewPage.setLabel(msgs.get("tree.web.menu.new")); //$NON-NLS-1$
118         menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth_add.gif"); //$NON-NLS-1$
119 
120         menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); //$NON-NLS-1$ //$NON-NLS-2$
121         menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
122                 + tree.getJavascriptTree()
123                 + ")"); //$NON-NLS-1$
124         menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
125 
126         ContextMenuItem menuDelete = new ContextMenuItem("delete");
127         menuDelete.setLabel(msgs.get("tree.web.menu.delete")); //$NON-NLS-1$
128         menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); //$NON-NLS-1$
129         menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode("+(!isEnableDeleteConfirmation()) +");"); //$NON-NLS-1$
130         menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
131                 + tree.getJavascriptTree()
132                 + ")"); //$NON-NLS-1$
133         menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
134                 + tree.getJavascriptTree()
135                 + ")"); //$NON-NLS-1$
136         menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
137 
138         ContextMenuItem menuMove = new ContextMenuItem("move");
139         menuMove.setLabel(msgs.get("tree.web.menu.move")); //$NON-NLS-1$
140         menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); //$NON-NLS-1$
141         menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); //$NON-NLS-1$
142         menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
143                 + tree.getJavascriptTree()
144                 + ")"); //$NON-NLS-1$
145         menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
146                 + tree.getJavascriptTree()
147                 + ")"); //$NON-NLS-1$
148         menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
149 
150         ContextMenuItem menuCopy = new ContextMenuItem("copy");
151         menuCopy.setLabel(msgs.get("tree.web.menu.copy")); //$NON-NLS-1$
152         menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); //$NON-NLS-1$
153         menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); //$NON-NLS-1$
154         menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
155                 + tree.getJavascriptTree()
156                 + ")"); //$NON-NLS-1$
157         menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
158 
159         ContextMenuItem menuVersions = new ContextMenuItem("versions");
160         menuVersions.setLabel(msgs.get("versions")); //$NON-NLS-1$
161         menuVersions.setIcon(request.getContextPath() + "/.resources/icons/16/elements1.gif"); //$NON-NLS-1$
162         menuVersions.setOnclick("mgnl.admininterface.WebsiteTree.showVersions(" + tree.getJavascriptTree() + ");"); //$NON-NLS-1$ //$NON-NLS-2$
163         menuVersions.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
164                 + tree.getJavascriptTree()
165                 + ")"); //$NON-NLS-1$
166 
167         ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
168         menuActivateExcl.setLabel(msgs.get("tree.web.menu.activate")); //$NON-NLS-1$
169         menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); //$NON-NLS-1$
170 
171         menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); //$NON-NLS-1$ //$NON-NLS-2$
172         menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
173                 + tree.getJavascriptTree()
174                 + ")"); //$NON-NLS-1$
175         menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
176                 + tree.getJavascriptTree()
177                 + ")"); //$NON-NLS-1$
178 
179         ContextMenuItem menuActivateIncl = new ContextMenuItem("activateInclSubs");
180         menuActivateIncl.setLabel(msgs.get("tree.web.menu.activateInclSubs")); //$NON-NLS-1$
181         menuActivateIncl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green_double.gif"); //$NON-NLS-1$
182         menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); //$NON-NLS-1$ //$NON-NLS-2$
183         menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
184                 + tree.getJavascriptTree()
185                 + ")"); //$NON-NLS-1$
186         menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
187                 + tree.getJavascriptTree()
188                 + ")"); //$NON-NLS-1$
189         menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
190 
191         ContextMenuItem menuDeactivate = new ContextMenuItem("deactivate");
192         menuDeactivate.setLabel(msgs.get("tree.web.menu.deactivate")); //$NON-NLS-1$
193         menuDeactivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); //$NON-NLS-1$
194         menuDeactivate.setOnclick(tree.getJavascriptTree() + ".deactivateNode(" + Tree.ACTION_DEACTIVATE + ");"); //$NON-NLS-1$ //$NON-NLS-2$
195         menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" //$NON-NLS-1$
196                 + tree.getJavascriptTree()
197                 + ")"); //$NON-NLS-1$
198         menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
199                 + tree.getJavascriptTree()
200                 + ")"); //$NON-NLS-1$
201         menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
202 
203         ContextMenuItem menuExport = new ContextMenuItem("export");
204         menuExport.setLabel(msgs.get("tree.menu.export")); //$NON-NLS-1$
205         menuExport.setIcon(request.getContextPath() + "/.resources/icons/16/export1.gif"); //$NON-NLS-1$
206         menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); //$NON-NLS-1$
207 
208         ContextMenuItem menuImport = new ContextMenuItem("import");
209         menuImport.setLabel(msgs.get("tree.menu.import")); //$NON-NLS-1$
210         menuImport.setIcon(request.getContextPath() + "/.resources/icons/16/import2.gif"); //$NON-NLS-1$
211         menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); //$NON-NLS-1$
212 
213         // is there a subscriber?
214         if (!hasAnyActiveSubscriber()) {
215             menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
216             menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
217             menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); //$NON-NLS-1$
218         }
219 
220         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
221                 + tree.getJavascriptTree()
222                 + ")"); //$NON-NLS-1$
223         menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
224 
225         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" //$NON-NLS-1$
226                 + tree.getJavascriptTree()
227                 + ")"); //$NON-NLS-1$
228         menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionNotDeleted(" + tree.getJavascriptTree() + ")");
229 
230         if (!browseMode) {
231             tree.addMenuItem(menuOpen);
232             tree.addMenuItem(menuNewPage);
233 
234             tree.addSeparator();
235             tree.addMenuItem(menuDelete);
236 
237             tree.addSeparator();
238             tree.addMenuItem(menuMove);
239             tree.addMenuItem(menuCopy);
240 
241             tree.addSeparator();
242             tree.addMenuItem(menuVersions);
243 
244             tree.addSeparator();
245             tree.addMenuItem(menuActivateExcl);
246             tree.addMenuItem(menuActivateIncl);
247             tree.addMenuItem(menuDeactivate);
248 
249             tree.addSeparator();
250             tree.addMenuItem(menuExport);
251             tree.addMenuItem(menuImport);
252         }
253         else {
254             tree.addMenuItem(ContextMenuItem.getRefreshMenuItem(tree, msgs, request));
255         }
256 
257     }
258 
259     /**
260      * @see info.magnolia.module.admininterface.AdminTreeConfiguration#prepareFunctionBar(info.magnolia.cms.gui.control.Tree,
261      * boolean, javax.servlet.http.HttpServletRequest)
262      */
263     public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) {
264         tree.addFunctionBarItemFromContextMenu("open");
265         tree.addFunctionBarItemFromContextMenu("new");
266         tree.addFunctionBarItem(null);
267         tree.addFunctionBarItemFromContextMenu("activate");
268         tree.addFunctionBarItemFromContextMenu("deactivate");
269         tree.addFunctionBarItem(null);
270 
271         tree.addFunctionBarItem(FunctionBarItem.getRefreshFunctionBarItem(tree, getMessages(), request));
272 
273         tree.getFunctionBar().setSearchable(true);
274         tree.getFunctionBar().setOnSearchFunction("mgnl.admininterface.WebsiteTree.search");
275     }
276 }