Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 86f51d8d2eaae9169940bf75e135dbf5d88811ad (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
/*****************************************************************************
 * 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.style.impl;

import org.eclipse.gmf.runtime.notation.DiagramStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.papyrus.infra.gmfdiag.css.engine.ExtendedCSSEngine;
import org.eclipse.papyrus.infra.gmfdiag.css.style.CSSDiagramStyle;
import org.w3c.dom.css.CSSValue;

public class CSSDiagramStyleDelegate implements CSSDiagramStyle {

	private DiagramStyle diagramStyle;

	private ExtendedCSSEngine engine;

	public CSSDiagramStyleDelegate(DiagramStyle diagramStyle, ExtendedCSSEngine engine) {
		this.diagramStyle = diagramStyle;
		this.engine = engine;
	}

	// //////////////////////////////////////////////
	// Implements a getter for each CSS property //
	// //////////////////////////////////////////////

	@Override
	public int getCSSPageX() {
		CSSValue cssValue = engine.retrievePropertyValue(diagramStyle, "pageX");
		if (cssValue == null) {
			Object defaultValue = NotationPackage.eINSTANCE.getPageStyle_PageX().getDefaultValue();
			return (Integer) defaultValue;
		}
		return (Integer) engine.convert(cssValue, Integer.class, null);
	}

	@Override
	public int getCSSPageY() {
		CSSValue cssValue = engine.retrievePropertyValue(diagramStyle, "pageY");
		if (cssValue == null) {
			Object defaultValue = NotationPackage.eINSTANCE.getPageStyle_PageY().getDefaultValue();
			return (Integer) defaultValue;
		}
		return (Integer) engine.convert(cssValue, Integer.class, null);
	}

	@Override
	public int getCSSPageWidth() {
		CSSValue cssValue = engine.retrievePropertyValue(diagramStyle, "pageWidth");
		if (cssValue == null) {
			Object defaultValue = NotationPackage.eINSTANCE.getPageStyle_PageWidth().getDefaultValue();
			return (Integer) defaultValue;
		}
		return (Integer) engine.convert(cssValue, Integer.class, null);
	}

	@Override
	public int getCSSPageHeight() {
		CSSValue cssValue = engine.retrievePropertyValue(diagramStyle, "pageHeight");
		if (cssValue == null) {
			Object defaultValue = NotationPackage.eINSTANCE.getPageStyle_PageHeight().getDefaultValue();
			return (Integer) defaultValue;
		}
		return (Integer) engine.convert(cssValue, Integer.class, null);
	}

	@Override
	public java.lang.String getCSSDescription() {
		CSSValue cssValue = engine.retrievePropertyValue(diagramStyle, "description");
		if (cssValue == null) {
			Object defaultValue = NotationPackage.eINSTANCE.getDescriptionStyle_Description().getDefaultValue();
			return (String) defaultValue;
		}
		return (String) engine.convert(cssValue, String.class, null);
	}
}

Back to the top