Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 82387adebc13a7275769041b032407a155b2626e (plain) (blame)
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
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright (c) 2007, 2009 Borland Software Corporation
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Alexander Shatalin (Borland) - initial API and implementation
 */

«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«EXTENSION xpt::navigator::Utils»

«DEFINE NavigatorLinkHelper FOR gmfgen::GenNavigator-»
	«EXPAND xpt::Common::copyright FOR editorGen-»
package «packageName»;

	«EXPAND xpt::Common::generatedClassComment»
public class «linkHelperClassName» implements org.eclipse.ui.navigator.ILinkHelper {

	«EXPAND xpt::navigator::getEditorInput::getEditorInput FOR editorGen-»

	«EXPAND findSelection-»
	
	«EXPAND activateEditor-»
	
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE findSelection FOR gmfgen::GenNavigator-»
	«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.jface.viewers.IStructuredSelection findSelection(org.eclipse.ui.IEditorInput anInput) {
	«EXPAND defineDiagramDocument FOR editorGen.plugin-»
	«EXPAND findSelectionBody-»
}
«ENDDEFINE»

«DEFINE defineDiagramDocument FOR gmfgen::GenPlugin-»
org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument document = «getActivatorQualifiedClassName()».getInstance().getDocumentProvider().getDiagramDocument(anInput);
«ENDDEFINE»

«DEFINE findSelectionBody FOR gmfgen::GenNavigator-»
	«EXPAND getDiagramSelection FOR getDiagramTopReference(self)-»
	return org.eclipse.jface.viewers.StructuredSelection.EMPTY;
«ENDDEFINE»

«REM»
	Linking with editor currently supported only for the navigators conteining top 
	reference to the diagram. In this case diagram node will be selected in navigator.
«ENDREM»
«DEFINE getDiagramSelection FOR gmfgen::GenNavigatorChildReference-»
«EXPAND getDiagram FOR navigator.editorGen-»
org.eclipse.core.resources.IFile file = org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(diagram.eResource());
if (file != null) {
	«IF isInsideGroup()-»
	«navigator.getNavigatorGroupQualifiedClassName()» parentGroup = new «navigator.getNavigatorGroupQualifiedClassName()»("«groupName»", "«groupIcon»", «EXPAND xpt::editor::VisualIDRegistry::modelID FOR navigator.editorGen.diagram», file);
	«ENDIF-»
	«navigator.getNavigatorItemQualifiedClassName()» item = new «navigator.getNavigatorItemQualifiedClassName()»(diagram, «IF isInsideGroup()»parentGroup«ELSE»file«ENDIF», false);
	«IF isInsideGroup()-»
	parentGroup.addChild(item);
	«ENDIF-»
	return new org.eclipse.jface.viewers.StructuredSelection(«IF isInsideGroup()»parentGroup«ELSE»item«ENDIF»);
}
«ENDDEFINE»

«DEFINE getDiagram FOR gmfgen::GenEditorGenerator-»
if (document == null) {
	return org.eclipse.jface.viewers.StructuredSelection.EMPTY;
}
org.eclipse.gmf.runtime.notation.Diagram diagram = document.getDiagram();
«ENDDEFINE»

«DEFINE activateEditor FOR gmfgen::GenNavigator-»
	«EXPAND xpt::Common::generatedMemberComment»
public void activateEditor(org.eclipse.ui.IWorkbenchPage aPage, org.eclipse.jface.viewers.IStructuredSelection aSelection) {
	if (aSelection == null || aSelection.isEmpty()) {
		return;
	}
	if (false == aSelection.getFirstElement() instanceof «getAbstractNavigatorItemQualifiedClassName()») {
		return;
	}
		
	«getAbstractNavigatorItemQualifiedClassName()» abstractNavigatorItem = («getAbstractNavigatorItemQualifiedClassName()») aSelection.getFirstElement();
	org.eclipse.gmf.runtime.notation.View navigatorView = null;
	if (abstractNavigatorItem instanceof «getNavigatorItemQualifiedClassName()») {
		navigatorView = ((«getNavigatorItemQualifiedClassName()») abstractNavigatorItem).getView();
	} else if (abstractNavigatorItem instanceof «getNavigatorGroupQualifiedClassName()») {
		«getNavigatorGroupQualifiedClassName()» navigatorGroup = («getNavigatorGroupQualifiedClassName()») abstractNavigatorItem;
		if (navigatorGroup.getParent() instanceof «getNavigatorItemQualifiedClassName()») {
			navigatorView = ((«getNavigatorItemQualifiedClassName()») navigatorGroup.getParent()).getView();
		}«EXPAND getViewFromShortcut-»
	}
	if (navigatorView == null) {
		return;
	}
	org.eclipse.ui.IEditorInput editorInput = getEditorInput(navigatorView.getDiagram());
	org.eclipse.ui.IEditorPart editor = aPage.findEditor(editorInput);
	if (editor == null) {
		return;
	}
	aPage.bringToTop(editor);
	if (editor instanceof «EXPAND diagramEditorClassFQName») {
		«EXPAND diagramEditorClassFQName» diagramEditor = («EXPAND diagramEditorClassFQName») editor;
		org.eclipse.emf.ecore.resource.ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet();
		org.eclipse.emf.ecore.EObject selectedView = diagramEditorResourceSet.getEObject(org.eclipse.emf.ecore.util.EcoreUtil.getURI(navigatorView), true);	
		if (selectedView == null) {
			return;
		}
		org.eclipse.gef.GraphicalViewer graphicalViewer = (org.eclipse.gef.GraphicalViewer) diagramEditor.getAdapter(org.eclipse.gef.GraphicalViewer.class);
		org.eclipse.gef.EditPart selectedEditPart = (org.eclipse.gef.EditPart) graphicalViewer.getEditPartRegistry().get(selectedView);
		if (selectedEditPart != null) {
			graphicalViewer.select(selectedEditPart);
		}
	}
}
«ENDDEFINE»

«DEFINE getViewFromShortcut FOR gmfgen::GenNavigator-»
	«IF editorGen.diagram.generateShortcutIcon()-»
else if (navigatorGroup.getParent() instanceof org.eclipse.core.runtime.IAdaptable) {
	navigatorView = (org.eclipse.gmf.runtime.notation.View) ((org.eclipse.core.runtime.IAdaptable) navigatorGroup.getParent()).getAdapter(org.eclipse.gmf.runtime.notation.View.class);
}
	«ENDIF-»
«ENDDEFINE»

«DEFINE diagramEditorClassFQName FOR gmfgen::GenNavigator»org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenNavigator-»
«ENDDEFINE»

Back to the top