Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3d3f28823f642394c5179a121947094a9a8723db (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
/*******************************************************************************
 * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
 * 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:
 * 		Juergen Haug (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.ui.behavior.fsm.provider

import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.Multimap
import java.util.Collection
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.etrice.core.fsm.fSM.ModelComponent
import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider
import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase
import org.eclipse.graphiti.mm.pictograms.PictogramElement
import org.eclipse.graphiti.mm.pictograms.PictogramLink
import org.eclipse.graphiti.services.Graphiti

/**
 *  Provides the {@linkplain PictogramElement} objects of the base class diagram.
 *  This is a reverse mapping from room business objects to linked base diagram pictograms.
 * 
 *  TODO: use fsmgenmodel instead
 */
class BaseDiagramProvider {

	val Multimap<EObject, PictogramElement> baseDiagramBusinessObjs = ArrayListMultimap.create

	new(AbstractFSMDiagramTypeProvider diagramTypeProvider) {
		val diagramAccess = diagramTypeProvider.injector.getInstance(DiagramAccessBase)
		val mc = Graphiti.linkService.getBusinessObjectForLinkedPictogramElement(diagramTypeProvider.diagram) as ModelComponent
		val rs = diagramTypeProvider.diagram.eResource.resourceSet
		
		// open base diagrams => causes full recursive update or creation of all base diagrams
		// all base diagrams have to be considered because inherited subgraph could not exist yet
		val baseClasses = newArrayList => [
			var base = mc.base
			while(base !== null && it.add(base)) { 
				base = base.base
			}		
		]
		baseClasses.reverseView.forEach[ base |
			val baseDiagram = diagramAccess.getDiagram(base, rs)	
			if(baseDiagram != null) {
				// create mapping from business object to pictogram elements
				EcoreUtil.ExternalCrossReferencer.find(baseDiagram).forEach [ targetEObj, eFeatureSetting |
					eFeatureSetting.map[getEObject].filter(PictogramLink).map[pictogramElement].forEach [ pe |
						baseDiagramBusinessObjs.put(targetEObj, pe)
					]
				]
				
				// base diagram resource not needed anymore
				rs.resources.remove(baseDiagram.eResource)		
			}	
		]		
	}

	def Collection<PictogramElement> getPictograms(EObject roomObj) {
		if(roomObj == null) emptyList else baseDiagramBusinessObjs.get(roomObj)
	}

}

Back to the top