blob: cd5f351fbd5e1039900d9e4845fa784030b86073 (
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
|
/*****************************************************************************
* Copyright (c) 2012 CEA LIST.
*
* 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.css.configuration.providers;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.EmbeddedStyleSheet;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference;
import org.eclipse.papyrus.infra.gmfdiag.css3.CSSRuntimeModule;
import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.ruleset;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.xtext.serializer.ISerializer;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
//TODO: Add a context to this LabelProvider (Selected View)
//TODO: When a Ruleset is applied/applicable on the selected View, change its color
public class StylesheetLabelProvider extends EMFLabelProvider {
@Inject
private ISerializer serializer;
public StylesheetLabelProvider() {
Injector injector = Guice.createInjector(new CSSRuntimeModule());
injector.injectMembers(this);
}
@Override
public String getText(Object element) {
if (element instanceof ruleset) {
return getText((ruleset) element);
}
if (element instanceof StyleSheetReference) {
return getText((StyleSheetReference) element);
}
if (element instanceof EmbeddedStyleSheet) {
return getText((EmbeddedStyleSheet) element);
}
return super.getText(element);
}
public String getText(ruleset ruleset) {
// Delegate the label to XText serialization
String label = "";
if (!ruleset.getSelectors().isEmpty()) {
label += serializer.serialize(ruleset.getSelectors().get(0));
for (int i = 1; i < ruleset.getSelectors().size(); i++) {
label += ", " + serializer.serialize(ruleset.getSelectors().get(i));
}
label = label.trim().replaceAll("\\s+", " ");
}
return label;
}
public String getText(StyleSheetReference stylesheet) {
return stylesheet.getPath();
}
public String getText(EmbeddedStyleSheet stylesheet) {
return stylesheet.getLabel();
}
@Override
public Color getForeground(Object element) {
if (!(element instanceof ruleset)) {
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
}
return super.getForeground(element);
}
@Override
public Image getImage(Object element) {
// if(element instanceof StyleSheetReference) {
// return org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(Activator.PLUGIN_ID, "/icons/sourceEditor.gif");
// }
return null;
}
}
|