blob: eabc39aa7ada3a7cd99caae0af5e4f01bf75c971 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* 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:
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.addons.vehicle.impl;
import java.util.Map;
import org.eclipse.apogy.addons.vehicle.ApogyAddonsVehiclePackage;
import org.eclipse.apogy.addons.vehicle.Thruster;
import org.eclipse.apogy.addons.vehicle.ThrusterBinding;
import org.eclipse.apogy.common.emf.ApogyCommonEMFPackage;
import org.eclipse.apogy.common.emf.FeatureNodeAdapter;
import org.eclipse.apogy.common.topology.Node;
import org.eclipse.apogy.common.topology.bindings.AbstractTopologyBinding;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
public class ThrusterBindingCustomImpl extends ThrusterBindingImpl {
private AdapterImpl adapter;
@Override
public AbstractTopologyBinding clone(Map<Node, Node> originalToCopyNodeMap) {
Thruster thrusterCopy = (Thruster) originalToCopyNodeMap.get(this.getThruster());
ThrusterBinding thrusterBindingCopy = EcoreUtil.copy(this);
thrusterBindingCopy.setThruster(thrusterCopy);
return thrusterBindingCopy;
}
@Override
public Class<?> getSupportedFeatureType() {
return Thruster.class;
}
@Override
protected Adapter getAdapter() {
if (this.adapter == null) {
this.adapter = new AdapterImpl() {
@Override
public void notifyChanged(Notification notification) {
if (notification.getFeatureID(
FeatureNodeAdapter.class) == ApogyCommonEMFPackage.FEATURE_NODE_ADAPTER__CURRENT_VALUE) {
if (notification.getOldValue() instanceof Thruster) {
Thruster oldFOV = (Thruster) notification.getOldValue();
oldFOV.eAdapters().remove(getAdapter());
}
if (notification.getNewValue() instanceof Thruster) {
Thruster newFOV = (Thruster) notification.getNewValue();
newFOV.eAdapters().add(getAdapter());
valueChanged(newFOV);
}
} else if (notification.getNotifier() instanceof ThrusterBinding) {
if (notification.getOldValue() instanceof Thruster) {
Thruster oldThruster = (Thruster) notification.getOldValue();
oldThruster.eAdapters().remove(getAdapter());
}
if (notification.getNewValue() instanceof Thruster) {
Thruster newThruster = (Thruster) notification.getNewValue();
newThruster.eAdapters().add(getAdapter());
valueChanged(newThruster);
}
} else if (notification.getNotifier() instanceof Thruster) {
int featureId = notification.getFeatureID(Thruster.class);
switch (featureId) {
case ApogyAddonsVehiclePackage.THRUSTER__PLUME_ANGLE:
getThruster().setPlumeAngle(notification.getNewDoubleValue());
break;
case ApogyAddonsVehiclePackage.THRUSTER__CURRENT_THRUST:
getThruster().setCurrentThrust(notification.getNewDoubleValue());
break;
case ApogyAddonsVehiclePackage.THRUSTER__MINIMUM_THRUST:
getThruster().setMinimumThrust(notification.getNewDoubleValue());
break;
case ApogyAddonsVehiclePackage.THRUSTER__MAXIMUM_THRUST:
getThruster().setMaximumThrust(notification.getNewDoubleValue());
break;
case ApogyAddonsVehiclePackage.THRUSTER__THRUST_LEVEL:
getThruster().setThrustLevel(notification.getNewDoubleValue());
break;
default:
break;
}
}
}
};
}
return this.adapter;
}
@Override
protected void valueChanged(Object newValue) {
if (newValue instanceof Thruster) {
Thruster sourceThruster = (Thruster) newValue;
getThruster().setCurrentThrust(sourceThruster.getCurrentThrust());
getThruster().setMaximumThrust(sourceThruster.getMaximumThrust());
getThruster().setMinimumThrust(sourceThruster.getMinimumThrust());
getThruster().setPlumeAngle(sourceThruster.getPlumeAngle());
getThruster().setThrustLevel(sourceThruster.getThrustLevel());
}
}
} // ThrusterBindingImpl