Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 962deb0b53d3c445e977cae44823dee366bd7120 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*****************************************************************************
 * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
 * 
 * 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:
 *   CEA LIST - initial API and implementation
 *   Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 510587: the palette must not be generated by using GMF gen
 *****************************************************************************/
package aspects.xpt.plugin

import aspects.xpt.Common
import aspects.xpt.editor.palette.Utils_qvto
import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.Iterator
import java.util.List
import org.eclipse.emf.ecore.EObject
import org.eclipse.gmf.codegen.gmfgen.AbstractToolEntry
import org.eclipse.gmf.codegen.gmfgen.GenCompartment
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator
import org.eclipse.gmf.codegen.gmfgen.GenExternalNodeLabel
import org.eclipse.gmf.codegen.gmfgen.GenLink
import org.eclipse.gmf.codegen.gmfgen.GenLinkLabel
import org.eclipse.gmf.codegen.gmfgen.GenPlugin
import org.eclipse.gmf.codegen.gmfgen.ToolEntry
import org.eclipse.gmf.codegen.gmfgen.ToolGroup
import org.eclipse.papyrus.papyrusgmfgenextension.ExtendedGenView
import org.eclipse.papyrus.papyrusgmfgenextension.LabelVisibilityPreference
import xpt.editor.extensions
import xpt.plugin.pluginUtils
import java.io.File

@Singleton class plugin extends xpt.plugin.plugin {

	@Inject extension Common
	@Inject extension pluginUtils
	@Inject extension Utils_qvto

	@Inject extensions xptEditorExtension
	@Inject xpt.diagram.preferences.extensions xptPreferencesExtension
	@Inject xpt.propsheet.extensions xptPropsheetExtension
	@Inject xpt.navigator.extensions xptNavigatorExtension
	@Inject xpt.application.extensions xptApplicationExtension
	@Inject xpt.diagram.updater.extensions xptUpdaterExtension
	@Inject impl.actions.extensions xptActionExtension
	@Inject xpt.providers.extensions xptProvidersExtension

	override plugin(GenPlugin it) '''
		<?xml version="1.0" encoding="UTF-8"?>
		<?eclipse version="3.0"?>
		«xcopyright(it.editorGen)»
		<plugin>
		««««fileTypes()»
		««««extension_parser()»
		«xptEditorExtension.extensions(it.editorGen)»
		«««global actions handled in the diagram.common plugin
		««««pluginMenu()»
		«validation(it.editorGen.diagram)»
		«IF it.editorGen.metrics != null»«metrics(it.editorGen.metrics)»«ENDIF»
		«««RS: redefine palette generation
«««		«palettePredefinedEntries(editorGen)»
«««		«paletteEntries(editorGen)»
		«xptPreferencesExtension.extensions(it.editorGen.diagram)»
		«IF it.editorGen.propertySheet != null»«xptPropsheetExtension.extensions(it.editorGen.propertySheet)»«ENDIF»
		«xptProvidersExtension.extensions(it.editorGen.diagram)»
		«IF it.editorGen.navigator != null»«xptNavigatorExtension.extensions(it.editorGen.navigator)»«ENDIF»
		«IF it.editorGen.application != null»«xptApplicationExtension.extensions(it.editorGen.application)»«ENDIF»
		«extensionsConstraintProviders(it.editorGen)»
		«xptUpdaterExtension.extensions(it.editorGen.diagramUpdater)»
		«xptActionExtension.Main(it.editorGen)»
		«additions(it)»
		«notationTypesMap(editorGen)»
«««		«paletteConfiguration(editorGen)»
		</plugin>
	'''
	
	
	/**
	 * deprecated: palette configuration are now declared through architecture model.
	 */
	def paletteConfiguration(GenEditorGenerator it) '''
<extension point="org.eclipse.papyrus.infra.gmfdiag.common.paletteDefinition">
	«xmlGeneratedTag»
	<paletteDefinition
		ID="«plugin.ID».paletteconfiguration"
		class="org.eclipse.papyrus.infra.gmfdiag.common.service.palette.ExtendedPluginPaletteProvider"
		name="«plugin.name» Palette"
		path="«relativePath»/«modelID».paletteconfiguration"
		provider="Eclipse Modeling Project">
		<Priority
			name="Lowest">
		</Priority>
		<!-- Specify diagram to which this palette tool relates -->
		<editor
			id="«plugin.ID»">
		</editor>
	</paletteDefinition>
</extension>
	'''

	override additions(GenPlugin it) ''''''

	//	def category(GenDiagram it) '''«getDiagramPreferencePageCategory()».«editorGen.modelID»'''

	//RS: redefine palette generation, using predefined entries
	def palettePredefinedEntries(GenEditorGenerator it) '''
		«xmlGeneratedTag»
		<extension
			id="«plugin.name».palettedefinition"
			name="«plugin.name» Predefined Entries"
			point="org.eclipse.gmf.runtime.diagram.ui.paletteProviders"> 
			
			«xmlGeneratedTag»	
			<paletteProvider class="org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider">
				<Priority name="Lowest"/>
				   		<contribution
				   		    	factoryClass="«it.diagram.palette.packageName».«it.diagram.palette.factoryClassName»">
				   		<predefinedEntry id="standardGroup/noteStack/noteTool" remove="true"/> 
				<predefinedEntry id="standardGroup/noteStack/textTool" remove="true"/> 
				<predefinedEntry id="standardGroup/noteStack/noteattachmentTool" remove="true"/>
				
				«FOR tool : collectTools(diagram.palette)»
					«predefinedEntryDefinition(tool)»
				«ENDFOR»
				
				</contribution>
			</paletteProvider>	
				
		</extension>
	'''

	//RS: redefine palette generation, using predefined entries
	def paletteEntries(GenEditorGenerator it) '''
		«xmlGeneratedTag»
		<extension
			id="«plugin.name».standard"
			name="«plugin.name» Standard Palette"
			point="org.eclipse.gmf.runtime.diagram.ui.paletteProviders"> 
			
			«xmlGeneratedTag»	
			<paletteProvider class="org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider">
				<Priority name="Low"/>
				   		<contribution
				   		    	factoryClass="«it.diagram.palette.packageName».«it.diagram.palette.factoryClassName»">
				   		<predefinedEntry id="standardGroup/noteStack/noteTool" remove="true"/> 
				<predefinedEntry id="standardGroup/noteStack/textTool" remove="true"/> 
				<predefinedEntry id="standardGroup/noteStack/noteattachmentTool" remove="true"/>
				
				«FOR tool : diagram.palette.groups»
					«groupUsage(tool)»
				«ENDFOR»
				</contribution>
				<editor id="«plugin.ID»"/>
			</paletteProvider>	
				
		</extension>
	'''

	def groupUsage(ToolGroup it) '''
		<entry
		      description="«it.description»"
		      id=«IF isQuoted(id,'"')»«id»«ELSE»"«id»"«ENDIF»
		      kind="«IF it.stack && it.toolsOnly»stack«ELSE»drawer«ENDIF»"
		      label="«it.title»"
		      large_icon="«largeIconPath»"
		      path="«getPath(it)»"
		      small_icon="«smallIconPath»">
		   <expand
		         force="true">
		   </expand>
		</entry>
		««« TODO: call sub entries... 
		«FOR entry : it.entries.filter[e| e instanceof ToolEntry]»
			«toolUsage(entry, it)»
		«ENDFOR»
		«FOR entry : it.entries.filter[e| e instanceof ToolGroup]»
			«toolUsage(entry, it)»
		«ENDFOR»
	'''

	private def getPath(ToolEntry it) {
		return buildPath(it.eContainer);
	}

	private def getPath(ToolGroup it) {
		return buildPath(it.eContainer);
	}

	private def buildPath(EObject it) {
		var path = new StringBuilder();
		var container = it;
		while (container instanceof ToolGroup) {
			path.insert(0, getToolPath((container as ToolGroup).id));
			container = container.eContainer;
		}
		return if(path.length() != 0) path.toString else "/" ;
	}
	
	def dispatch toolUsage(ToolEntry it, ToolGroup group) '''
 		<predefinedEntry
 		        id=«IF isQuoted(id,'"')»«id»«ELSE»"«id»"«ENDIF»
 				path="«getPath(it)»">
 		  </predefinedEntry>
 	'''

	def dispatch toolUsage(ToolGroup it, ToolGroup group) '''
		«groupUsage(it)»
	'''

	def predefinedEntryDefinition(AbstractToolEntry it) '''
		<entry
		      defineOnly="true"
		      description="«it.description»"
		      id=«IF isQuoted(id,'"')»«id»«ELSE»"«id»"«ENDIF»
		      kind="tool"
		      label="«it.title»"
		      large_icon="«largeIconPath»"
		      path=""
		      small_icon="«smallIconPath»">
		</entry>
	'''
	
	//	set notation type mapping extension point
	def notationTypesMap(GenEditorGenerator it) '''	
«tripleSpace(0)»<extension point="org.eclipse.papyrus.infra.gmfdiag.common.notationTypesMapping"> 
«tripleSpace(1)»«xmlGeneratedTag»
«tripleSpace(1)»<diagramMappings diagramID="«modelID»">
«tripleSpace(1)»	<mapping type="«modelID»" humanReadableType="«modelID.replaceAll('Papyrus|UML|Diagram', '')»Diagram"/>
			«FOR compartment : diagram.compartments»
				«compartmentToTypeMap(compartment)»
			«ENDFOR»
			«FOR link : diagram.links»
				«linksToTypeMap(link)»
			«ENDFOR»
			«FOR externalLabel : diagram.eResource.allContents.filter(typeof (GenExternalNodeLabel)).toIterable»
				«floatingLabelToTypeMap(externalLabel)»
				«externalNodeLabelToTypeMap(externalLabel)»
			«ENDFOR»
«tripleSpace(1)»</diagramMappings>
«tripleSpace(0)»</extension>
	'''
	def compartmentToTypeMap(GenCompartment it) '''
		<mapping
			humanReadableType="«title.replaceAll('Compartment', '')»"
			type="«stringVisualID»">
		</mapping>
	'''

	def linksToTypeMap(GenLink it) '''
		«FOR label : labels»
			«linkLabelToTypeMap(label)»
		«ENDFOR»
	'''
	
	def linkLabelToTypeMap(GenLinkLabel it)'''
	«««	it is used on a LabelVisibilityPreference...
		«LabelVisibilityPreferenceToTypeMap(it.eResource.allContents.filter(typeof (LabelVisibilityPreference)).filter[v | v.linkLabels != null && v.linkLabels.contains(it) && v.role != null], stringVisualID)»	
	'''
	
	def externalNodeLabelToTypeMap(GenExternalNodeLabel it)'''
		«LabelVisibilityPreferenceToTypeMap(it.eResource.allContents.filter(typeof (LabelVisibilityPreference)).filter[v | v.externalNodeLabels != null && v.externalNodeLabels.contains(it) && v.role != null],stringVisualID)»	
	'''
	
	def LabelVisibilityPreferenceToTypeMap(Iterator<LabelVisibilityPreference> it, String visualID)'''
	«var List<LabelVisibilityPreference> links = it.toList»
	«IF links.size != 0»
		<mapping
			humanReadableType="«links.get(0).role»"
			type="«visualID»">
		</mapping>
	«ENDIF»	
	'''
		
	def floatingLabelToTypeMap(GenExternalNodeLabel it)'''
	«««	it is used on a ExtensionGenView...
	«IF it.eResource.allContents.filter(typeof (ExtendedGenView)).filter[v | v.genView.contains(it) && v.superOwnedEditPart != null].size != 0»
	«FOR extendedObject : it.eResource.allContents.filter(typeof (ExtendedGenView)).filter[v|v.genView.contains(it) && v.superOwnedEditPart != null].toIterable»
				«««...to be extended as floatingLabel			
				«IF "FloatingLabelEditPart".equals(extendedObject.name) »
					<mapping
						humanReadableType="Floating Label"
						type="«stringVisualID»">
					</mapping>
				«ENDIF»
	«ENDFOR»
	«ENDIF»	
	'''
}

Back to the top