blob: 99618fd5045a87f4f13e918d077a879cf83fd6ef [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.sensors.fov.bindings.impl;
import java.util.Map;
import org.eclipse.apogy.addons.sensors.fov.AngularSpan;
import org.eclipse.apogy.addons.sensors.fov.ApogyAddonsSensorsFOVPackage;
import org.eclipse.apogy.addons.sensors.fov.CircularSectorFieldOfView;
import org.eclipse.apogy.addons.sensors.fov.DistanceRange;
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 CircularSectorFieldOfViewBindingCustomImpl extends CircularSectorFieldOfViewBindingImpl {
private AdapterImpl adapter;
@Override
public AbstractTopologyBinding clone(Map<Node, Node> originalToCopyNodeMap) {
CircularSectorFieldOfViewBindingCustomImpl fovBindingCopy = EcoreUtil.copy(this);
fovBindingCopy.setFov((CircularSectorFieldOfView) originalToCopyNodeMap.get(this.getFov()));
return fovBindingCopy;
}
@Override
public Class<?> getSupportedFeatureType() {
return CircularSectorFieldOfView.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 CircularSectorFieldOfView) {
CircularSectorFieldOfView oldFOV = (CircularSectorFieldOfView) notification.getOldValue();
oldFOV.eAdapters().remove(getAdapter());
if (oldFOV.getAngularSpan() != null) {
oldFOV.getAngularSpan().eAdapters().remove(getAdapter());
}
if (oldFOV.getRange() != null) {
oldFOV.getRange().eAdapters().remove(getAdapter());
}
}
valueChanged(notification.getNewValue());
if (notification.getNewValue() instanceof CircularSectorFieldOfView) {
CircularSectorFieldOfView newFOV = (CircularSectorFieldOfView) notification.getNewValue();
newFOV.eAdapters().add(getAdapter());
if (newFOV.getAngularSpan() != null) {
newFOV.getAngularSpan().eAdapters().add(getAdapter());
}
if (newFOV.getRange() != null) {
newFOV.getRange().eAdapters().add(getAdapter());
}
}
} else if (notification.getNotifier() instanceof CircularSectorFieldOfView) {
if (notification.getFeatureID(
CircularSectorFieldOfView.class) == ApogyAddonsSensorsFOVPackage.CIRCULAR_SECTOR_FIELD_OF_VIEW__RANGE) {
if (notification.getOldValue() instanceof DistanceRange) {
DistanceRange oldDistanceRange = (DistanceRange) notification.getOldValue();
oldDistanceRange.eAdapters().remove(getAdapter());
}
if (notification.getNewValue() instanceof DistanceRange) {
DistanceRange newDistanceRange = (DistanceRange) notification.getNewValue();
newDistanceRange.eAdapters().add(getAdapter());
updateDistanceRange(newDistanceRange);
}
} else if (notification.getFeatureID(
CircularSectorFieldOfView.class) == ApogyAddonsSensorsFOVPackage.CIRCULAR_SECTOR_FIELD_OF_VIEW__ANGULAR_SPAN) {
if (notification.getOldValue() instanceof AngularSpan) {
AngularSpan oldAngularSpan = (AngularSpan) notification.getOldValue();
oldAngularSpan.eAdapters().remove(getAdapter());
}
if (notification.getNewValue() instanceof AngularSpan) {
AngularSpan newAngularSpan = (AngularSpan) notification.getNewValue();
newAngularSpan.eAdapters().add(getAdapter());
updateAngularSpan(newAngularSpan);
}
}
} else if (notification.getNotifier() instanceof DistanceRange) {
DistanceRange distanceRange = (DistanceRange) notification.getNotifier();
// Updates.
updateDistanceRange(distanceRange);
} else if (notification.getNotifier() instanceof AngularSpan) {
AngularSpan angularSpan = (AngularSpan) notification.getNotifier();
// Updates.
updateAngularSpan(angularSpan);
}
}
};
}
return this.adapter;
}
private void updateDistanceRange(DistanceRange newDistanceRange) {
getFov().getRange().setMinimumDistance(newDistanceRange.getMinimumDistance());
getFov().getRange().setMaximumDistance(newDistanceRange.getMaximumDistance());
}
private void updateAngularSpan(AngularSpan newAngularSpan) {
getFov().getAngularSpan().setMinimumAngle(newAngularSpan.getMinimumAngle());
getFov().getAngularSpan().setMaximumAngle(newAngularSpan.getMaximumAngle());
}
@Override
protected void valueChanged(Object newValue) {
if (newValue instanceof CircularSectorFieldOfView) {
// Just update everything.
CircularSectorFieldOfView sourceFOV = (CircularSectorFieldOfView) newValue;
getFov().setDescription(sourceFOV.getDescription());
// Updates Range.
if (sourceFOV.getRange() != null) {
updateDistanceRange(sourceFOV.getRange());
} else {
getFov().setRange(null);
}
// Updates AngularSpan
if (sourceFOV.getAngularSpan() != null) {
updateAngularSpan(sourceFOV.getAngularSpan());
} else {
getFov().setAngularSpan(null);
}
}
}
} // CircularSectorFieldOfViewBindingImpl