Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eccccb2e6c4fbd94064d6f2c11a17bb8868823bd (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
/*****************************************************************************
 * 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.provider;

import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
import org.eclipse.papyrus.infra.emf.appearance.style.AnnotationStyleProvider;
import org.eclipse.papyrus.infra.emf.appearance.style.AppearanceStyleProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.engine.ExtendedCSSEngine;
import org.eclipse.papyrus.infra.gmfdiag.css.helper.CSSDOMSemanticElementHelper;
import org.eclipse.papyrus.infra.gmfdiag.css.helper.StringHelper;
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSValue;

/**
 * Standard implementation of Papyrus Custom Style, CSS-based
 *
 * @author Camille Letavernier
 */
//FIXME: Use constants for the CSS Properties elementIcon, qualifiedNameDepth and shadow
@SuppressWarnings("restriction")
public class CSSCustomStyleDelegate implements CustomStyle {

	private View view;

	private ExtendedCSSEngine engine;

	private Element element;

	private static final String NONE = "none";

	private static final String FULL = "full";

	private static int NONE_VALUE = 1000;

	private static int FULL_VALUE = 0;

	private static final AppearanceStyleProvider provider = new AnnotationStyleProvider();

	/**
	 * Constructor
	 *
	 * @param view
	 *        The GMF view on which the custom style is applied
	 * @param engine
	 *        The CSS engine used to handle the custom properties
	 */
	public CSSCustomStyleDelegate(View view, ExtendedCSSEngine engine) {
		this.view = CSSDOMSemanticElementHelper.findPrimaryView(view);
		this.engine = engine;
		this.element = engine.getElement(this.view);
	}

	@Override
	public boolean showElementIcon() {
		EAnnotation displayNameLabelIcon = view.getEAnnotation(VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON);
		if(displayNameLabelIcon != null) {
			return provider.showElementIcon(view);
		}

		CSSValue cssValue = engine.retrievePropertyValue(element, "elementIcon");
		if(cssValue == null) {
			return false;
		}
		return (Boolean)engine.convert(cssValue, Boolean.class, null);
	}

	@Override
	public int getQualifiedNameDepth() {
		EAnnotation qualifiedNameAnnotation = view.getEAnnotation(VisualInformationPapyrusConstants.QUALIFIED_NAME);
		if(qualifiedNameAnnotation != null) {
			return provider.getQualifiedNameDepth(view);
		}

		CSSValue cssValue = engine.retrievePropertyValue(element, "qualifiedNameDepth");
		if(cssValue == null) {
			return NONE_VALUE;
		}

		String cssText = cssValue.getCssText();

		if(StringHelper.equals(FULL, cssText)) {
			return FULL_VALUE;
		}

		if(StringHelper.equals(NONE, cssText)) {
			return NONE_VALUE;
		}

		try {
			int value = Integer.parseInt(cssText);
			return value > 0 ? -value : value;
		} catch (NumberFormatException ex) {
			engine.handleExceptions(ex);
			return NONE_VALUE;
		}
	}

	@Override
	public boolean showShadow() {
		EAnnotation shadowAnnotation = view.getEAnnotation(VisualInformationPapyrusConstants.SHADOWFIGURE);

		if(shadowAnnotation != null) {
			return provider.showShadow(view);
		}

		CSSValue cssValue = engine.retrievePropertyValue(element, "shadow");
		if(cssValue == null) {
			return false;
		}
		return (Boolean)engine.convert(cssValue, Boolean.class, null);
	}

}

Back to the top