]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/EditNode.java
Revert hack that was necessary before Rap 2.3.x
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui.workbench / src / org / argeo / eclipse / ui / workbench / commands / EditNode.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.eclipse.ui.workbench.commands;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import javax.jcr.Property;
22 import javax.jcr.nodetype.NodeType;
23
24 import org.argeo.eclipse.ui.workbench.ErrorFeedback;
25 import org.argeo.eclipse.ui.workbench.jcr.internal.parts.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;
31
32 /** Generic command to open a path in an editor. */
33 public class EditNode extends AbstractHandler {
34 public final static String EDITOR_PARAM = "editor";
35
36 private String defaultEditorId;
37
38 private Map<String, String> nodeTypeToEditor = new HashMap<String, String>();
39
40 public Object execute(ExecutionEvent event) throws ExecutionException {
41 String path = event.getParameter(Property.JCR_PATH);
42
43 String type = event.getParameter(NodeType.NT_NODE_TYPE);
44 if (type == null)
45 type = NodeType.NT_UNSTRUCTURED;
46
47 String editorId = event.getParameter(NodeType.NT_NODE_TYPE);
48 if (editorId == null)
49 editorId = nodeTypeToEditor.containsKey(type) ? nodeTypeToEditor
50 .get(type) : defaultEditorId;
51
52 NodeEditorInput nei = new NodeEditorInput(path);
53
54 try {
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);
60 }
61 // TODO Auto-generated method stub
62 return null;
63 }
64
65 public void setDefaultEditorId(String defaultEditorId) {
66 this.defaultEditorId = defaultEditorId;
67 }
68
69 }