-
Notifications
You must be signed in to change notification settings - Fork 85
/
NavigationSemanticBrowserDoubleClickHandler.java
120 lines (107 loc) · 4.24 KB
/
NavigationSemanticBrowserDoubleClickHandler.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
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
115
116
117
118
119
120
package org.polarsys.capella.core.ui.semantic.browser.sirius.handlers;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.polarsys.capella.common.ui.toolkit.browser.content.provider.wrapper.EObjectWrapper;
import org.polarsys.capella.core.commands.preferences.ui.sirius.DoubleClickBehaviourUtil;
import org.polarsys.capella.core.platform.sirius.ui.navigator.actions.OpenRelatedDiagramAction;
import org.polarsys.capella.core.ui.semantic.browser.handler.DefaultSemanticBrowserDoubleClickHandler;
import org.polarsys.capella.core.ui.semantic.browser.sirius.actions.DiagramOpenAction;
import org.polarsys.capella.core.ui.semantic.browser.view.SemanticBrowserView;
public class NavigationSemanticBrowserDoubleClickHandler extends DefaultSemanticBrowserDoubleClickHandler {
@Override
public void handle(SemanticBrowserView view, DoubleClickEvent event, Object selectedElement) {
// Get selection of currently selected viewer
// Right now this is the only way to get the selection from Referenced or Referencing viewer
IStructuredSelection selection = (IStructuredSelection) view.getSite().getSelectionProvider().getSelection();
if (!selection.isEmpty()) {
if (selection.size() == 1) {
if (isCtrlKeyPressed()) {
// If CTRL is pressed on double-click on a single element, it shall be put as the current element
super.handle(view, event, selectedElement);
} else {
// If it wasn't pressed, run navigation action
runAction(view, event, selectedElement);
}
} else {
// If multiple elements in the selection, run action on each of them
for (Object element : selection.toList()) {
runAction(view, event, element);
}
}
}
}
protected void runAction(SemanticBrowserView view, DoubleClickEvent event, Object selectedElement) {
if (selectedElement instanceof EObjectWrapper) {
selectedElement = ((EObjectWrapper) selectedElement).getElement();
}
if (!(selectedElement instanceof EObject)) {
// Not handled
return;
}
EObject elementAsEObject = (EObject) selectedElement;
if (shouldOpenDiagram(elementAsEObject)) {
openDiagram(view, (DRepresentationDescriptor) elementAsEObject);
} else {
if (shouldNavigate(elementAsEObject)) {
openRelatedDiagrams(elementAsEObject);
} else {
// Should open wizard
super.runAction(view, event, elementAsEObject);
}
}
}
/**
* Returns true if double-click on selectedElement should execute the navigation action
*
* @param selectedElement
* @return
*/
public boolean shouldNavigate(EObject selectedElement) {
return selectedElement != null
&& DoubleClickBehaviourUtil.INSTANCE.shouldOpenRelatedDiagramsOnDoubleClick(selectedElement);
}
/**
* Returns true if double-click on selectedElement should open the properties wizard
*
* @param selectedElement
* @return
*/
public boolean shouldOpenPropertyWizard(EObject selectedElement) {
if (shouldOpenDiagram(selectedElement))
return false;
return !shouldNavigate(selectedElement);
}
/**
* Returns true if double-click on selectedElement should open the diagram
*
* @param selectedElement
* @return
*/
public boolean shouldOpenDiagram(EObject selectedElement) {
return selectedElement instanceof DRepresentationDescriptor;
}
/**
* Open diagram of given diagram descriptor
*
* @param diagramToOpen
*/
protected void openDiagram(SemanticBrowserView view, DRepresentationDescriptor diagramToOpen) {
DiagramOpenAction action = new DiagramOpenAction();
// Open related diagram editor.
action.init(view);
action.selectionChanged(null, new StructuredSelection(diagramToOpen));
action.run(null);
}
/**
* Run the OpenRelatedDiagramAction on selected element
*
* @param selectedElement
*/
protected void openRelatedDiagrams(EObject selectedElement) {
OpenRelatedDiagramAction action = new OpenRelatedDiagramAction(selectedElement);
action.run();
}
}