| /******************************************************************************* |
| * Copyright (c) 2008-2011 Chair for Applied Software Engineering, |
| * Technische Universitaet Muenchen. |
| * 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: |
| ******************************************************************************/ |
| package org.eclipse.emf.emfstore.internal.server.model.versioning.operations.impl; |
| |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.ecore.EAttribute; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| import org.eclipse.emf.emfstore.internal.common.model.IdEObjectCollection; |
| import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.AbstractOperation; |
| import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.AttributeOperation; |
| import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.OperationsFactory; |
| import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.OperationsPackage; |
| import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.UnkownFeatureException; |
| import org.eclipse.emf.emfstore.internal.server.model.versioning.operations.UnsetType; |
| |
| /** |
| * <!-- begin-user-doc --> An implementation of the model object ' <em><b>Attribute Operation</b></em>'. <!-- |
| * end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * </p> |
| * <ul> |
| * <li> |
| * {@link org.eclipse.emf.emfstore.internal.server.model.versioning.operations.impl.AttributeOperationImpl#getOldValue |
| * <em>Old Value</em>}</li> |
| * <li> |
| * {@link org.eclipse.emf.emfstore.internal.server.model.versioning.operations.impl.AttributeOperationImpl#getNewValue |
| * <em>New Value</em>}</li> |
| * </ul> |
| * |
| * @generated |
| */ |
| public class AttributeOperationImpl extends FeatureOperationImpl implements AttributeOperation { |
| /** |
| * The default value of the '{@link #getOldValue() <em>Old Value</em>}' attribute. |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @see #getOldValue() |
| * @generated |
| * @ordered |
| */ |
| protected static final Object OLD_VALUE_EDEFAULT = null; |
| |
| /** |
| * The cached value of the '{@link #getOldValue() <em>Old Value</em>}' attribute. |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @see #getOldValue() |
| * @generated |
| * @ordered |
| */ |
| protected Object oldValue = OLD_VALUE_EDEFAULT; |
| |
| /** |
| * The default value of the '{@link #getNewValue() <em>New Value</em>}' attribute. |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @see #getNewValue() |
| * @generated |
| * @ordered |
| */ |
| protected static final Object NEW_VALUE_EDEFAULT = null; |
| |
| /** |
| * The cached value of the '{@link #getNewValue() <em>New Value</em>}' attribute. |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @see #getNewValue() |
| * @generated |
| * @ordered |
| */ |
| protected Object newValue = NEW_VALUE_EDEFAULT; |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| protected AttributeOperationImpl() { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() { |
| return OperationsPackage.Literals.ATTRIBUTE_OPERATION; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| public Object getOldValue() { |
| return oldValue; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| public void setOldValue(Object newOldValue) { |
| final Object oldOldValue = oldValue; |
| oldValue = newOldValue; |
| if (eNotificationRequired()) { |
| eNotify(new ENotificationImpl(this, Notification.SET, OperationsPackage.ATTRIBUTE_OPERATION__OLD_VALUE, |
| oldOldValue, oldValue)); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| public Object getNewValue() { |
| return newValue; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| public void setNewValue(Object newNewValue) { |
| final Object oldNewValue = newValue; |
| newValue = newNewValue; |
| if (eNotificationRequired()) { |
| eNotify(new ENotificationImpl(this, Notification.SET, OperationsPackage.ATTRIBUTE_OPERATION__NEW_VALUE, |
| oldNewValue, newValue)); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| switch (featureID) { |
| case OperationsPackage.ATTRIBUTE_OPERATION__OLD_VALUE: |
| return getOldValue(); |
| case OperationsPackage.ATTRIBUTE_OPERATION__NEW_VALUE: |
| return getNewValue(); |
| } |
| return super.eGet(featureID, resolve, coreType); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public void eSet(int featureID, Object newValue) { |
| switch (featureID) { |
| case OperationsPackage.ATTRIBUTE_OPERATION__OLD_VALUE: |
| setOldValue(newValue); |
| return; |
| case OperationsPackage.ATTRIBUTE_OPERATION__NEW_VALUE: |
| setNewValue(newValue); |
| return; |
| } |
| super.eSet(featureID, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public void eUnset(int featureID) { |
| switch (featureID) { |
| case OperationsPackage.ATTRIBUTE_OPERATION__OLD_VALUE: |
| setOldValue(OLD_VALUE_EDEFAULT); |
| return; |
| case OperationsPackage.ATTRIBUTE_OPERATION__NEW_VALUE: |
| setNewValue(NEW_VALUE_EDEFAULT); |
| return; |
| } |
| super.eUnset(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) { |
| switch (featureID) { |
| case OperationsPackage.ATTRIBUTE_OPERATION__OLD_VALUE: |
| return OLD_VALUE_EDEFAULT == null ? oldValue != null : !OLD_VALUE_EDEFAULT.equals(oldValue); |
| case OperationsPackage.ATTRIBUTE_OPERATION__NEW_VALUE: |
| return NEW_VALUE_EDEFAULT == null ? newValue != null : !NEW_VALUE_EDEFAULT.equals(newValue); |
| } |
| return super.eIsSet(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated |
| */ |
| @Override |
| public String toString() { |
| if (eIsProxy()) { |
| return super.toString(); |
| } |
| |
| final StringBuffer result = new StringBuffer(super.toString()); |
| result.append(" (oldValue: "); //$NON-NLS-1$ |
| result.append(oldValue); |
| result.append(", newValue: "); //$NON-NLS-1$ |
| result.append(newValue); |
| result.append(')'); |
| return result.toString(); |
| } |
| |
| public void apply(IdEObjectCollection project) { |
| final EObject object = project.getModelElement(getModelElementId()); |
| |
| if (object == null) { |
| // silently fail |
| return; |
| } |
| |
| EAttribute attribute; |
| try { |
| attribute = (EAttribute) this.getFeature(object); |
| switch (getUnset().getValue()) { |
| case UnsetType.IS_UNSET_VALUE: |
| object.eUnset(attribute); |
| break; |
| case UnsetType.NONE_VALUE: |
| object.eSet(attribute, getNewValue()); |
| break; |
| case UnsetType.WAS_UNSET_VALUE: |
| object.eSet(attribute, getNewValue()); |
| break; |
| } |
| } catch (final UnkownFeatureException e) { |
| // fail silently |
| return; |
| } |
| } |
| |
| @Override |
| public AbstractOperation reverse() { |
| final AttributeOperation attributeOperation = OperationsFactory.eINSTANCE.createAttributeOperation(); |
| super.reverse(attributeOperation); |
| // swap old and new value |
| attributeOperation.setNewValue(getOldValue()); |
| attributeOperation.setOldValue(getNewValue()); |
| |
| setUnsetForReverseOperation(attributeOperation); |
| |
| return attributeOperation; |
| } |
| |
| } // AttributeOperationImpl |