1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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.cms.util.NodeNameComparator;
44 import info.magnolia.module.admininterface.AbstractTreeConfiguration;
45
46 import javax.servlet.http.HttpServletRequest;
47
48
49
50
51
52 public class RolesTreeConfiguration extends AbstractTreeConfiguration {
53
54
55
56
57
58 public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest request) {
59 tree.setSortComparator(new NodeNameComparator());
60
61 tree.setDrawShifter(false);
62
63 tree.setIcon(ItemType.ROLE.getSystemName(), Tree.ICONDOCROOT + "hat_white.gif");
64 tree.setIconOndblclick("mgnlTreeMenuOpenDialog("
65 + tree.getJavascriptTree()
66 + ",'.magnolia/dialogs/roleedit.html');");
67 tree.addItemType(ItemType.ROLE);
68
69 final Messages msgs = getMessages();
70 TreeColumn column0 = TreeColumn.createLabelColumn(tree, msgs.get("tree.roles.name"), !browseMode);
71 column0.setWidth(2);
72
73 TreeColumn column1 = TreeColumn.createNodeDataColumn(tree, msgs.get("tree.roles.fullname"), "title", !browseMode);
74 column1.setWidth(2);
75
76 TreeColumn columnIcons = TreeColumn.createActivationColumn(tree, msgs.get("tree.roles.status"));
77
78 TreeColumn column2 = TreeColumn.createMetaDataColumn(tree, msgs.get("tree.roles.date"), MetaData.LAST_MODIFIED, "yyyy-MM-dd, HH:mm");
79 column2.setWidth(2);
80
81 tree.addColumn(column0);
82 if (!browseMode) {
83 tree.addColumn(column1);
84 if (isAdminInstance() || hasAnyActiveSubscriber()) {
85 tree.addColumn(columnIcons);
86 }
87 tree.addColumn(column2);
88 }
89 }
90
91
92
93
94
95 public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) {
96 final Messages msgs = getMessages();
97
98 ContextMenuItem menuOpen = new ContextMenuItem("edit");
99 menuOpen.setLabel(msgs.get("tree.roles.menu.edit"));
100 menuOpen.setIcon(request.getContextPath() + "/.resources/icons/16/hat_white.gif");
101 menuOpen.setOnclick("mgnlTreeMenuOpenDialog("
102 + tree.getJavascriptTree()
103 + ",'.magnolia/dialogs/roleedit.html');");
104 menuOpen.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
105 + tree.getJavascriptTree()
106 + ")");
107 ContextMenuItem menuNewPage = new ContextMenuItem("new");
108 menuNewPage.setLabel(msgs.get("tree.roles.menu.new"));
109 menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/hat_white_add.gif");
110 menuNewPage.setOnclick(tree.getJavascriptTree() + ".createRootNode('"
111 + ItemType.ROLE.getSystemName()
112 + "');");
113 ContextMenuItem menuDelete = new ContextMenuItem("delete");
114 menuDelete.setLabel(msgs.get("tree.roles.menu.delete"));
115 menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif");
116 menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();");
117 menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
118 + tree.getJavascriptTree()
119 + ")");
120 ContextMenuItem menuMove = new ContextMenuItem("move");
121 menuMove.setLabel(msgs.get("tree.roles.menu.move"));
122 menuMove.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif");
123 menuMove.setOnclick(tree.getJavascriptTree() + ".cutNode();");
124 menuMove.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
125 + tree.getJavascriptTree()
126 + ")");
127 ContextMenuItem menuCopy = new ContextMenuItem("copy");
128 menuCopy.setLabel(msgs.get("tree.roles.menu.copy"));
129 menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif");
130 menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();");
131 menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
132 + tree.getJavascriptTree()
133 + ")");
134
135 ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
136 menuActivateExcl.setLabel(msgs.get("tree.roles.menu.activate"));
137 menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif");
138 menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);");
139 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
140 + tree.getJavascriptTree()
141 + ")");
142 ContextMenuItem menuDeactivate = new ContextMenuItem("deactivate");
143 menuDeactivate.setLabel(msgs.get("tree.roles.menu.deactivate"));
144 menuDeactivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif");
145 menuDeactivate.setOnclick(tree.getJavascriptTree() + ".deactivateNode(" + Tree.ACTION_DEACTIVATE + ");");
146 menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
147 + tree.getJavascriptTree()
148 + ")");
149
150 if (!hasAnyActiveSubscriber()) {
151 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)");
152 menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)");
153 }
154
155 if (!browseMode) {
156 tree.addMenuItem(menuOpen);
157 tree.addMenuItem(menuNewPage);
158
159 tree.addMenuItem(null);
160 tree.addMenuItem(menuDelete);
161
162 tree.addMenuItem(null);
163 tree.addMenuItem(menuActivateExcl);
164 tree.addMenuItem(menuDeactivate);
165 }
166 else {
167 tree.addMenuItem(ContextMenuItem.getRefreshMenuItem(tree, msgs, request));
168 }
169 }
170
171
172
173
174
175 public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) {
176 tree.addFunctionBarItemFromContextMenu("edit");
177 tree.addFunctionBarItemFromContextMenu("new");
178 tree.addFunctionBarItem(null);
179 tree.addFunctionBarItemFromContextMenu("activate");
180 tree.addFunctionBarItemFromContextMenu("deactivate");
181 tree.addFunctionBarItem(null);
182 tree.addFunctionBarItem(FunctionBarItem.getRefreshFunctionBarItem(tree, getMessages(), request));
183 }
184
185 }