Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d6b0af38fa202709f9151a7d44d2b7fe96aa4011 (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
/*****************************************************************************
 * Copyright (c) 2011 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.properties.databinding;

import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.gmf.runtime.notation.datatype.GradientData;

/**
 * An ObservableValue for GradientData
 * The GradientData is not a pure EMF object
 * 
 * @author Camille Letavernier
 */
public class GradientDataObservableValue extends AbstractObservableValue {

	private GradientData data;

	private GradientProperty property;

	/**
	 * 
	 * Constructor.
	 * 
	 * @param data
	 *        The GradientData to observe
	 * @param property
	 *        The name of the property to observe
	 */
	public GradientDataObservableValue(GradientData data, String property) {
		this.data = data;
		this.property = GradientProperty.valueOf(property);
	}

	public Object getValueType() {
		return Object.class;
	}

	@Override
	protected Object doGetValue() {
		if(data == null) {
			return null;
		}

		switch(property) {
		case gradientColor1:
			return data.getGradientColor1();
		case gradientColor2:
			return data.getGradientColor2();
		case gradientStyle:
			return data.getGradientStyle();
		case activate:
			if(data instanceof ObservableGradientData) {
				return ((ObservableGradientData)data).getActivate();
			} else {
				return true;
			}
		}

		return null;
	}

	@Override
	protected void doSetValue(Object value) {
		if(data == null) {
			return;
		}

		switch(property) {
		case gradientColor1:
			data.setGradientColor1((Integer)value);
			break;
		case gradientColor2:
			data.setGradientColor2((Integer)value);
			break;
		case gradientStyle:
			data.setGradientStyle((Integer)value);
			break;
		case activate:
			if(data instanceof ObservableGradientData) {
				((ObservableGradientData)data).setActivate((Boolean)value);
			}
		}
	}

	/**
	 * The list of properties that can be used by the GradientDataObservableValue
	 * 
	 * @author Camille Letavernier
	 */
	public static enum GradientProperty {
		/**
		 * The gradientColor2 property
		 * (In Papyrus diagrams, it is actually the fillColor that is used
		 * instead of the gradientColor2)
		 */
		gradientColor2,

		/**
		 * The gradientColor1 property
		 */
		gradientColor1,

		/**
		 * The gradientStyle property (Vertical or Horizontal)
		 */
		gradientStyle,

		/**
		 * Whether the gradient is activated or not
		 */
		activate
	}

}

Back to the top