Skip to main content
summaryrefslogtreecommitdiffstats
blob: 39cc9655c0361cdd9f4b1dd9b9056fa5ef3107d0 (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
/*******************************************************************************
 * Copyright (c) 2012 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:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.ui.behavior.fsm.editor;

import java.io.File;

import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.fSM.State;
import org.eclipse.etrice.core.fsm.fSM.StateGraph;
import org.eclipse.etrice.ui.behavior.fsm.support.util.FSMSupportUtil;
import org.eclipse.etrice.ui.common.base.editor.DiagramExporter;
import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase;
import org.eclipse.ui.PlatformUI;

import com.google.inject.Inject;

public class BehaviorExporter {

	private static final String SUFFIX = "_behavior";
	
	@Inject
	private DiagramAccessBase da;

	public void export(ModelComponent mc, String folder) {

		boolean wasOpen = false;
		AbstractFSMEditor editor = (AbstractFSMEditor) da.findDiagramEditor(mc);
		if (editor!=null)
			wasOpen = true;
		else
			editor = (AbstractFSMEditor) da.openDiagramEditor(mc);

		if (editor!=null) {
			String filename = folder+File.separatorChar+mc.getComponentName()+SUFFIX;
			DiagramExporter.export(editor, filename);
			
			exportSubGraphsRecursively(mc.getStateMachine(), editor, folder+File.separatorChar+mc.getComponentName());
			
			if (!wasOpen)
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
		}
	}

	private void exportSubGraphsRecursively(StateGraph sg, AbstractFSMEditor editor, String basename) {
		if (sg==null)
			return;
		
		for (State state : sg.getStates()) {
			if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(state)) {
				if (editor.showStateGraph(state.getSubgraph())) {
					String filename = basename+"_"+FSMSupportUtil.getInstance().getFSMNameProvider().getStatePathName(state)+SUFFIX;
					DiagramExporter.export(editor, filename);
				}
				
				exportSubGraphsRecursively(state.getSubgraph(), editor, basename);
			}
		}
	}
}

Back to the top