Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 961b5da9d548cd9df771dc9b5f099997f7ae88eb (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
/*******************************************************************************
 * Copyright (c) 2011 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.support

import java.util.Map
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.Diagram
import org.eclipse.graphiti.mm.pictograms.PictogramElement
import org.eclipse.graphiti.mm.pictograms.PictogramLink
import org.eclipse.graphiti.services.Graphiti

/**
 *  Provides the PictogramElements from the base class diagram. Replacement for DefaultPositionProvider.
 */
class BaseDiagramProvider {

	val DiagramAccessBase diagramAccess

	val Map<EObject, PictogramElement> graphElements = newHashMap
	val Map<EObject, PictogramElement> stateElements = newHashMap

	new(AbstractFSMDiagramTypeProvider diagramTypeProvider) {
		diagramAccess = diagramTypeProvider.injector.getInstance(DiagramAccessBase)

		val mc = Graphiti.linkService.getBusinessObjectForLinkedPictogramElement(diagramTypeProvider.diagram)
		if (mc instanceof ModelComponent)
			visitDiagramRec(mc.base)
	}

	def void visitDiagramRec(ModelComponent mc) {
		if(mc == null) return;

		val rs = mc.eResource.resourceSet
		// temporary load base diagram into current resourceSet to link its business objects against current resources
		val diagram = diagramAccess.getDiagram(mc, mc.eResource.resourceSet)
		if (diagram != null) {
			mapPositions(diagram)
			rs.resources.remove(diagram)
		}

	// visitDiagramRec(mc.base)
	}

	def mapPositions(Diagram diagram) {
		// create mapping from business object to pictogram elements
		EcoreUtil.ExternalCrossReferencer.find(diagram).forEach [ crossRef, eFeatureSetting |
			eFeatureSetting.forEach [
				// println(crossRef + " -> " + EObject)
				if (EObject instanceof PictogramLink) {
					val pe = (EObject as PictogramLink).pictogramElement
					graphElements.put(crossRef, pe)
				}
			]
		]
	}

	def getBasePictogram(EObject roomObj) {
		return graphElements.get(roomObj)
	}

}

Back to the top