]> git.argeo.org Git - gpl/argeo-slc.git/blob - commands/EditNode.java
Prepare next development cycle
[gpl/argeo-slc.git] / commands / EditNode.java
1 package org.argeo.cms.ui.workbench.internal.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.cms.ui.workbench.internal.jcr.parts.NodeEditorInput;
10 import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
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 Node in an editor. */
18 public class EditNode extends AbstractHandler {
19 public final static String PARAM_EDITOR_ID = "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 String type = event.getParameter(NodeType.NT_NODE_TYPE);
28 if (type == null)
29 type = NodeType.NT_UNSTRUCTURED;
30
31 String editorId = event.getParameter(PARAM_EDITOR_ID);
32 if (editorId == null)
33 editorId = nodeTypeToEditor.containsKey(type) ? nodeTypeToEditor
34 .get(type) : defaultEditorId;
35
36 NodeEditorInput nei = new NodeEditorInput(path);
37 try {
38 HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
39 .openEditor(nei, editorId);
40 } catch (PartInitException e) {
41 ErrorFeedback.show("Cannot open " + editorId + " with " + path
42 + " of type " + type, e);
43 }
44 return null;
45 }
46
47 public void setDefaultEditorId(String defaultEditorId) {
48 this.defaultEditorId = defaultEditorId;
49 }
50 }