Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c9a2fffc2bf43e445d5dbb88f71d7b7f781ab779 (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
/*****************************************************************************
 * Copyright (c) 2017 CEA LIST and Others.
 *
 * 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:
 * 	Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
 *  
 *****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;

import java.math.BigDecimal;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;

/**
 *
 * Implementation for an ObservableValue associated to a GMF custom style (DoubleValueStyle).
 *
 */
public class CustomDoubleStyleObservableValue extends AbstractCustomStyleObservableValue {

	/**
	 * Default double value.
	 */
	private final static double DEFAULT_VALUE = 0.0;

	/**
	 * 
	 * Constructor.
	 *
	 * @param source
	 *            the view source
	 * @param domain
	 *            the editing domain
	 * @param styleName
	 *            the style name
	 */
	public CustomDoubleStyleObservableValue(final View source, final EditingDomain domain, final String styleName) {
		super(source, domain, styleName, NotationPackage.eINSTANCE.getDoubleValueStyle(), NotationPackage.eINSTANCE.getDoubleValueStyle_DoubleValue());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object getValueType() {
		return EcorePackage.eINSTANCE.getEFloat();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Object getDefaultValue() {
		return DEFAULT_VALUE;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Object doGetValue() {
		return super.doGetValue();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Command getCommand(final Object value) {
		if (value instanceof Double) {
			return super.getCommand(value);
		} else if (value instanceof Float) {
			BigDecimal number = new BigDecimal((Float) value);
			return super.getCommand(number.doubleValue());
		}
		throw new IllegalArgumentException("The value " + value + " is not a valid Double Value"); //$NON-NLS-1$ //$NON-NLS-2$
	}
}

Back to the top