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
.eclipse
.ui
.workbench
.commands
;
18 import org
.argeo
.ArgeoException
;
19 import org
.argeo
.eclipse
.ui
.jcr
.editors
.JcrQueryEditorInput
;
20 import org
.argeo
.eclipse
.ui
.jcr
.editors
.NodeEditorInput
;
21 import org
.argeo
.eclipse
.ui
.workbench
.WorkbenchUiPlugin
;
22 import org
.argeo
.eclipse
.ui
.workbench
.jcr
.GenericJcrQueryEditor
;
23 import org
.argeo
.eclipse
.ui
.workbench
.jcr
.DefaultNodeEditor
;
24 import org
.eclipse
.core
.commands
.AbstractHandler
;
25 import org
.eclipse
.core
.commands
.ExecutionEvent
;
26 import org
.eclipse
.core
.commands
.ExecutionException
;
27 import org
.eclipse
.ui
.IWorkbenchPage
;
28 import org
.eclipse
.ui
.PartInitException
;
29 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
31 /** Opens an editor given its ID. */
32 public class OpenEditor
extends AbstractHandler
{
33 public final static String ID
= WorkbenchUiPlugin
.ID
+ ".openEditor";
35 public final static String PARAM_PATH
= "param.jcrNodePath";
36 public final static String PARAM_EDITOR_ID
= "param.editorId";
38 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
39 String editorId
= event
.getParameter(PARAM_EDITOR_ID
);
41 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(
42 event
).getActivePage();
43 if (DefaultNodeEditor
.ID
.equals(editorId
)) {
44 String path
= event
.getParameter(PARAM_PATH
);
45 NodeEditorInput nei
= new NodeEditorInput(path
);
46 activePage
.openEditor(nei
, DefaultNodeEditor
.ID
);
47 } else if (GenericJcrQueryEditor
.ID
.equals(editorId
)) {
48 JcrQueryEditorInput editorInput
= new JcrQueryEditorInput(
49 GenericJcrQueryEditor
.ID
, null);
50 activePage
.openEditor(editorInput
, editorId
);
52 } catch (PartInitException e
) {
53 throw new ArgeoException("Cannot open editor of ID " + editorId
, e
);