1 13 package info.magnolia.module.admininterface.trees; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 import info.magnolia.cms.beans.config.Server; 17 import info.magnolia.cms.beans.config.Subscriber; 18 import info.magnolia.cms.beans.config.Template; 19 import info.magnolia.cms.beans.config.TemplateManager; 20 import info.magnolia.cms.core.ItemType; 21 import info.magnolia.cms.core.MetaData; 22 import info.magnolia.cms.gui.control.ContextMenu; 23 import info.magnolia.cms.gui.control.ContextMenuItem; 24 import info.magnolia.cms.gui.control.FunctionBarItem; 25 import info.magnolia.cms.gui.control.Select; 26 import info.magnolia.cms.gui.control.Tree; 27 import info.magnolia.cms.gui.control.TreeColumn; 28 import info.magnolia.cms.i18n.Messages; 29 import info.magnolia.cms.i18n.MessagesManager; 30 import info.magnolia.cms.i18n.MessagesUtil; 31 import info.magnolia.cms.i18n.TemplateMessagesUtil; 32 import info.magnolia.context.MgnlContext; 33 import info.magnolia.module.admininterface.AdminTreeConfiguration; 34 35 import java.util.Iterator ; 36 37 import javax.servlet.http.HttpServletRequest ; 38 39 import org.apache.commons.lang.StringUtils; 40 41 42 46 public class WebsiteTreeConfiguration implements AdminTreeConfiguration { 47 48 52 public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest request) { 53 Messages msgs = MessagesManager.getMessages(); 54 55 tree.setIconOndblclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); 57 tree.addItemType(ItemType.CONTENT); 58 59 TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request); 60 column0.setIsLabel(true); 61 column0.setTitle(msgs.get("tree.web.page")); 62 column0.setWidth(3); 63 column0.setHtmlEdit(); 64 65 TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request); 66 columnIcons.setCssClass(StringUtils.EMPTY); 67 columnIcons.setWidth(1); 68 columnIcons.setIsIcons(true); 69 columnIcons.setIconsActivation(true); 70 columnIcons.setIconsPermission(true); 71 72 TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request); 73 column1.setName("title"); column1.setTitle(msgs.get("tree.web.title")); column1.setWidth(2); 76 column1.setHtmlEdit(); 77 78 TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request); 79 column2.setName(MetaData.TEMPLATE); 80 column2.setIsMeta(true); 81 column2.setWidth(2); 82 column2.setTitle(msgs.get("tree.web.template")); column2.setHtmlRenderer(new TemplateTreeColumnHtmlRenderer()); 85 86 Select templateSelect = new Select(); 87 templateSelect.setName(tree.getJavascriptTree() + TreeColumn.EDIT_NAMEADDITION); 88 templateSelect.setSaveInfo(false); 89 templateSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT); 90 91 templateSelect.setEvent("onblur", tree.getJavascriptTree() + ".saveNodeData(this.value,this.options[this.selectedIndex].text)"); templateSelect.setEvent("onchange", tree.getJavascriptTree() + ".saveNodeData(this.value,this.options[this.selectedIndex].text)"); 99 Iterator templates = TemplateManager.getInstance().getAvailableTemplates( 100 MgnlContext.getAccessManager(ContentRepository.CONFIG)); 101 Messages templateMsgs = TemplateMessagesUtil.getMessages(); 102 while (templates.hasNext()) { 103 Template template = (Template) templates.next(); 104 String title = template.getTitle(); 105 title = templateMsgs.getWithDefault(title, title); 106 title = MessagesUtil.javaScriptString(title); 107 templateSelect.setOptions(title, template.getName()); 108 } 109 column2.setHtmlEdit(templateSelect.getHtml()); 110 111 TreeColumn column3 = new TreeColumn(tree.getJavascriptTree(), request); 114 column3.setName(MetaData.LAST_MODIFIED); 115 column3.setIsMeta(true); 117 column3.setDateFormat("yy-MM-dd, HH:mm"); column3.setWidth(2); 119 column3.setTitle(msgs.get("tree.web.date")); 121 tree.addColumn(column0); 122 123 if (!browseMode) { 124 tree.addColumn(column1); 125 if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) { 126 tree.addColumn(columnIcons); 127 } 128 tree.addColumn(column2); 129 tree.addColumn(column3); 130 } 131 132 } 133 134 138 public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) { 139 Messages msgs = MessagesManager.getMessages(); 140 ContextMenuItem menuOpen = new ContextMenuItem("open"); 141 menuOpen.setLabel(msgs.get("tree.web.menu.open")); menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth.gif"); menuOpen.setOnclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 146 + ")"); 148 ContextMenuItem menuNewPage = new ContextMenuItem("new"); 149 menuNewPage.setLabel(msgs.get("tree.web.menu.new")); menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/document_plain_earth_add.gif"); 152 menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 155 + ")"); 157 ContextMenuItem menuDelete = new ContextMenuItem("delete"); 158 menuDelete.setLabel(msgs.get("tree.web.menu.delete")); menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 163 + ")"); menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 166 + ")"); 168 ContextMenuItem menuMove = new ContextMenuItem("move"); 169 menuMove.setLabel(msgs.get("tree.web.menu.move")); menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 174 + ")"); menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 177 + ")"); 179 ContextMenuItem menuCopy = new ContextMenuItem("copy"); 180 menuCopy.setLabel(msgs.get("tree.web.menu.copy")); menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 185 + ")"); 187 ContextMenuItem menuVersions = new ContextMenuItem("versions"); 188 menuVersions.setLabel(msgs.get("versions")); menuVersions.setIcon(request.getContextPath() + "/.resources/icons/16/elements1.gif"); menuVersions.setOnclick("mgnl.admininterface.WebsiteTree.showVersions(" + tree.getJavascriptTree() + ");"); menuVersions.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 193 + ")"); 195 ContextMenuItem menuActivateExcl = new ContextMenuItem("activate"); 196 menuActivateExcl.setLabel(msgs.get("tree.web.menu.activate")); menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); 199 menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 202 + ")"); menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 205 + ")"); 207 ContextMenuItem menuActivateIncl = new ContextMenuItem("activateInclSubs"); 208 menuActivateIncl.setLabel(msgs.get("tree.web.menu.activateInclSubs")); menuActivateIncl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green_double.gif"); menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 213 + ")"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 216 + ")"); 218 ContextMenuItem menuDeActivate = new ContextMenuItem("deactivate"); 219 menuDeActivate.setLabel(msgs.get("tree.web.menu.deactivate")); menuDeActivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif"); menuDeActivate.setOnclick(tree.getJavascriptTree() + ".deActivateNode(" + Tree.ACTION_DEACTIVATE + ");"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 224 + ")"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 227 + ")"); 229 ContextMenuItem menuExport = new ContextMenuItem("export"); 230 menuExport.setLabel(msgs.get("tree.menu.export")); menuExport.setIcon(request.getContextPath() + "/.resources/icons/16/export1.gif"); menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); 234 ContextMenuItem menuImport = new ContextMenuItem("import"); 235 menuImport.setLabel(msgs.get("tree.menu.import")); menuImport.setIcon(request.getContextPath() + "/.resources/icons/16/import2.gif"); menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); 239 if (!Subscriber.isSubscribersEnabled()) { 241 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); } 245 246 menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 248 + ")"); 250 menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 252 + ")"); 254 if (!browseMode) { 255 tree.addMenuItem(menuOpen); 256 tree.addMenuItem(menuNewPage); 257 258 tree.addSeparator(); 259 tree.addMenuItem(menuDelete); 260 261 tree.addSeparator(); 262 tree.addMenuItem(menuMove); 263 tree.addMenuItem(menuCopy); 264 265 tree.addSeparator(); 266 tree.addMenuItem(menuVersions); 267 268 tree.addSeparator(); 269 tree.addMenuItem(menuActivateExcl); 270 tree.addMenuItem(menuActivateIncl); 271 tree.addMenuItem(menuDeActivate); 272 273 tree.addSeparator(); 274 tree.addMenuItem(menuExport); 275 tree.addMenuItem(menuImport); 276 } 277 else { 278 ContextMenuItem menuRefresh = new ContextMenuItem("refresh"); 279 menuRefresh.setLabel(msgs.get("tree.menu.refresh")); menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); tree.addMenuItem(menuRefresh); 283 } 284 285 } 286 287 291 public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) { 292 Messages msgs = MessagesManager.getMessages(); 293 ContextMenu cm = tree.getMenu(); 294 ContextMenuItem cmItem = cm.getMenuItemByName("open"); 295 if (cmItem != null) { 296 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 297 } 298 cmItem = cm.getMenuItemByName("new"); 299 if (cmItem != null) { 300 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 301 } 302 tree.addFunctionBarItem(null); 304 cmItem = cm.getMenuItemByName("activate"); 305 if (cmItem != null) { 306 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 307 } 308 cmItem = cm.getMenuItemByName("deactivate"); 309 if (cmItem != null) { 310 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 311 } 312 tree.addFunctionBarItem(null); 314 315 ContextMenuItem menuRefresh = new ContextMenuItem("refresh"); 316 menuRefresh.setLabel(msgs.get("tree.menu.refresh")); menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); tree.addFunctionBarItem(new FunctionBarItem(menuRefresh)); 320 321 tree.getFunctionBar().setSearchable(true); 322 tree.getFunctionBar().setOnSearchFunction("mgnl.admininterface.WebsiteTree.search"); 323 } 324 325 } 326 | Popular Tags |