Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5af93bde68231f42e2e2e08accf1d938e8901b7b (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
/*****************************************************************************
 * 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:
 *   Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
 *****************************************************************************/
package aspects.xpt.editor.palette

import javax.inject.Inject
import javax.inject.Singleton
import org.eclipse.emf.ecore.xmi.XMLResource
import org.eclipse.gmf.codegen.gmfgen.AbstractToolEntry
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator
import org.eclipse.gmf.codegen.gmfgen.ToolEntry
import org.eclipse.gmf.codegen.gmfgen.ToolGroup
import xpt.Common
import xpt.Common_qvto

/**
 * Template for generation of palette configuration model from gmfgen.
 */
@Singleton class PaletteConfiguration {
	
	@Inject extension Common
	@Inject extension Common_qvto;
	@Inject extension Utils_qvto;
	
	/**
	 * Generate a palette configuration.
	 */
	def PaletteConfiguration(GenEditorGenerator it) '''
<?xml version="1.0" encoding="ASCII"?>
«xmlGeneratedTag»
<paletteconfiguration:PaletteConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:paletteconfiguration="http://www.eclipse.org/papyrus/diagram/paletteconfiguration/0.8"
	xmlns:elementtypesconfigurations="http://www.eclipse.org/papyrus/infra/elementtypesconfigurations/1.2"
	id="«plugin.ID».paletteconfiguration"
	label="«plugin.name» Palette"
	description="This is the palette of «plugin.name»">
	«FOR tool : diagram.palette.groups»
	«addDrawerConfigurations(tool)»
	«ENDFOR»
</paletteconfiguration:PaletteConfiguration>
	'''
	
	/**
	 * Generate drawer configurations.
	 */
	def addDrawerConfigurations(ToolGroup it) '''
<drawerConfigurations
	id=«IF isQuoted(id,'"')»«id»«ELSE»"«id»"«ENDIF»
	label="«it.title»"
	description="«description»">
	<icon pluginID="«retrieveBundleId(smallIconPath,palette.diagram.editorGen.plugin.ID)»" iconPath="«retrieveLocalPath(smallIconPath)»"/>
	«FOR entry : entries»
		«IF entry instanceof ToolEntry  && isValidTool(entry as AbstractToolEntry)»
			«addToolConfiguration(entry as ToolEntry)»
		«ENDIF»
		«IF entry instanceof ToolGroup»
			«addStackConfiguration(entry as ToolGroup)»
		«ENDIF»
	«ENDFOR»
</drawerConfigurations>
'''
	
	/**
	 * Add tool configuration.
	 */
	def addToolConfiguration(ToolEntry it) '''
<ownedConfigurations xsi:type="paletteconfiguration:ToolConfiguration"
	id=«IF isQuoted(id,'"')»«id»«ELSE»"«id»"«ENDIF» 
	label="«title»"
	«IF null!=qualifiedToolName && !qualifiedToolName.empty»
		toolClassName="«qualifiedToolName»"
	«ENDIF»
	description="«description»"«IF genNodes.empty && !genLinks.empty» kind="ConnectionTool"«ENDIF»>
	<icon pluginID="«retrieveBundleId(smallIconPath,group.palette.diagram.editorGen.plugin.ID)»" iconPath="«retrieveLocalPath(smallIconPath)»"/>
	«IF elements.empty && (null==qualifiedToolName || qualifiedToolName.empty)»
		«ERROR('No elements for tool generation (Palette):'+title)»
	«ENDIF»
	«FOR e : elements»
		«val href = getElementTypeConfHRef(e.elementType.uniqueIdentifier,eResource as XMLResource)»
		«IF null!=href && !href.empty»
			<elementDescriptors>
				<elementType
					xsi:type="«getConfigurationXsiType(e.elementType.uniqueIdentifier,eResource as XMLResource)»"
					href="«href»"/>
			</elementDescriptors>
		«ELSEIF null==qualifiedToolName || qualifiedToolName.empty»
			«ERROR('No element type configuration or classToolName for tool generation (Palette):' + title)»
		«ENDIF»
	«ENDFOR»
</ownedConfigurations>
 	'''
 	
 	/**
 	 * Add stack configuration.
 	 */
 	def addStackConfiguration(ToolGroup it) '''
<ownedConfigurations xsi:type="paletteconfiguration:StackConfiguration" id=«IF isQuoted(id,'"')»«id»«ELSE»"«id»"«ENDIF» label="«title»">
	«FOR entry : entries»
		«IF entry instanceof ToolEntry && isValidTool(entry as AbstractToolEntry)»
			«addToolConfiguration(entry as ToolEntry)»
		«ENDIF»
	«ENDFOR»
</ownedConfigurations>
	'''
}

Back to the top