]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/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
.cms
.ui
.workbench
.internal
.jcr
.commands
;
18 import java
.util
.HashMap
;
21 import javax
.jcr
.Property
;
22 import javax
.jcr
.nodetype
.NodeType
;
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
;
32 /** Generic command to open a Node in an editor. */
33 public class EditNode
extends AbstractHandler
{
34 public final static String PARAM_EDITOR_ID
= "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
);
42 String type
= event
.getParameter(NodeType
.NT_NODE_TYPE
);
44 type
= NodeType
.NT_UNSTRUCTURED
;
46 String editorId
= event
.getParameter(PARAM_EDITOR_ID
);
48 editorId
= nodeTypeToEditor
.containsKey(type
) ? nodeTypeToEditor
49 .get(type
) : defaultEditorId
;
51 NodeEditorInput nei
= new NodeEditorInput(path
);
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
);
62 public void setDefaultEditorId(String defaultEditorId
) {
63 this.defaultEditorId
= defaultEditorId
;