Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 970182d092c812cfa39b6a4ec2dd8f59f6269300 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.eclipse.etrice.ui.layout;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
import org.eclipse.ui.IWorkbenchPart;

import de.cau.cs.kieler.core.kgraph.KGraphData;
import de.cau.cs.kieler.kiml.LayoutContext;
import de.cau.cs.kieler.kiml.LayoutOptionData;
import de.cau.cs.kieler.kiml.config.DefaultLayoutConfig;
import de.cau.cs.kieler.kiml.config.ILayoutConfig;
import de.cau.cs.kieler.kiml.options.LayoutOptions;
import de.cau.cs.kieler.kiml.ui.service.EclipseLayoutConfig;

/**
 * A layout config for option configuration in eTrice. It configures the diagram
 * types of diagram elements based on the domain model and the specific diagram
 * editor.
 * 
 * @author jayant
 */
public class ETriceLayoutConfig implements ILayoutConfig {

	/** The priority for this layout configurations. */
	public static final int PRIORITY = 40;

	/**
	 * The diagram type for the diagram elements in eTrice behavior diagrams.
	 */
	public static final String BEHAVIOR_DIAGRAM_TYPE = "org.eclipse.etrice.ui.layout.eTriceBehaviorDiagram";

	/**
	 * The diagram type for the diagram elements in eTrice structure diagrams.
	 */
	public static final String STRUCTURE_DIAGRAM_TYPE = "org.eclipse.etrice.ui.layout.eTriceStructureDiagram";

	/**
	 * {@inheritDoc}
	 * 
	 * @author jayant
	 */
	@Override
	public int getPriority() {
		return PRIORITY;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author jayant
	 */
	@Override
	public void enrich(LayoutContext context) {
		Object element = context.getProperty(LayoutContext.DOMAIN_MODEL);

		if (element instanceof ActorContainerClass
				|| element instanceof StateGraph) {
			IWorkbenchPart workbenchPart = context
					.getProperty(EclipseLayoutConfig.WORKBENCH_PART);
			Object diagramType = getDiagramType(element, workbenchPart);

			if (diagramType != null)
				context.setProperty(DefaultLayoutConfig.CONTENT_DIAGT,
						diagramType);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author jayant
	 */
	@Override
	public Object getValue(LayoutOptionData<?> optionData, LayoutContext context) {
		if (optionData.getId().equals(LayoutOptions.DIAGRAM_TYPE.getId())) {
			EObject element = context.getProperty(LayoutContext.DOMAIN_MODEL);

			if (element instanceof ActorContainerClass
					|| element instanceof StateGraph) {
				IWorkbenchPart workbenchPart = context
						.getProperty(EclipseLayoutConfig.WORKBENCH_PART);
				return getDiagramType(element, workbenchPart);
			}
		}

		return null;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author jayant
	 */
	@Override
	public void transferValues(KGraphData graphData, LayoutContext context) {
		// not required : no other options to set dynamically
	}

	/**
	 * Returns the diagram type(string) for a domain model element depending
	 * upon the diagram editor which contains the corresponding diagram element
	 * 
	 * @param modelElement
	 *            the domain model element
	 * @param workbenchPart
	 *            the editor containing the corresspnding diagram element
	 * @return the diagram type for the domain model element
	 * 
	 * @author jayant
	 */
	private String getDiagramType(final Object modelElement,
			IWorkbenchPart workbenchPart) {
		if (modelElement instanceof StateGraph) {
			return BEHAVIOR_DIAGRAM_TYPE;
		} else if (modelElement instanceof ActorContainerClass) {
			if (workbenchPart instanceof BehaviorEditor)
				return BEHAVIOR_DIAGRAM_TYPE;
			else
				return STRUCTURE_DIAGRAM_TYPE;
		}

		return null;
	}
}

Back to the top