blob: 75cec4ce4c448ba64e1a43b3978a2d0b8f00642d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013 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:
* Cedric Dumoulin - cedric.dumoulin@lifl.fr
******************************************************************************/
/**
*/
package org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.impl;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.ColorInstance;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.FillInstance;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.LayersPackage;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.TypeInstance;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Fill Instance</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.impl.FillInstanceImpl#getTransparency <em>Transparency</em>}</li>
* <li>{@link org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.impl.FillInstanceImpl#getFillColor <em>Fill Color</em>}</li>
* </ul>
*
* @generated
*/
public class FillInstanceImpl extends TypeInstanceImpl implements FillInstance {
/**
* The default value of the '{@link #getTransparency() <em>Transparency</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTransparency()
* @generated
* @ordered
*/
protected static final int TRANSPARENCY_EDEFAULT = 0;
/**
* The cached value of the '{@link #getTransparency() <em>Transparency</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTransparency()
* @generated
* @ordered
*/
protected int transparency = TRANSPARENCY_EDEFAULT;
/**
* The cached value of the '{@link #getFillColor() <em>Fill Color</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getFillColor()
* @generated
* @ordered
*/
protected ColorInstance fillColor;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected FillInstanceImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return LayersPackage.Literals.FILL_INSTANCE;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public int getTransparency() {
return transparency;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setTransparency(int newTransparency) {
int oldTransparency = transparency;
transparency = newTransparency;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, LayersPackage.FILL_INSTANCE__TRANSPARENCY, oldTransparency, transparency));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public ColorInstance getFillColor() {
return fillColor;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetFillColor(ColorInstance newFillColor, NotificationChain msgs) {
ColorInstance oldFillColor = fillColor;
fillColor = newFillColor;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, LayersPackage.FILL_INSTANCE__FILL_COLOR, oldFillColor, newFillColor);
if (msgs == null) msgs = notification; else msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setFillColor(ColorInstance newFillColor) {
if (newFillColor != fillColor) {
NotificationChain msgs = null;
if (fillColor != null)
msgs = ((InternalEObject)fillColor).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - LayersPackage.FILL_INSTANCE__FILL_COLOR, null, msgs);
if (newFillColor != null)
msgs = ((InternalEObject)newFillColor).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - LayersPackage.FILL_INSTANCE__FILL_COLOR, null, msgs);
msgs = basicSetFillColor(newFillColor, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, LayersPackage.FILL_INSTANCE__FILL_COLOR, newFillColor, newFillColor));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case LayersPackage.FILL_INSTANCE__FILL_COLOR:
return basicSetFillColor(null, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case LayersPackage.FILL_INSTANCE__TRANSPARENCY:
return getTransparency();
case LayersPackage.FILL_INSTANCE__FILL_COLOR:
return getFillColor();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case LayersPackage.FILL_INSTANCE__TRANSPARENCY:
setTransparency((Integer)newValue);
return;
case LayersPackage.FILL_INSTANCE__FILL_COLOR:
setFillColor((ColorInstance)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case LayersPackage.FILL_INSTANCE__TRANSPARENCY:
setTransparency(TRANSPARENCY_EDEFAULT);
return;
case LayersPackage.FILL_INSTANCE__FILL_COLOR:
setFillColor((ColorInstance)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case LayersPackage.FILL_INSTANCE__TRANSPARENCY:
return transparency != TRANSPARENCY_EDEFAULT;
case LayersPackage.FILL_INSTANCE__FILL_COLOR:
return fillColor != null;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated NOT
*/
@Override
public void setValueFromString(String value) {
if (value == null || value.length() == 0) {
return;
}
// The value should contains the 2 values, separated by comma
// "transparency, fillColor"
String[] values = value.split(",");
try {
setTransparency(Integer.parseInt(values[0].trim()));
getFillColor().setValueFromString(values[1]);
} catch (NumberFormatException e) {
// fail silently
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated NOT
*/
@Override
public void setValueFromInstance(TypeInstance value) {
// Check if the value is of the right instance
if (!getClass().isInstance(value)) {
return;
}
FillInstance instance = (FillInstance) value;
setTransparency(instance.getTransparency());
// Set by copy
getFillColor().setValueFromInstance(instance.getFillColor());
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
if (eIsProxy()) return super.toString();
StringBuffer result = new StringBuffer(super.toString());
result.append(" (transparency: "); //$NON-NLS-1$
result.append(transparency);
result.append(')');
return result.toString();
}
} // FillInstanceImpl