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.Select;
41 import info.magnolia.cms.gui.control.Tree;
42 import info.magnolia.cms.gui.control.TreeColumn;
43 import info.magnolia.cms.i18n.Messages;
44 import info.magnolia.module.admininterface.AbstractTreeConfiguration;
45
46 import javax.jcr.PropertyType;
47 import javax.servlet.http.HttpServletRequest;
48
49 import org.apache.commons.lang.StringUtils;
50
51
52
53
54
55
56 public class ConfigTreeConfiguration extends AbstractTreeConfiguration {
57
58
59
60
61
62 public void prepareTree(Tree tree, boolean browseMode, HttpServletRequest request) {
63 final Messages msgs = getMessages();
64
65 tree.setIconPage(Tree.ICONDOCROOT + "folder_cubes.gif");
66
67 tree.addItemType(ItemType.CONTENT.getSystemName());
68 tree.addItemType(ItemType.CONTENTNODE.getSystemName());
69 tree.addItemType(Tree.ITEM_TYPE_NODEDATA);
70 TreeColumn column0 = new TreeColumn(tree.getJavascriptTree(), request);
71 column0.setHtmlEdit();
72 column0.setIsLabel(true);
73 column0.setWidth(3);
74
75 TreeColumn column1 = new TreeColumn(tree.getJavascriptTree(), request);
76 column1.setName(StringUtils.EMPTY);
77 column1.setTitle(msgs.get("tree.config.value"));
78 column1.setIsNodeDataValue(true);
79 column1.setWidth(3);
80 column1.setHtmlEdit();
81
82 TreeColumn column2 = new TreeColumn(tree.getJavascriptTree(), request);
83 column2.setName(StringUtils.EMPTY);
84 column2.setTitle(msgs.get("tree.config.type"));
85 column2.setIsNodeDataType(true);
86 column2.setWidth(1);
87 Select typeSelect = new Select();
88 typeSelect.setName(tree.getJavascriptTree() + TreeColumn.EDIT_NAMEADDITION);
89 typeSelect.setSaveInfo(false);
90 typeSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT);
91 typeSelect.setEvent(
92 "onblur", tree.getJavascriptTree() + ".saveNodeData(this.value,this.options[this.selectedIndex].text)");
93 typeSelect.setOptions(PropertyType.TYPENAME_STRING, Integer.toString(PropertyType.STRING));
94 typeSelect.setOptions(PropertyType.TYPENAME_BOOLEAN, Integer.toString(PropertyType.BOOLEAN));
95 typeSelect.setOptions(PropertyType.TYPENAME_LONG, Integer.toString(PropertyType.LONG));
96 typeSelect.setOptions(PropertyType.TYPENAME_DOUBLE, Integer.toString(PropertyType.DOUBLE));
97
98 column2.setHtmlEdit(typeSelect.getHtml());
99
100 TreeColumn columnIcons = new TreeColumn(tree.getJavascriptTree(), request);
101 columnIcons.setCssClass(StringUtils.EMPTY);
102 columnIcons.setTitle(msgs.get("tree.config.status"));
103 columnIcons.setWidth(1);
104 columnIcons.setIsIcons(true);
105 columnIcons.setIconsActivation(true);
106 columnIcons.setIconsPermission(true);
107
108 TreeColumn column4 = new TreeColumn(tree.getJavascriptTree(), request);
109 column4.setName(MetaData.LAST_MODIFIED);
110 column4.setIsMeta(true);
111 column4.setDateFormat("yy-MM-dd, HH:mm");
112 column4.setWidth(2);
113 column4.setTitle(msgs.get("tree.config.date"));
114
115 tree.addColumn(column0);
116
117 if (!browseMode) {
118 tree.addColumn(column1);
119 tree.addColumn(column2);
120
121 if (isAdminInstance() || hasAnyActiveSubscriber()) {
122 tree.addColumn(columnIcons);
123 }
124 tree.addColumn(column4);
125 }
126 }
127
128
129
130
131
132 public void prepareContextMenu(Tree tree, boolean browseMode, HttpServletRequest request) {
133 final Messages msgs = getMessages();
134
135 ContextMenuItem menuNewPage = new ContextMenuItem("newFolder");
136 menuNewPage.setLabel(msgs.get("tree.config.menu.newFolder"));
137 menuNewPage.setIcon(request.getContextPath() + "/.resources/icons/16/folder_cubes.gif");
138 menuNewPage.setOnclick(tree.getJavascriptTree() + ".createNode('" + ItemType.CONTENT.getSystemName() + "');");
139 menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
140 + tree.getJavascriptTree()
141 + ")");
142 menuNewPage.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotContentNode("
143 + tree.getJavascriptTree()
144 + ")");
145
146 ContextMenuItem menuNewContentNode = new ContextMenuItem("newNode");
147 menuNewContentNode.setLabel(msgs.get("tree.config.menu.newNode"));
148 menuNewContentNode.setIcon(request.getContextPath() + "/.resources/icons/16/cubes.gif");
149 menuNewContentNode.setOnclick(tree.getJavascriptTree() + ".createNode('"
150 + ItemType.CONTENTNODE.getSystemName()
151 + "');");
152 menuNewContentNode.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
153 + tree.getJavascriptTree()
154 + ")");
155
156 ContextMenuItem menuNewNodeData = new ContextMenuItem("newData");
157 menuNewNodeData.setLabel(msgs.get("tree.config.menu.newNodeData"));
158 menuNewNodeData.setIcon(request.getContextPath() + "/.resources/icons/16/cube_green.gif");
159 menuNewNodeData.setOnclick(tree.getJavascriptTree() + ".createNode('" + Tree.ITEM_TYPE_NODEDATA + "');");
160 menuNewNodeData.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
161 + tree.getJavascriptTree()
162 + ")");
163
164 ContextMenuItem menuDelete = new ContextMenuItem("delete");
165 menuDelete.setLabel(msgs.get("tree.config.menu.delete"));
166 menuDelete.setIcon(request.getContextPath() + "/.resources/icons/16/delete2.gif");
167 menuDelete.setOnclick(tree.getJavascriptTree() + ".deleteNode();");
168 menuDelete.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
169 + tree.getJavascriptTree()
170 + ")");
171
172 ContextMenuItem menuCopy = new ContextMenuItem("copy");
173 menuCopy.setLabel(msgs.get("tree.config.menu.copy"));
174 menuCopy.setIcon(request.getContextPath() + "/.resources/icons/16/copy.gif");
175 menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
176 + tree.getJavascriptTree()
177 + ")");
178 menuCopy.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
179 + tree.getJavascriptTree()
180 + ")");
181 menuCopy.setOnclick(tree.getJavascriptTree() + ".copyNode();");
182
183 ContextMenuItem menuCut = new ContextMenuItem("move");
184 menuCut.setLabel(msgs.get("tree.config.menu.move"));
185 menuCut.setIcon(request.getContextPath() + "/.resources/icons/16/up_down.gif");
186 menuCut
187 .addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot(" + tree.getJavascriptTree() + ")");
188 menuCut.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
189 + tree.getJavascriptTree()
190 + ")");
191 menuCut.setOnclick(tree.getJavascriptTree() + ".cutNode();");
192
193 ContextMenuItem menuActivateExcl = new ContextMenuItem("activate");
194 menuActivateExcl.setLabel(msgs.get("tree.config.menu.activate"));
195 menuActivateExcl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green.gif");
196 menuActivateExcl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",false);");
197 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
198 + tree.getJavascriptTree()
199 + ")");
200 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
201 + tree.getJavascriptTree()
202 + ")");
203
204 ContextMenuItem menuActivateIncl = new ContextMenuItem("activateInclSubs");
205 menuActivateIncl.setLabel(msgs.get("tree.config.menu.activateInclSubs"));
206 menuActivateIncl.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_right_green_double.gif");
207 menuActivateIncl.setOnclick(tree.getJavascriptTree() + ".activateNode(" + Tree.ACTION_ACTIVATE + ",true);");
208 menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
209 + tree.getJavascriptTree()
210 + ")");
211 menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
212 + tree.getJavascriptTree()
213 + ")");
214
215 ContextMenuItem menuDeactivate = new ContextMenuItem("deactivate");
216 menuDeactivate.setLabel(msgs.get("tree.config.menu.deactivate"));
217 menuDeactivate.setIcon(request.getContextPath() + "/.resources/icons/16/arrow_left_red.gif");
218 menuDeactivate.setOnclick(tree.getJavascriptTree() + ".deactivateNode(" + Tree.ACTION_DEACTIVATE + ");");
219 menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotRoot("
220 + tree.getJavascriptTree()
221 + ")");
222 menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
223 + tree.getJavascriptTree()
224 + ")");
225
226 ContextMenuItem menuExport = new ContextMenuItem("export");
227 menuExport.setLabel(msgs.get("tree.menu.export"));
228 menuExport.setIcon(request.getContextPath() + "/.resources/icons/16/export1.gif");
229 menuExport.setOnclick(tree.getJavascriptTree() + ".exportNode();");
230 menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
231 + tree.getJavascriptTree()
232 + ")");
233
234 ContextMenuItem menuImport = new ContextMenuItem("import");
235 menuImport.setLabel(msgs.get("tree.menu.import"));
236 menuImport.setIcon(request.getContextPath() + "/.resources/icons/16/import2.gif");
237 menuImport.setOnclick(tree.getJavascriptTree() + ".importNode(this);");
238 menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionSelectedNotNodeData("
239 + tree.getJavascriptTree()
240 + ")");
241
242
243 if (!hasAnyActiveSubscriber()) {
244 menuActivateExcl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)");
245 menuActivateIncl.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)");
246 menuDeactivate.addJavascriptCondition("new mgnlTreeMenuItemConditionBoolean(false)");
247 }
248
249 menuImport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite("
250 + tree.getJavascriptTree()
251 + ")");
252
253 menuExport.addJavascriptCondition("new mgnlTreeMenuItemConditionPermissionWrite("
254 + tree.getJavascriptTree()
255 + ")");
256
257 if (!browseMode) {
258 tree.addMenuItem(menuNewPage);
259 tree.addMenuItem(menuNewContentNode);
260 tree.addMenuItem(menuNewNodeData);
261
262 tree.addSeparator();
263 tree.addMenuItem(menuDelete);
264
265 tree.addSeparator();
266 tree.addMenuItem(menuCut);
267 tree.addMenuItem(menuCopy);
268
269 tree.addSeparator();
270 tree.addMenuItem(menuActivateExcl);
271 tree.addMenuItem(menuActivateIncl);
272 tree.addMenuItem(menuDeactivate);
273
274 tree.addSeparator();
275 tree.addMenuItem(menuExport);
276 tree.addMenuItem(menuImport);
277 }
278 else {
279 tree.addMenuItem(ContextMenuItem.getRefreshMenuItem(tree, msgs, request));
280 }
281
282 }
283
284
285
286
287
288 public void prepareFunctionBar(Tree tree, boolean browseMode, HttpServletRequest request) {
289 final Messages msgs = getMessages();
290 tree.addFunctionBarItemFromContextMenu("newFolder");
291 tree.addFunctionBarItemFromContextMenu("newNode");
292 tree.addFunctionBarItemFromContextMenu("newData");
293
294 tree.addFunctionBarItem(null);
295 tree.addFunctionBarItemFromContextMenu("activate");
296 tree.addFunctionBarItemFromContextMenu("deactivate");
297
298 tree.addFunctionBarItem(null);
299
300 tree.addFunctionBarItem(FunctionBarItem.getRefreshFunctionBarItem(tree, msgs, request));
301 }
302
303 }