Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 61696340b23b091c25ca8cb83abe5c2aff4bae88 (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
/*******************************************************************************
 * Copyright (c) 2013 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:
 * 		Eyrak Paen (initial contribution)
 * 
 *******************************************************************************/
package org.eclipse.etrice.core.common.ui.labeling

import com.google.inject.Inject
import org.eclipse.jface.viewers.StyledString
import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.etrice.core.common.base.Import
import org.eclipse.xtext.ui.label.StylerFactory
import org.eclipse.jface.resource.JFaceResources
import org.eclipse.swt.SWT
import org.eclipse.swt.graphics.RGB

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

	protected static final String KEYWORD_COLOR = "KEYWORD_COLOR";

	@Inject
	protected StylerFactory stylerFactory;
	
	protected Styler keywordStyler = null;
	protected Styler typeStyler = null;
	
	@Inject
	new(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider delegate) {
		super(delegate);
		
		JFaceResources.getColorRegistry().put(KEYWORD_COLOR, new RGB(50, 50, 50));
	}

	def String image(Import mdl) {
		return null;
	}
	
	def StyledString text(Import im) {
		if (im.getImportedNamespace() === null) {
			var txt = new StyledString("import model " + im.getImportURI())
			txt.setStyle(0, 12, getKeywordStyler())
			return txt
		} else {
			var txt = new StyledString("import ns " + im.getImportedNamespace())
			txt.setStyle(0, 9, getKeywordStyler())
			return txt
		}
	}
	
	def protected Styler getKeywordStyler() {
		if (keywordStyler===null) {
			var font = JFaceResources.getFontDescriptor(JFaceResources.TEXT_FONT)
			var boldFont = font.setStyle(SWT.BOLD)
			keywordStyler = stylerFactory.createStyler(boldFont, KEYWORD_COLOR, null)
		}
		return keywordStyler
	}

	def protected Styler getTypeStyler() {
		if (typeStyler===null) {
			var font = JFaceResources.getFontDescriptor(JFaceResources.TEXT_FONT)
			var italicFont = font.setStyle(SWT.ITALIC)
			typeStyler = stylerFactory.createStyler(italicFont, null, null)
		}
		return typeStyler
	}
}

Back to the top