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
.commands
;
18 import javax
.jcr
.Node
;
20 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
21 import org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.parts
.JcrQueryEditorInput
;
22 import org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.parts
.NodeEditorInput
;
23 import org
.argeo
.cms
.ui
.workbench
.jcr
.DefaultNodeEditor
;
24 import org
.argeo
.cms
.ui
.workbench
.jcr
.GenericJcrQueryEditor
;
25 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
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
.IWorkbenchPage
;
30 import org
.eclipse
.ui
.PartInitException
;
31 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
33 /** Open a {@link Node} editor of a specific type given the node path */
34 public class OpenEditor
extends AbstractHandler
{
35 public final static String ID
= WorkbenchUiPlugin
.PLUGIN_ID
+ ".openEditor";
37 public final static String PARAM_PATH
= "param.jcrNodePath";
38 public final static String PARAM_EDITOR_ID
= "param.editorId";
40 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
41 String editorId
= event
.getParameter(PARAM_EDITOR_ID
);
43 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(
44 event
).getActivePage();
45 if (DefaultNodeEditor
.ID
.equals(editorId
)) {
46 String path
= event
.getParameter(PARAM_PATH
);
47 NodeEditorInput nei
= new NodeEditorInput(path
);
48 activePage
.openEditor(nei
, DefaultNodeEditor
.ID
);
49 } else if (GenericJcrQueryEditor
.ID
.equals(editorId
)) {
50 JcrQueryEditorInput editorInput
= new JcrQueryEditorInput(
51 GenericJcrQueryEditor
.ID
, null);
52 activePage
.openEditor(editorInput
, editorId
);
54 } catch (PartInitException e
) {
55 throw new EclipseUiException(
56 "Cannot open editor of ID " + editorId
, e
);