Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0d4c303e94102dce59bcab588d2c73194cca3743 (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
/*******************************************************************************
 * 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 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * 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
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.FSMGenElement
import org.eclipse.etrice.core.genmodel.fsm.BasicFsmGenBuilderFactory

class GenModelProvider {

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

	var GraphContainer modelInstance = null

	new(AbstractFSMDiagramTypeProvider fsmDiagramProvider) {
		this.fsmDiagramProvider = fsmDiagramProvider
		builder = fsmDiagramProvider.injector.getInstance(BasicFsmGenBuilderFactory).create
	}

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

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

		return modelInstance;
	}

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

Back to the top