1 13 package info.magnolia.module.admininterface.trees; 14 15 import info.magnolia.cms.beans.config.Server; 16 import info.magnolia.cms.beans.config.Subscriber; 17 import info.magnolia.cms.core.ItemType; 18 import info.magnolia.cms.core.MetaData; 19 import info.magnolia.cms.gui.control.ContextMenu; 20 import info.magnolia.cms.gui.control.ContextMenuItem; 21 import info.magnolia.cms.gui.control.FunctionBarItem; 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.module.admininterface.AdminTreeConfiguration; 28 29 import javax.jcr.PropertyType; 30 import javax.servlet.http.HttpServletRequest ; 31 32 import org.apache.commons.lang.StringUtils; 33 34 35 39 public class ConfigTreeConfiguration implements AdminTreeConfiguration { 40 41 45 public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest request) { 46 Messages msgs = MessagesManager.getMessages(); 47 48 tree.setIconPage(Tree.ICONDOCROOT + "folder_cubes.gif"); 50 tree.addItemType(ItemType.CONTENT.getSystemName()); 51 tree.addItemType(ItemType.CONTENTNODE.getSystemName()); 52 tree.addItemType(Tree.ITEM_TYPE_NODEDATA); 53 TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request); 54 column0.setWidth(1); 55 column0.setHtmlEdit(); 56 column0.setIsLabel(true); 57 column0.setWidth(3); 58 TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request); 59 column1.setName(StringUtils.EMPTY); 60 column1.setTitle(msgs.get("tree.config.value")); column1.setIsNodeDataValue(true); 62 column1.setWidth(2); 63 column1.setHtmlEdit(); 64 TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request); 65 column2.setName(StringUtils.EMPTY); 66 column2.setTitle(msgs.get("tree.config.type")); column2.setIsNodeDataType(true); 68 column2.setWidth(2); 69 Select typeSelect = new Select(); 70 typeSelect.setName(tree.getJavascriptTree() + TreeColumn.EDIT_NAMEADDITION); 71 typeSelect.setSaveInfo(false); 72 typeSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT); 73 typeSelect.setEvent( 74 "onblur", tree.getJavascriptTree() + ".saveNodeData(this.value,this.options[this.selectedIndex].text)"); typeSelect.setOptions(PropertyType.TYPENAME_STRING, Integer.toString(PropertyType.STRING)); 76 typeSelect.setOptions(PropertyType.TYPENAME_BOOLEAN, Integer.toString(PropertyType.BOOLEAN)); 77 typeSelect.setOptions(PropertyType.TYPENAME_LONG, Integer.toString(PropertyType.LONG)); 78 typeSelect.setOptions(PropertyType.TYPENAME_DOUBLE, Integer.toString(PropertyType.DOUBLE)); 79 column2.setHtmlEdit(typeSelect.getHtml()); 81 TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request); 82 columnIcons.setCssClass(StringUtils.EMPTY); 83 columnIcons.setWidth(1); 84 columnIcons.setIsIcons(true); 85 columnIcons.setIconsActivation(true); 86 columnIcons.setIconsPermission(true); 87 TreeColumn column4 = new TreeColumn(tree.getJavascriptTree(), request); 88 column4.setName(MetaData.LAST_MODIFIED); 89 column4.setIsMeta(true); 90 column4.setDateFormat("yy-MM-dd, HH:mm"); column4.setWidth(2); 92 column4.setTitle(msgs.get("tree.config.date")); 94 tree.addColumn(column0); 95 96 if (!browseMode) { 97 tree.addColumn(column1); 98 tree.addColumn(column2); 99 if (Server.isAdmin() || Subscriber.isSubscribersEnabled()) { 100 tree.addColumn(columnIcons); 101 } 102 tree.addColumn(column4); 103 } 104 } 105 106 110 public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) { 111 Messages msgs = MessagesManager.getMessages(); 112 113 ContextMenuItem menuNewPage = new ContextMenuItem("newFolder"); 114 menuNewPage.setLabel(msgs.get("tree.config.menu.newFolder")); menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/folder_cubes.gif"); menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');"); menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 119 + ")"); menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotContentNode(" + tree.getJavascriptTree() 122 + ")"); 124 ContextMenuItem menuNewContentNode = new ContextMenuItem("newNode"); 125 menuNewContentNode.setLabel(msgs.get("tree.config.menu.newNode")); menuNewContentNode.setIcon(request.getContextPath() + "/.resources/icons/16/cubes.gif"); menuNewContentNode.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENTNODE.getSystemName() 129 + "');"); menuNewContentNode.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 132 + ")"); 134 ContextMenuItem menuNewNodeData = new ContextMenuItem("newData"); 135 menuNewNodeData.setLabel(msgs.get("tree.config.menu.newNodeData")); menuNewNodeData.setIcon(request.getContextPath() + "/.resources/icons/16/cube_green.gif"); menuNewNodeData.setOnclick(tree.getJavascriptTree() + ".createNode('" + Tree.ITEM_TYPE_NODEDATA + "');"); menuNewNodeData.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 140 + ")"); 142 ContextMenuItem menuDelete = new ContextMenuItem("delete"); 143 menuDelete.setLabel(msgs.get("tree.config.menu.delete")); menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif"); menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();"); menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 148 + ")"); 150 ContextMenuItem menuCopy = new ContextMenuItem("copy"); 151 menuCopy.setLabel(msgs.get("tree.config.menu.copy")); menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif"); menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 155 + ")"); menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 158 + ")"); menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();"); 161 ContextMenuItem menuCut = new ContextMenuItem("move"); 162 menuCut.setLabel(msgs.get("tree.config.menu.move")); menuCut.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif"); menuCut 165 .addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")"); menuCut.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 168 + ")"); menuCut.setOnclick(tree.getJavascriptTree() + ".cutNode();"); 171 ContextMenuItem menuActivateExcl = new ContextMenuItem("activate"); 172 menuActivateExcl.setLabel(msgs.get("tree.config.menu.activate")); menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif"); menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);"); menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() 177 + ")"); menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 180 + ")"); 182 ContextMenuItem menuActivateIncl = new ContextMenuItem("activateInclSubs"); 183 menuActivateIncl.setLabel(msgs.get("tree.config.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() 188 + ")"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 191 + ")"); 193 ContextMenuItem menuDeActivate = new ContextMenuItem("deactivate"); 194 menuDeActivate.setLabel(msgs.get("tree.config.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() 199 + ")"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 202 + ")"); 204 ContextMenuItem menuExport = new ContextMenuItem("export"); 205 menuExport.setLabel(msgs.get("tree.menu.export")); menuExport.setIcon(request.getContextPath() + "/.resources/icons/16/export1.gif"); menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();"); menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 210 + ")"); 212 ContextMenuItem menuImport = new ContextMenuItem("import"); 213 menuImport.setLabel(msgs.get("tree.menu.import")); menuImport.setIcon(request.getContextPath() + "/.resources/icons/16/import2.gif"); menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);"); menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData(" + tree.getJavascriptTree() 218 + ")"); 220 if (!Subscriber.isSubscribersEnabled()) { 222 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); menuDeActivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)"); } 226 227 menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 229 + ")"); 231 menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite(" + tree.getJavascriptTree() 233 + ")"); 235 if (!browseMode) { 236 tree.addMenuItem(menuNewPage); 237 tree.addMenuItem(menuNewContentNode); 238 tree.addMenuItem(menuNewNodeData); 239 240 tree.addSeparator(); 241 tree.addMenuItem(menuDelete); 242 243 tree.addSeparator(); 244 tree.addMenuItem(menuCut); 245 tree.addMenuItem(menuCopy); 246 247 tree.addSeparator(); 248 tree.addMenuItem(menuActivateExcl); 249 tree.addMenuItem(menuActivateIncl); 250 tree.addMenuItem(menuDeActivate); 251 252 tree.addSeparator(); 253 tree.addMenuItem(menuExport); 254 tree.addMenuItem(menuImport); 255 } 256 else { 257 ContextMenuItem menuRefresh = new ContextMenuItem("refresh"); 258 menuRefresh.setLabel(msgs.get("tree.menu.refresh")); menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif"); menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();"); tree.addMenuItem(menuRefresh); 262 } 263 264 } 265 266 270 public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) { 271 Messages msgs = MessagesManager.getMessages(); 272 ContextMenu cm = tree.getMenu(); 273 ContextMenuItem cmItem = cm.getMenuItemByName("newFolder"); 274 if (cmItem != null) { 275 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 276 } 277 cmItem = cm.getMenuItemByName("newNode"); 278 if (cmItem != null) { 279 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 280 } 281 cmItem = cm.getMenuItemByName("newData"); 282 if (cmItem != null) { 283 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 284 } 285 tree.addFunctionBarItem(null); 287 cmItem = cm.getMenuItemByName("activate"); 288 if (cmItem != null) { 289 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 290 } 291 cmItem = cm.getMenuItemByName("deactivate"); 292 if (cmItem != null) { 293 tree.addFunctionBarItem(new FunctionBarItem(cmItem)); 294 } 295 tree.addFunctionBarItem(null); 297 298 ContextMenuItem menuRefresh = new ContextMenuItem("refresh"); 299 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)); 303 } 304 305 } 306 | Popular Tags |