| /******************************************************************************* |
| * 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.ApogyAddonsSensorsFOVFacade; |
| import org.eclipse.apogy.addons.sensors.fov.ConicalFieldOfView; |
| 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 ConicalFieldOfViewBindingCustomImpl extends ConicalFieldOfViewBindingImpl { |
| |
| private AdapterImpl adapter; |
| |
| @Override |
| public AbstractTopologyBinding clone(Map<Node, Node> originalToCopyNodeMap) { |
| ConicalFieldOfViewBindingCustomImpl fovBindingCopy = EcoreUtil.copy(this); |
| fovBindingCopy.setFov((ConicalFieldOfView) originalToCopyNodeMap.get(this.getFov())); |
| return fovBindingCopy; |
| } |
| |
| @Override |
| public Class<?> getSupportedFeatureType() { |
| return ConicalFieldOfView.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 ConicalFieldOfView) { |
| ConicalFieldOfView oldFOV = (ConicalFieldOfView) notification.getOldValue(); |
| oldFOV.eAdapters().remove(getAdapter()); |
| } |
| |
| valueChanged(notification.getNewValue()); |
| |
| if (notification.getNewValue() instanceof ConicalFieldOfView) { |
| ConicalFieldOfView newFOV = (ConicalFieldOfView) notification.getNewValue(); |
| newFOV.eAdapters().add(getAdapter()); |
| } |
| } else if (notification.getNotifier() instanceof ConicalFieldOfView) { |
| valueChanged(notification.getNotifier()); |
| } |
| } |
| }; |
| } |
| |
| return this.adapter; |
| } |
| |
| @Override |
| protected void valueChanged(Object newValue) { |
| if (newValue instanceof ConicalFieldOfView) { |
| // Just update everything. |
| ConicalFieldOfView sourceFOV = (ConicalFieldOfView) newValue; |
| |
| getFov().setDescription(sourceFOV.getDescription()); |
| |
| // Updates Range. |
| if (sourceFOV.getRange() != null) { |
| DistanceRange newRange = ApogyAddonsSensorsFOVFacade.INSTANCE.createDistanceRange(sourceFOV.getRange()); |
| getFov().setRange(newRange); |
| } else { |
| getFov().setRange(null); |
| } |
| |
| // Updates FOV Angle. |
| getFov().setFieldOfViewAngle(sourceFOV.getFieldOfViewAngle()); |
| } |
| } |
| |
| } // ConicalFieldOfViewBindingImpl |