/
EClassHierarchyHandler.java
72 lines (67 loc) · 2.63 KB
/
EClassHierarchyHandler.java
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
/*******************************************************************************
* Copyright (c) 2015 IRT AESE (IRT Saint Exupery) and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Pierre Gaufillet (IRT Saint Exupery) - initial API and implementation
*
*******************************************************************************/
package org.eclipse.emf.ecoretools.ui.views;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecoretools.ui.Activator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
public class EClassHierarchyHandler extends AbstractHandler {
/* (non-Javadoc)
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveMenuSelection(event);
if (selection != null) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object o = structuredSelection.getFirstElement();
if (o instanceof IAdaptable) {
Object adaptedObj = ((IAdaptable) o).getAdapter(EObject.class);
if (adaptedObj instanceof EObject) {
o = adaptedObj;
}
}
if (o instanceof DSemanticDecorator) {
o = ((DSemanticDecorator) o).getTarget();
}
if (o instanceof EObject) {
EObject eObject = (EObject) o;
if (!(eObject instanceof EClass)) {
eObject = eObject.eClass();
}
if (eObject != null) {
try {
IWorkbenchPart activePart = HandlerUtil.getActivePartChecked(event);
IViewPart view = activePart.getSite().getPage().showView(EClassHierarchyView.VIEW_ID);
((EClassHierarchyView) view).setAnalyzedObject(eObject);
} catch (PartInitException exception) {
Activator.log(exception);
}
}
}
}
}
return null;
}
}