Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a52096ecc026de19aad0b1008539e32af5e01f62 (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
/******************************************************************************
 * Copyright (c) 2012, 2020 Montages AG, CEA LIST, Artal
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/ 
 * 
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors: 
 *    Michael Golubev (Borland) - initial API and implementation
 *    Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174
 *****************************************************************************/

«IMPORT 'http://www.eclipse.org/papyrus/gmf/2020/GenModel'»

«EXTENSION xpt::GenEditorGenerator»

«DEFINE DomainToNotationClassName FOR gmfgen::GenDiagram»Domain2Notation«ENDDEFINE»

«DEFINE DomainToNotationClass FOR gmfgen::GenDiagram-»
	«EXPAND DomainToNotationClass_One2One-»
«ENDDEFINE»

«DEFINE DomainToNotationClass_One2One FOR gmfgen::GenDiagram-»
    «EXPAND xpt::Common::generatedMemberComment»
	@SuppressWarnings("serial")
	protected static class «EXPAND DomainToNotationClassName» extends «EXPAND CodeStyle::G2('java.util.HashMap', 'org.eclipse.emf.ecore.EObject', 'org.eclipse.gmf.runtime.notation.View')» {
	    «EXPAND xpt::Common::generatedMemberComment»
		public boolean containsDomainElement(org.eclipse.emf.ecore.EObject domainElement){
			return this.containsKey(domainElement);
		}
		
		«EXPAND xpt::Common::generatedMemberComment»
		public org.eclipse.gmf.runtime.notation.View getHinted(org.eclipse.emf.ecore.EObject domainEObject, String hint) {
			return «IF self.jdkComplianceLevel() < 5»(org.eclipse.gmf.runtime.notation.View)«ENDIF»this.get(domainEObject);
		}
		
		«EXPAND xpt::Common::generatedMemberComment»
		public void putView(org.eclipse.emf.ecore.EObject domainElement, org.eclipse.gmf.runtime.notation.View view) {
			«REM»
			Before GMFT 3.0 the call to put() was guarded by the same check in order to store element only once and to prefer non-shortcuts to shortcuts
			As part of the #389368, we moved this guard to callee implementation, to optionally allow *_One2Many case
			«ENDREM»«-»
			if (!containsKey(view.getElement()) «IF getDiagram().containsShortcutsTo->notEmpty()»|| !isShortcut(view)«ENDIF») {
				this.put(domainElement, view);
			}
		}
		
	}
«ENDDEFINE»

«DEFINE DomainToNotationClass_One2Many FOR gmfgen::GenDiagram»
    «EXPAND xpt::Common::generatedMemberComment»
	@SuppressWarnings({"rawtypes", "unchecked"})
	protected static class «EXPAND DomainToNotationClassName» {
	    «EXPAND xpt::Common::generatedMemberComment»
		private final java.util.HashMap myMap = new java.util.HashMap();
		
	    «EXPAND xpt::Common::generatedMemberComment»
		public boolean containsDomainElement(org.eclipse.emf.ecore.EObject domainElement){
			return myMap.containsKey(domainElement);
		}

	    «EXPAND xpt::Common::generatedMemberComment»
		public boolean containsKey(org.eclipse.emf.ecore.EObject domainElement){
			return containsDomainElement(domainElement);
		}
		
	    «EXPAND xpt::Common::generatedMemberComment»
		public void putView(org.eclipse.emf.ecore.EObject domainElement, org.eclipse.gmf.runtime.notation.View view){
			Object viewOrList = myMap.get(domainElement);
			if (viewOrList instanceof org.eclipse.gmf.runtime.notation.View){
				myMap.remove(domainElement);
				java.util.List<org.eclipse.gmf.runtime.notation.View> list = new java.util.LinkedList<org.eclipse.gmf.runtime.notation.View>();
				list.add((org.eclipse.gmf.runtime.notation.View)viewOrList);
				myMap.put(domainElement, list);
				list.add(view);
			} else if (viewOrList instanceof java.util.List){
				((java.util.List)viewOrList).add(view);
			} else {
				myMap.put(domainElement, view);
			}
		}
		
	    «EXPAND xpt::Common::generatedMemberComment»
		public org.eclipse.gmf.runtime.notation.View get(org.eclipse.emf.ecore.EObject domainEObject){
			Object viewOrList = myMap.get(domainEObject);
			if (viewOrList instanceof org.eclipse.gmf.runtime.notation.View){
				return (org.eclipse.gmf.runtime.notation.View)viewOrList;
			}
			if (viewOrList instanceof java.util.List){
				// preferring not-shortcut to shortcut -- important for cases when links arr to/from 
				// the element that is additionally shortcutted to the same diagram
				for (Object next : (java.util.List)viewOrList){
					org.eclipse.gmf.runtime.notation.View nextView = (org.eclipse.gmf.runtime.notation.View)next;
					if (nextView.getEAnnotation("Shortcut") == null) { «EXPAND xpt::Common::nonNLS»
						return nextView;
					}
				}
				return (org.eclipse.gmf.runtime.notation.View)((java.util.List)viewOrList).get(0);
			}
			return null;
		}
		
	    «EXPAND xpt::Common::generatedMemberComment»
		public org.eclipse.gmf.runtime.notation.View getHinted(org.eclipse.emf.ecore.EObject domainEObject, String hint){
			if (hint == null){
				return get(domainEObject);
			}
			Object viewOrList = myMap.get(domainEObject);
			if (viewOrList instanceof org.eclipse.gmf.runtime.notation.View){
				//no choice, will return what we have
				return (org.eclipse.gmf.runtime.notation.View)viewOrList;
			}
			if (viewOrList instanceof java.util.List){ 
				for (Object next : (java.util.List)viewOrList){
					org.eclipse.gmf.runtime.notation.View nextView = (org.eclipse.gmf.runtime.notation.View)next;
					if (hint.equals(nextView.getType())){
						return nextView;
					}
				}
				//hint not found -- return what we have
				return (org.eclipse.gmf.runtime.notation.View)((java.util.List)viewOrList).get(0);
			}
			return null;
		}
	}
«ENDDEFINE»

Back to the top