]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java
Clean internal package structure
[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 javax.jcr.Node;
19
20 import org.argeo.ArgeoException;
21 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
22 import org.argeo.eclipse.ui.workbench.internal.jcr.parts.JcrQueryEditorInput;
23 import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodeEditorInput;
24 import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
25 import org.argeo.eclipse.ui.workbench.jcr.GenericJcrQueryEditor;
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;
32
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.ID + ".openEditor";
36
37 public final static String PARAM_PATH = "param.jcrNodePath";
38 public final static String PARAM_EDITOR_ID = "param.editorId";
39
40 public Object execute(ExecutionEvent event) throws ExecutionException {
41 String editorId = event.getParameter(PARAM_EDITOR_ID);
42 try {
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);
53 }
54 } catch (PartInitException e) {
55 throw new ArgeoException("Cannot open editor of ID " + editorId, e);
56 }
57 return null;
58 }
59 }