]> git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/commands/EditNode.java
Add a logger
[lgpl/argeo-commons.git] / eclipse / runtime / org.argeo.eclipse.ui.jcr / src / main / java / org / argeo / eclipse / ui / jcr / commands / EditNode.java
1 package org.argeo.eclipse.ui.jcr.commands;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.jcr.Property;
7 import javax.jcr.nodetype.NodeType;
8
9 import org.argeo.eclipse.ui.dialogs.Error;
10 import org.argeo.eclipse.ui.jcr.editors.NodeEditorInput;
11 import org.eclipse.core.commands.AbstractHandler;
12 import org.eclipse.core.commands.ExecutionEvent;
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.ui.PartInitException;
15 import org.eclipse.ui.handlers.HandlerUtil;
16
17 /** Generic command to open a path in an editor. */
18 public class EditNode extends AbstractHandler {
19 public final static String EDITOR_PARAM = "editor";
20
21 private String defaultEditorId;
22
23 private Map<String, String> nodeTypeToEditor = new HashMap<String, String>();
24
25 public Object execute(ExecutionEvent event) throws ExecutionException {
26 String path = event.getParameter(Property.JCR_PATH);
27
28 String type = event.getParameter(NodeType.NT_NODE_TYPE);
29 if (type == null)
30 type = NodeType.NT_UNSTRUCTURED;
31
32 String editorId = event.getParameter(NodeType.NT_NODE_TYPE);
33 if (editorId == null)
34 editorId = nodeTypeToEditor.containsKey(type) ? nodeTypeToEditor
35 .get(type) : defaultEditorId;
36
37 NodeEditorInput nei = new NodeEditorInput(path);
38
39 try {
40 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
41 .openEditor(nei, editorId);
42 } catch (PartInitException e) {
43 Error.show("Cannot open " + editorId + " with " + path
44 + " of type " + type, e);
45 }
46 // TODO Auto-generated method stub
47 return null;
48 }
49
50 public void setDefaultEditorId(String defaultEditorId) {
51 this.defaultEditorId = defaultEditorId;
52 }
53
54 }