]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/EditNode.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.jcr
.ui
.explorer
.commands
;
18 import java
.util
.HashMap
;
21 import javax
.jcr
.Property
;
22 import javax
.jcr
.nodetype
.NodeType
;
24 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
25 import org
.argeo
.eclipse
.ui
.jcr
.editors
.NodeEditorInput
;
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
;
32 /** Generic command to open a path in an editor. */
33 public class EditNode
extends AbstractHandler
{
34 public final static String EDITOR_PARAM
= "editor";
36 private String defaultEditorId
;
38 private Map
<String
, String
> nodeTypeToEditor
= new HashMap
<String
, String
>();
40 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
41 String path
= event
.getParameter(Property
.JCR_PATH
);
43 String type
= event
.getParameter(NodeType
.NT_NODE_TYPE
);
45 type
= NodeType
.NT_UNSTRUCTURED
;
47 String editorId
= event
.getParameter(NodeType
.NT_NODE_TYPE
);
49 editorId
= nodeTypeToEditor
.containsKey(type
) ? nodeTypeToEditor
50 .get(type
) : defaultEditorId
;
52 NodeEditorInput nei
= new NodeEditorInput(path
);
55 HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage()
56 .openEditor(nei
, editorId
);
57 } catch (PartInitException e
) {
58 ErrorFeedback
.show("Cannot open " + editorId
+ " with " + path
59 + " of type " + type
, e
);
61 // TODO Auto-generated method stub
65 public void setDefaultEditorId(String defaultEditorId
) {
66 this.defaultEditorId
= defaultEditorId
;