Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 493a16d85cd7e7bcf899641a29bb15cb2526906b (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*******************************************************************************
 * Copyright (c) 2012 Jayant Gupta
 * 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:
 * 		Jayant Gupta (initial contribution)
 * 
 * 
 *******************************************************************************/

package org.eclipse.etrice.ui.layout.preferences;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.jface.util.Util;
import org.eclipse.jface.viewers.TreeNode;

import de.cau.cs.kieler.core.util.Pair;

/**
 * A class to represent Domain Model Elements(classes of eTrice). The class
 * extends {@code TreeNode} which helps in :
 * <ul>
 * <li>Representing the class hierarchy
 * <li>Making it a valid object to be passes to {@code TreeNodeContentProvider},
 * thus eliminates the need of a custom Content Provider.
 * </ul>
 * 
 * @author jayant
 * 
 */
public class ETriceDomainModelElement extends TreeNode {

	/**
	 * Constructs a new instance of {@code ETriceDomainModelElement} with the
	 * given id and no children.
	 * 
	 * @param id
	 *            The String which represents the Fully Qualified Domain Name of
	 *            the Class
	 * 
	 * @author jayant
	 */
	public ETriceDomainModelElement(String id) {
		super(id.substring(id.lastIndexOf('.') + 1));
		this.id = id;
	}

	/**
	 * Constructs a new instance of {@code ETriceDomainModelElement} with given
	 * id and array of children
	 * 
	 * @param id
	 *            The String which represents the Fully Qualified Domain Name of
	 *            the Class
	 * @param children
	 *            The array of children fo this element(node)
	 * 
	 * @author jayant
	 */
	public ETriceDomainModelElement(String id,
			ETriceDomainModelElement[] children) {
		super(id.substring(id.lastIndexOf('.') + 1));
		this.id = id;
		setChildren(children);
	}

	/**
	 * The id of the Domain Model Class. This is a string which is the Fully
	 * Qualified Domain Name of the class.
	 */
	private String id;

	/**
	 * The public instance of {@code ETriceDomainModelElement} which encompasses
	 * the complete class hierarchy of configurable Structure diagram elements
	 */
	public static final ETriceDomainModelElement STRUCTURE_MODEL = new ETriceDomainModelElement(
			"StructureRoot",
			new ETriceDomainModelElement[] {
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.ActorContainerRef",
							new ETriceDomainModelElement[] {
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.ActorRef"),
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.SubSystemRef") }),
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.InterfaceItem",
							new ETriceDomainModelElement[] {
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.Port"),
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.SAPRef"),
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.SPPRef") }),
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.StructureClass",
							new ETriceDomainModelElement[] {
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.ActorContainerClass",
											new ETriceDomainModelElement[] {
													new ETriceDomainModelElement(
															"org.eclipse.etrice.core.room.ActorClass"),
													new ETriceDomainModelElement(
															"org.eclipse.etrice.core.room.SubSystemClass") }),
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.LogicalSystem") }),
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.SAPoint",
							new ETriceDomainModelElement[] {
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.RefSAPoint"),
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.RelaySAPoint") }),
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.SPPoint"),
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.Binding") });

	/**
	 * The public instance of {@code ETriceDomainModelElement} which encompasses
	 * the complete class hierarchy of configurable Behavior diagram elements
	 */
	public static final ETriceDomainModelElement BEHAVIOR_MODEL = new ETriceDomainModelElement(
			"BehaviorRoot",
			new ETriceDomainModelElement[] {
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.StateGraph"),
					new ETriceDomainModelElement(
							"org.eclipse.etrice.core.room.StateGraphItem",
							new ETriceDomainModelElement[] {
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.StateGraphNode",
											new ETriceDomainModelElement[] {
													new ETriceDomainModelElement(
															"org.eclipse.etrice.core.room.ChoicePoint"),
													new ETriceDomainModelElement(
															"org.eclipse.etrice.core.room.State",
															new ETriceDomainModelElement[] {
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.RefinedState"),
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.SimpleState") }),
													new ETriceDomainModelElement(
															"org.eclipse.etrice.core.room.TrPoint",
															new ETriceDomainModelElement[] {
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.EntryPoint"),
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.ExitPoint"),
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.TransitionPoint") }) }),
									new ETriceDomainModelElement(
											"org.eclipse.etrice.core.room.Transition",
											new ETriceDomainModelElement[] {
													new ETriceDomainModelElement(
															"org.eclipse.etrice.core.room.InitialTransition"),
													new ETriceDomainModelElement(
															"org.eclipse.etrice.core.room.NonInitialTransition",
															new ETriceDomainModelElement[] {
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.ContinuationTransition"),
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.CPBranchTransition"),
																	new ETriceDomainModelElement(
																			"org.eclipse.etrice.core.room.TransitionChainStartTransition",
																			new ETriceDomainModelElement[] {
																					new ETriceDomainModelElement(
																							"org.eclipse.etrice.core.room.GuardedTransition"),
																					new ETriceDomainModelElement(
																							"org.eclipse.etrice.core.room.TriggeredTransition") }) }) }) }), });

	/**
	 * public list of {@code Pair<String, <String>>} enumerating all diagram
	 * types relevant for Structure Diagrams
	 */
	@SuppressWarnings("unchecked")
	public static final List<Pair<String, String>> STRUCTURE_DIAGRAM_TYPES = new ArrayList<Pair<String, String>>(
			Arrays.asList(
					new Pair<String, String>(
							"de.cau.cs.kieler.layout.diagrams.gereral",
							"General"),
					new Pair<String, String>(
							"org.eclipse.etrice.ui.layout.eTriceStructureDiagram",
							"eTrice Structure Diagram")));

	/**
	 * public list of {@code Pair<String, <String>>} enumerating all diagram
	 * types relevant for Behavior Diagrams
	 */
	@SuppressWarnings("unchecked")
	public static final List<Pair<String, String>> BEHAVIOR_DIAGRAM_TYPES = new ArrayList<Pair<String, String>>(
			Arrays.asList(
					new Pair<String, String>(
							"de.cau.cs.kieler.layout.diagrams.gereral",
							"General"),
					new Pair<String, String>(
							"org.eclipse.etrice.ui.layout.eTriceBehaviorDiagram",
							"eTrice Behavior Diagram")));

	/**
	 * Finds whether the given id belongs to a particular domain model class
	 * (for behavior diagram elements)
	 * 
	 * @param id
	 *            The id to be checked (found)
	 * @return true, if there is a class in behavior model hierarchy with same
	 *         id, otherwise false
	 */
	public static boolean isBehaviorModelElement(String id) {
		return (BEHAVIOR_MODEL.traverseModel(id));
	}

	/**
	 * Finds whether the given id belongs to a particular domain model class
	 * (for structure diagram elements)
	 * 
	 * @param id
	 *            The id to be found
	 * @return true, if there is a class in structure model hierarchy with same
	 *         id, otherwise false
	 */
	public static boolean isStructureModelElement(String id) {
		return (STRUCTURE_MODEL.traverseModel(id));
	}

	/**
	 * Traverses the n-ary tree recursively from the invoking node and try to
	 * find the given id.
	 * 
	 * @param findId
	 *            The id to be found
	 * @return true, if id matches with any node of the tree (with root as the
	 *         invoking node), otherwise false
	 */
	public boolean traverseModel(final String findId) {

		if (Util.equals(this.id, findId)) {
			return true;
		} else {
			TreeNode[] children = getChildren();
			if (children != null) {
				for (TreeNode child : children) {
					if (((ETriceDomainModelElement) child)
							.traverseModel(findId))
						return true;
				}
			}

			return false;
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author jayant
	 */
	@Override
	public boolean equals(final Object object) {
		if (object instanceof ETriceDomainModelElement) {
			return Util.equals(this.id, ((ETriceDomainModelElement) object).id);
		}

		return false;
	}

	/**
	 * Getter for id
	 * 
	 * @return the id
	 * 
	 * @author jayant
	 */
	public String getId() {
		return id;
	}

	/**
	 * Setter for id
	 * 
	 * @param id
	 *            the id to set
	 * 
	 * @author jayant
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * {@inheritDoc}
	 * <p>
	 * Useful for using this class with default {@code LabelProvider}
	 * 
	 * @author jayant
	 */
	@Override
	public String toString() {
		return ((String) value + " (" + id + ")");
	}

}

Back to the top