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.core.ItemType; 20 import info.magnolia.cms.core.MetaData; 21 import info.magnolia.cms.gui.control.ContextMenuItem; 22 import info.magnolia.cms.gui.control.Select; 23 import info.magnolia.cms.gui.control.Tree; 24 import info.magnolia.cms.gui.control.TreeColumn; 25 import info.magnolia.cms.i18n.Messages; 26 import info.magnolia.cms.i18n.MessagesManager; 27 import info.magnolia.cms.i18n.TemplateMessagesUtil; 28 import info.magnolia.cms.security.SessionAccessControl; 29 import info.magnolia.module.admininterface.AdminTreeMVCHandler; 30 31 import java.util.Iterator ; 32 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 36 import org.apache.commons.lang.StringUtils; 37 38 39 44 public class AdminTreeWebsite extends AdminTreeMVCHandler { 45 46 51 public AdminTreeWebsite(String name, HttpServletRequest request, HttpServletResponse response) { 52 super(name, request, response); 53 } 54 55 protected String getRepository() { 56 return ContentRepository.WEBSITE; 57 } 58 59 62 protected void prepareTree(Tree tree, HttpServletRequest request) { 63 Messages msgs = MessagesManager.getMessages(request); 64 65 tree.setIconOndblclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); 67 tree.addItemType(ItemType.CONTENT); 68 69 TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request); 70 column0.setIsLabel(true); 71 column0.setWidth(3); 72 if (Server.isAdmin()) { 73 column0.setHtmlEdit(); 74 } 75 TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request); 76 columnIcons.setCssClass(StringUtils.EMPTY); 77 columnIcons.setWidth(1); 78 columnIcons.setIsIcons(true); 79 columnIcons.setIconsActivation(true); 80 columnIcons.setIconsPermission(true); 81 TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request); 82 column1.setName("title"); column1.setTitle(msgs.get("tree.web.title")); column1.setWidth(2); 85 if (Server.isAdmin()) { 86 column1.setHtmlEdit(); 87 } 88 TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request); 89 column2.setName(MetaData.TEMPLATE); 90 column2.setIsMeta(true); 91 column2.setWidth(2); 92 column2.setTitle(msgs.get("tree.web.template")); column2.setHtmlRenderer(new TemplateTreeColumnHtmlRenderer()); 95 96 Select templateSelect = new Select(); 97 templateSelect.setName(tree.getJavascriptTree() + TreeColumn.EDIT_NAMEADDITION); 98 templateSelect.setSaveInfo(false); 99 templateSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT); 100 101 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)"); 109 Iterator templates = Template.getAvailableTemplates(SessionAccessControl.getAccessManager( 110 request, 111 ContentRepository.CONFIG)); 112 while (templates.hasNext()) { 113 Template template = (Template) templates.next(); 114 String title = template.getTitle(); 115 title = TemplateMessagesUtil.get(request, title); 116 title = Messages.javaScriptString(title); 117 templateSelect.setOptions(title, template.getName()); 118 } 119 if (Server.isAdmin()) { 120 column2.setHtmlEdit(templateSelect.getHtml()); 121 } 122 TreeColumn column3 = new TreeColumn(tree.getJavascriptTree(), request); 125 column3.setName(MetaData.LAST_MODIFIED); 126 column3.setIsMeta(true); 128 column3.setDateFormat("yy-MM-dd, HH:mm"); column3.setWidth(2); 130 column3.setTitle(msgs.get("tree.web.date")); 132 tree.addColumn(column0); 133 134 if (!this.isBrowseMode()) { 135 tree.addColumn(column1); 136 if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) { 137 tree.addColumn(columnIcons); 138 } 139 tree.addColumn(column2); 140 tree.addColumn(column3); 141 } 142 } 143 144 148 protected void prepareContextMenu(Tree tree, HttpServletRequest request) { 149 Messages msgs = MessagesManager.getMessages(request); 150 ContextMenuItem menuOpen = new ContextMenuItem(); 151 menuOpen.setLabel(msgs.get("tree.web.menu.open")); menuOpen.setIcon(request.getContextPath() + "/admindocroot/icons/16/document_plain_earth.gif"); menuOpen.setOnclick("mgnlTreeMenuItemOpen(" + tree.getJavascriptTree() + ");"); menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); 157 ContextMenuItem menuNewPage = new ContextMenuItem(); 158 menuNewPage.setLabel(msgs.get("tree.web.menu.new")); menuNewPage.setIcon(request.getContextPath() + "/admindocroot/icons/16/document_plain_earth_add.gif"); 161 menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 165 ContextMenuItem menuDelete = new ContextMenuItem(); 166 menuDelete.setLabel(msgs.get("tree.web.menu.delete")); menuDelete.setIcon(request.getContextPath() + "/admindocroot/icons/16/delete2.gif"); menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 174 ContextMenuItem menuMove = new ContextMenuItem(); 175 menuMove.setLabel(msgs.get("tree.web.menu.move")); menuMove.setIcon(request.getContextPath() + "/admindocroot/icons/16/up_down.gif"); menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();"); menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 183 ContextMenuItem menuCopy = new ContextMenuItem(); 184 menuCopy.setLabel(msgs.get("tree.web.menu.copy")); menuCopy.setIcon(request.getContextPath() + "/admindocroot/icons/16/copy.gif"); menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); 190 ContextMenuItem menuActivateExcl = new ContextMenuItem(); 191 menuActivateExcl.setLabel(msgs.get("tree.web.menu.activate")); menuActivateExcl.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_right_green.gif"); 194 menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 200 ContextMenuItem menuActivateIncl = new ContextMenuItem(); 201 menuActivateIncl.setLabel(msgs.get("tree.web.menu.activateInclSubs")); menuActivateIncl.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_right_green.gif"); menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 209 ContextMenuItem menuDeActivate = new ContextMenuItem(); 210 menuDeActivate.setLabel(msgs.get("tree.web.menu.deactivate")); menuDeActivate.setIcon(request.getContextPath() + "/admindocroot/icons/16/arrow_left_red.gif"); menuDeActivate.setOnclick(tree.getJavascriptTree() + ".deActivateNode(" + Tree.ACTION_DEACTIVATE + ");"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 218 ContextMenuItem menuRefresh = new ContextMenuItem(); 219 menuRefresh.setLabel(msgs.get("tree.menu.refresh")); menuRefresh.setIcon(request.getContextPath() + "/admindocroot/icons/16/refresh.gif"); menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); 223 ContextMenuItem menuExport = new ContextMenuItem(); 224 menuExport.setLabel(msgs.get("tree.menu.export")); menuExport.setIcon(request.getContextPath() + "/admindocroot/icons/16/export.gif"); menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() + ")"); 232 ContextMenuItem menuImport = new ContextMenuItem(); 233 menuImport.setLabel(msgs.get("tree.menu.import")); menuImport.setIcon(request.getContextPath() + "/admindocroot/icons/16/import1.gif"); menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() + ")"); 241 if (!Server.isAdmin()) { 243 menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); } 249 250 if (!Subscriber.isSubscribersEnabled()) { 252 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); } 256 257 menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 260 menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() + ")"); 263 if (!this.isBrowseMode()) { 264 tree.addMenuItem(menuOpen); 265 tree.addMenuItem(menuNewPage); 266 267 tree.addSeparator(); 268 tree.addMenuItem(menuDelete); 269 270 tree.addSeparator(); 271 tree.addMenuItem(menuMove); 272 tree.addMenuItem(menuCopy); 273 274 tree.addSeparator(); 275 tree.addMenuItem(menuActivateExcl); 276 tree.addMenuItem(menuActivateIncl); 277 tree.addMenuItem(menuDeActivate); 278 279 tree.addSeparator(); 280 tree.addMenuItem(menuExport); 281 tree.addMenuItem(menuImport); 282 283 tree.addSeparator(); 284 } 285 tree.addMenuItem(menuRefresh); 286 } 287 288 } | Popular Tags |