1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*******************************************************************************
* Copyright (c) 2011, 2012 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Obeo - initial implementation
*******************************************************************************/
package org.eclipse.m2m.atl.adt.ui.actions;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.m2m.atl.adt.ui.editor.AtlEditor;
import org.eclipse.m2m.atl.adt.ui.text.atl.OpenDeclarationUtils;
import org.eclipse.m2m.atl.adt.ui.text.atl.types.Feature;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
/**
* The ATL Open declaration action.
*
* @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
*/
public class OpenDeclarationAction extends Action implements IWorkbenchWindowActionDelegate, IObjectActionDelegate, IEditorActionDelegate {
/**
* The action id
*/
public final static String ACTION_ID = "org.eclipse.m2m.atl.adt.ui.actions.OpenDeclaration"; //$NON-NLS-1$
/**
* The associated command ID
*/
public final static String COMMAND_ID = "atlCommands.openDeclaration"; //$NON-NLS-1$
/* (non-Javadoc) */
public void dispose() {
// nothing to do
}
/* (non-Javadoc) */
public void init(IWorkbenchWindow window) {
// nothing to do
}
/* (non-Javadoc) */
public void run(IAction action) {
super.run();
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() instanceof AtlEditor) {
AtlEditor textEditor = (AtlEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
if (textEditor.getSelectionProvider() != null) {
ITextSelection selection = (ITextSelection)textEditor.getSelectionProvider().getSelection();
if (selection != null) {
try {
Object declaration = OpenDeclarationUtils.getDeclaration(textEditor, selection
.getOffset(), selection.getLength());
if (declaration != null) {
if (declaration instanceof EObject) {
OpenDeclarationUtils.openDeclaration(null, (EObject)declaration, textEditor);
} else if (declaration instanceof Feature) {
OpenDeclarationUtils.openDeclaration(((Feature)declaration).getUnit(),
((Feature)declaration).getDeclaration(), textEditor);
}
}
} catch (BadLocationException e) {
// continue
}
}
}
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
}
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
* org.eclipse.ui.IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart part) {
}
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction,
* org.eclipse.ui.IEditorPart)
*/
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
}
}
|