Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0f0d874ebfcb368d2fdcfdffed62c92f8921094d (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
/*******************************************************************************
 * 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.provider

import java.util.Map
import org.eclipse.emf.ecore.EObject
import org.eclipse.etrice.core.fsm.fSM.ModelComponent
import org.eclipse.etrice.core.genmodel.fsm.BasicFsmGenBuilder
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider
import org.eclipse.graphiti.dt.IDiagramTypeProvider
import org.eclipse.graphiti.services.Graphiti

class GenModelProvider {

	val BasicFsmGenBuilder builder
	val IDiagramTypeProvider fsmDiagramProvider
	var Map<EObject, EObject> graphMap = newHashMap

	var GraphContainer modelInstance = null

	new(AbstractFSMDiagramTypeProvider fsmDiagramProvider) {
		this.fsmDiagramProvider = fsmDiagramProvider
		builder = new BasicFsmGenBuilder(fsmDiagramProvider.injector)
	}

	def updateModel() {
		Graphiti.linkService.getBusinessObjectForLinkedPictogramElement(fsmDiagramProvider.diagram) => [
			modelInstance = if(it instanceof ModelComponent) builder.createTransformedModel(it) else null
		]
		if (modelInstance != null) {
			graphMap = modelInstance.eAllContents.toMap [
				switch (it) {
					Graph: stateGraph
					Node: stateGraphNode
					Link: transition
				}
			]
		}
	}

	def getModel() {
		if (modelInstance == null) {
			updateModel()
		}

		return modelInstance;
	}

	def <T extends EObject> getCasted(EObject roomObj) {
		return graphMap.get(roomObj) as T
	}
}

Back to the top