Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5487ad9f5fc813a5cd28d40a48417e3b73908b7b (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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*******************************************************************************
 * Copyright (c) 2010 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:
 * 		Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.core.ui.labeling;

import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.etrice.core.common.base.AnnotationAttribute;
import org.eclipse.etrice.core.common.base.AnnotationType;
import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ActorInstanceMapping;
import org.eclipse.etrice.core.room.ActorRef;
import org.eclipse.etrice.core.room.Attribute;
import org.eclipse.etrice.core.room.Binding;
import org.eclipse.etrice.core.room.CompoundProtocolClass;
import org.eclipse.etrice.core.room.DataClass;
import org.eclipse.etrice.core.room.EnumLiteral;
import org.eclipse.etrice.core.room.EnumerationType;
import org.eclipse.etrice.core.room.ExternalPort;
import org.eclipse.etrice.core.room.ExternalType;
import org.eclipse.etrice.core.room.Import;
import org.eclipse.etrice.core.room.LogicalSystem;
import org.eclipse.etrice.core.room.LogicalThread;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.Operation;
import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.PortOperation;
import org.eclipse.etrice.core.room.PrimitiveType;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.core.room.SAP;
import org.eclipse.etrice.core.room.SPP;
import org.eclipse.etrice.core.room.ServiceImplementation;
import org.eclipse.etrice.core.room.SimpleState;
import org.eclipse.etrice.core.room.StandardOperation;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.SubProtocol;
import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.core.room.SubSystemRef;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.jface.resource.FontDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;
import org.eclipse.xtext.ui.label.StylerFactory;

import com.google.inject.Inject;

/**
 * Provides labels for a EObjects.
 * 
 * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
 */
public class RoomLabelProvider extends DefaultEObjectLabelProvider {

	private static final String KEYWORD_COLOR = "KEYWORD_COLOR";

	@Inject
	private StylerFactory stylerFactory;
	private Styler keywordStyler = null;
	private Styler typeStyler = null;
	
	@Inject
	public RoomLabelProvider(AdapterFactoryLabelProvider delegate) {
		super(delegate);
		
		JFaceResources.getColorRegistry().put(KEYWORD_COLOR, new RGB(50, 50, 50));
	}

	// custom images for ROOM classes
	
	String image(RoomModel rm) {
		return "RoomModel.gif";
	}
	
	String image(Import im) {
		return "RoomModelImport.gif";
	}
	
	String image(DataClass dc) {
		return "DataClass.gif";
	}
	
	String image(PrimitiveType pt) {
		return "PrimitiveType.gif";
	}
	
	String image(ExternalType et) {
		return "ExternalType.gif";
	}
	
	String image(Attribute a) {
		return "Attribute.gif";
	}

	String image(ProtocolClass pc) {
		return "ProtocolClass.gif";
	}

	String image(CompoundProtocolClass pc) {
		return "CompoundProtocolClass.gif";
	}

	String image(SubProtocol pc) {
		return "SubProtocol.gif";
	}

	String image(ActorClass ac) {
		return "ActorClass.gif";
	}

	String image(SubSystemClass cc) {
		return "SubSystemClass.gif";
	}

	String image(LogicalSystem sys) {
		return "LogicalSystem.gif";
	}

	String image(SAP sap) {
		return "SAP.gif";
	}

	String image(SPP spp) {
		return "SPP.gif";
	}

	String image(ActorRef ar) {
		return "ActorRef.gif";
	}

	String image(SubSystemRef ar) {
		return "SubSystemRef.gif";
	}

	String image(SimpleState state) {
		return "State.gif";
	}

	String image(RefinedState state) {
		return "RefinedState.gif";
	}
	
	String image(ServiceImplementation svc) {
		return "ServiceImpl.gif";
	}

	String image(Message state) {
		if (state.isPriv())
			return "MessagePrivate.gif";
		else
			return "Message.gif";
	}

	String image(Operation op) {
		if (op instanceof PortOperation && ((PortOperation) op).getSendsMsg()!=null)
			return "OperationMsg.gif";
		else
			return "Operation.gif";
	}
	
	String image(Port p) {
		boolean relay = RoomHelpers.isRelay(p);
		if (relay)
			if (p.isConjugated())
				if (p.isReplicated())
					return "ConjReplRelayPort.gif";
				else
					return "ConjRelayPort.gif";
			else
				if (p.isReplicated())
					return "ReplRelayPort.gif";
				else
					return "RelayPort.gif";
		else
			if (p.isConjugated())
				if (p.isReplicated())
					return "ConjReplPort.gif";
				else
					return "ConjPort.gif";
			else
				if (p.isReplicated())
					return "ReplPort.gif";
				else
					return "Port.gif";
	}
	
	String image(ActorInstanceMapping aim) {
		return "actorInstanceMapping.gif";
	}
	String image(LogicalThread lt) {
		return "LogicalThread.gif";
	} 
	
	String image(AnnotationType at) {
		return "annotation_obj.gif";
	}
	
	String image(AnnotationAttribute aa) {
		return "Attribute.gif";
	}
	
	String image(EnumerationType et) {
		return "EnumerationType.gif";
	}
	
	String image(EnumLiteral lit) {
		return "EnumLiteral.gif";
	}
	
	// custom labels
	
	StyledString text(Import im) {
		if (im.getImportedNamespace()==null) {
			StyledString txt = new StyledString("import model "+im.getImportURI());
			txt.setStyle(0, 12, getKeywordStyler());
			return txt;
		}
		else {
			StyledString txt = new StyledString("import ns "+im.getImportedNamespace());
			txt.setStyle(0, 9, getKeywordStyler());
			return txt;
		}
	}
	
	String text(DataClass dc) {
		String base = dc.getBase()!=null? " extends "+dc.getBase().getName():"";
		return dc.getName()+base;
	}
	
	String text(PrimitiveType pt) {
		return pt.getName()+" -> "+pt.getTargetName();
	}
	
	String text(ExternalType et) {
		return et.getName()+" -> "+et.getTargetName();
	}
	
	String text(ProtocolClass pc) {
		String base = pc.getBase()!=null? " extends "+pc.getBase().getName():"";
		return pc.getName()+base;
	}
	
	String text(SubProtocol pc) {
		return pc.getName()+": "+pc.getProtocol().getName();
	}
	
	String text(ActorClass ac) {
		String base = ac.getBase()!=null? " extends "+ac.getBase().getName():"";
		return ac.getName()+base;
	}
	
	String text(Port p) {
		String location = null;
		if (RoomHelpers.isInternal(p))
			location = "internal";
		else if (RoomHelpers.isExternal(p)) {
			location = "external";
		}
		else
			location = "relay";
		String conjugated = p.isConjugated()?"conjugated ":"";
		String multiplicity = p.getMultiplicity()>1? ("["+p.getMultiplicity()+"]") : p.getMultiplicity()==-1? "[*]" : "";
		String protocol = p.getProtocol()!=null? (" : "+p.getProtocol().getName()):"";
		return conjugated+" "+location+" Port "+p.getName()+multiplicity+protocol;
	}
	
	String text(Binding bind) {
		return RoomNameProvider.getDisplayName(bind);
	}
	
	String text(ExternalPort ep) {
		return text(ep.getInterfacePort());
	}
	
	String text(SAP sap) {
		String protocol = sap.getProtocol()!=null? (" : "+sap.getProtocol().getName()):"";
		return "SAP "+sap.getName()+protocol;
	}
	
	String text(SPP spp) {
		String protocol = spp.getProtocol()!=null? (" : "+spp.getProtocol().getName()):"";
		return "SPP "+spp.getName()+protocol;
	}
	
	String text(ServiceImplementation svc) {
		if (svc.getSpp()==null)
			return "Implementation";
		
		String protocol = svc.getSpp().getProtocol()!=null? (" : "+svc.getSpp().getProtocol().getName()):"";
		return "Implementation of "+svc.getSpp().getName()+protocol;
	}
	
	StyledString text(ActorRef ref) {
		String cls = ref.getType()!=null? (" : "+ref.getType().getName()):"";
		StyledString txt = new StyledString("ref "+ref.getName()+cls);
		if (!cls.isEmpty())
			txt.setStyle(txt.length()-cls.length()+2, cls.length()-2, getTypeStyler());
		return txt;
	}
	
	String text(SubSystemRef ref) {
		String cls = ref.getType()!=null? (" : "+ref.getType().getName()):"";
		return "ref "+ref.getName()+cls;
	}
	
	String text(Attribute attr) {
		String type = attr.getType().getType()!=null? (" : "+attr.getType().getType().getName()):"";
		String value = (attr.getDefaultValueLiteral()!=null && !attr.getDefaultValueLiteral().isEmpty())?
				(" = "+attr.getDefaultValueLiteral()) : "";
		String mult = attr.getSize()>1? ("["+attr.getSize()+"]") : "";
		return "Attr "+attr.getName()+mult+type+value;
	}
	
	StyledString text(Operation op) {
		/* TODO TS: create complete signature including return type and ref */

		String signature = RoomHelpers.getSignature(op);
		String special = RoomHelpers.isConstructor(op)? "ctor " : RoomHelpers.isDestructor(op)? "dtor " : "";
		if (op instanceof PortOperation && ((PortOperation) op).getSendsMsg()!=null) {
		}
		String destr = (op instanceof StandardOperation && ((StandardOperation)op).isDestructor())? "~":"";
		StyledString result = new StyledString(special+destr+signature);
		int pos = result.toString().indexOf(" sends ");
		if (pos>=0)
			result.setStyle(pos+1, 5, getKeywordStyler());

		if (!special.isEmpty())
			result.setStyle(0, 4, getKeywordStyler());
		
		return result;
	}
	
	String text(Message m) {
		String signature = "";
		if (m.getData()!=null)
			signature = m.getData().getName()+":"+m.getData().getRefType().getType().getName();
		signature = "("+signature+")";
		return m.getName()+signature;
	}
	
	String text(State s) {
		return s.getName();
	}

	String text(ActorInstanceMapping aim) {
		return aim.getPath().toString()+" -> "+aim.getThread().getName();
	}
	
	String text (LogicalThread lt ) {
		return lt.getName();		
	}
	
	StyledString text(EnumerationType et) {
		StyledString txt = new StyledString("enum "+et.getName());
		txt.setStyle(0, 4, getKeywordStyler());
		return txt;
	}
	
	String text (EnumLiteral lit) {
		return lit.getName()+" = "+lit.getLiteralValue();		
	}
	
	private Styler getKeywordStyler() {
		if (keywordStyler==null) {
			FontDescriptor font = JFaceResources.getFontDescriptor(JFaceResources.TEXT_FONT);
			FontDescriptor boldFont = font.setStyle(SWT.BOLD);
			keywordStyler = stylerFactory.createStyler(boldFont, KEYWORD_COLOR, null);
		}
		return keywordStyler;
	}

	private Styler getTypeStyler() {
		if (typeStyler==null) {
			FontDescriptor font = JFaceResources.getFontDescriptor(JFaceResources.TEXT_FONT);
			FontDescriptor italicFont = font.setStyle(SWT.ITALIC);
			typeStyler = stylerFactory.createStyler(italicFont, null, null);
		}
		return typeStyler;
	}
}

Back to the top