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
|
/*****************************************************************************
* 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.properties.modelelement;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSAnnotations;
import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagram;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.creation.StyleSheetFactory;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding.DiagramStyleSheetObservableList;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.provider.CSSStyleSheetContentProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.provider.CSSStyleSheetLabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSClassContentProvider;
import org.eclipse.papyrus.infra.gmfdiag.properties.modelelement.CustomStyleModelElement;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.creation.StringEditionFactory;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
public class CSSModelElement extends CustomStyleModelElement {
public CSSModelElement(View source, DataContextElement context) {
super(source, context);
}
public CSSModelElement(View source, EditingDomain domain, DataContextElement element) {
super(source, domain, element);
}
@Override
public ReferenceValueFactory getValueFactory(String propertyPath) {
if(CSSAnnotations.CSS_DIAGRAM_STYLESHEETS_KEY.equals(propertyPath)) {
return new StyleSheetFactory((View)this.source);
}
if(CSSAnnotations.CSS_GMF_CLASS_KEY.equals(propertyPath)) {
StringEditionFactory factory = new StringEditionFactory();
factory.setContentProvider(getContentProvider(propertyPath));
return factory;
}
return super.getValueFactory(propertyPath);
}
@Override
public IObservable doGetObservable(String propertyPath) {
if(CSSAnnotations.CSS_DIAGRAM_STYLESHEETS_KEY.equals(propertyPath)) {
return new DiagramStyleSheetObservableList((View)source, domain, propertyPath);
}
return super.doGetObservable(propertyPath);
}
@Override
public ILabelProvider getLabelProvider(String propertyPath) {
if(CSSAnnotations.CSS_DIAGRAM_STYLESHEETS_KEY.equals(propertyPath)) {
return new CSSStyleSheetLabelProvider();
}
return super.getLabelProvider(propertyPath);
}
@Override
public IStaticContentProvider getContentProvider(String propertyPath) {
if(propertyPath.equals(CSSAnnotations.CSS_DIAGRAM_STYLESHEETS_KEY)) {
return new CSSStyleSheetContentProvider(source);
}
if(propertyPath.equals(CSSAnnotations.CSS_GMF_CLASS_KEY)) {
Diagram diagram = ((View)source).getDiagram();
if(diagram instanceof CSSDiagram) {
EObject semanticElement = ((View)source).getElement();
if(semanticElement != null) {
//TODO: For Diagrams, we should use the right DiagramKind (See GMFElementAdapter)
//Until then, we list all available classes (*)
String elementName = source instanceof Diagram ? "*" : semanticElement.eClass().getName();
return new CSSClassContentProvider(elementName, ((CSSDiagram)diagram).getEngine());
}
}
return null;
}
return null;
}
}
|