]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java
Do not use latest EclipseUiUtils to enable using the new command as hot fix on existi...
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui.workbench / src / org / argeo / eclipse / ui / workbench / commands / OpenEditor.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 org.argeo.ArgeoException;
19 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
20 import org.argeo.eclipse.ui.workbench.jcr.GenericJcrQueryEditor;
21 import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
22 import org.argeo.eclipse.ui.workbench.jcr.internal.parts.JcrQueryEditorInput;
23 import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodeEditorInput;
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;
30
31 /** Opens an editor given its ID. */
32 public class OpenEditor extends AbstractHandler {
33 public final static String ID = WorkbenchUiPlugin.ID + ".openEditor";
34
35 public final static String PARAM_PATH = "param.jcrNodePath";
36 public final static String PARAM_EDITOR_ID = "param.editorId";
37
38 public Object execute(ExecutionEvent event) throws ExecutionException {
39 String editorId = event.getParameter(PARAM_EDITOR_ID);
40 try {
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);
51 }
52 } catch (PartInitException e) {
53 throw new ArgeoException("Cannot open editor of ID " + editorId, e);
54 }
55 return null;
56 }
57 }