]>
git.argeo.org Git - gpl/argeo-slc.git/blob - commands/EditNode.java
1 package org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.commands
;
3 import java
.util
.HashMap
;
6 import javax
.jcr
.Property
;
7 import javax
.jcr
.nodetype
.NodeType
;
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
;
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";
21 private String defaultEditorId
;
23 private Map
<String
, String
> nodeTypeToEditor
= new HashMap
<String
, String
>();
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
);
29 type
= NodeType
.NT_UNSTRUCTURED
;
31 String editorId
= event
.getParameter(PARAM_EDITOR_ID
);
33 editorId
= nodeTypeToEditor
.containsKey(type
) ? nodeTypeToEditor
34 .get(type
) : defaultEditorId
;
36 NodeEditorInput nei
= new NodeEditorInput(path
);
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
);
47 public void setDefaultEditorId(String defaultEditorId
) {
48 this.defaultEditorId
= defaultEditorId
;