1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.cms.ui.workbench.internal.jcr.commands;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import javax.jcr.Property;
22 import javax.jcr.nodetype.NodeType;
23
24 import org.argeo.cms.ui.workbench.internal.jcr.parts.NodeEditorInput;
25 import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
26 import org.eclipse.core.commands.AbstractHandler;
27 import org.eclipse.core.commands.ExecutionEvent;
28 import org.eclipse.core.commands.ExecutionException;
29 import org.eclipse.ui.PartInitException;
30 import org.eclipse.ui.handlers.HandlerUtil;
31
32
33 public class EditNode extends AbstractHandler {
34 public final static String PARAM_EDITOR_ID = "editor";
35
36 private String defaultEditorId;
37
38 private Map<String, String> nodeTypeToEditor = new HashMap<String, String>();
39
40 public Object execute(ExecutionEvent event) throws ExecutionException {
41 String path = event.getParameter(Property.JCR_PATH);
42 String type = event.getParameter(NodeType.NT_NODE_TYPE);
43 if (type == null)
44 type = NodeType.NT_UNSTRUCTURED;
45
46 String editorId = event.getParameter(PARAM_EDITOR_ID);
47 if (editorId == null)
48 editorId = nodeTypeToEditor.containsKey(type) ? nodeTypeToEditor
49 .get(type) : defaultEditorId;
50
51 NodeEditorInput nei = new NodeEditorInput(path);
52 try {
53 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
54 .openEditor(nei, editorId);
55 } catch (PartInitException e) {
56 ErrorFeedback.show("Cannot open " + editorId + " with " + path
57 + " of type " + type, e);
58 }
59 return null;
60 }
61
62 public void setDefaultEditorId(String defaultEditorId) {
63 this.defaultEditorId = defaultEditorId;
64 }
65 }