blob: 9a5bd7fc9e6b4ab6f35e9aa4e31492b5f83206f3 [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 org.eclipse.apogy.addons.geometry.paths.ApogyAddonsGeometryPathsFactory;
import org.eclipse.apogy.addons.geometry.paths.WayPointPath;
import org.eclipse.apogy.addons.geometry.paths.WayPointPathBinding;
import org.eclipse.apogy.addons.vehicle.ApogyAddonsVehiclePackage;
import org.eclipse.apogy.addons.vehicle.PathPlannerTool;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
public class PathPlannerToolNodeCustomImpl extends PathPlannerToolNodeImpl {
private Adapter adapter = null;
private WayPointPath plannedPathLocal = null;
private WayPointPathBinding binding = null;
@Override
public NotificationChain basicSetPathPlannerTool(PathPlannerTool newPathPlannerTool, NotificationChain msgs) {
internalUpdatePathPlannerTool(this.pathPlannerTool, newPathPlannerTool);
return super.basicSetPathPlannerTool(newPathPlannerTool, msgs);
}
@Override
public void setPathPlannerTool(PathPlannerTool newPathPlannerTool) {
internalUpdatePathPlannerTool(this.pathPlannerTool, newPathPlannerTool);
super.setPathPlannerTool(newPathPlannerTool);
}
private void internalUpdatePathPlannerTool(PathPlannerTool oldPathPlannerTool, PathPlannerTool newPathPlannerTool) {
if (oldPathPlannerTool != null) {
oldPathPlannerTool.eAdapters().remove(getAdapter());
updateWayPointPath(null);
}
getChildren().clear();
if (newPathPlannerTool != null) {
newPathPlannerTool.eAdapters().add(getAdapter());
updateWayPointPath(newPathPlannerTool.getPlannedPath());
}
}
protected void updateWayPointPath(WayPointPath newWayPointPath) {
if (this.plannedPathLocal != null) {
getChildren().remove(this.plannedPathLocal);
}
if (this.binding != null) {
this.binding.setTargetWayPointPath(null);
this.binding.setSourceWayPointPath(null);
}
if (newWayPointPath != null) {
this.plannedPathLocal = ApogyAddonsGeometryPathsFactory.eINSTANCE.createWayPointPath();
this.plannedPathLocal.setNodeId(newWayPointPath.getNodeId());
this.plannedPathLocal.setDescription(newWayPointPath.getDescription());
this.binding = new WayPointPathBinding(newWayPointPath, this.plannedPathLocal);
getChildren().add(this.plannedPathLocal);
}
}
protected Adapter getAdapter() {
if (this.adapter == null) {
this.adapter = new AdapterImpl() {
@Override
public void notifyChanged(Notification msg) {
if (msg.getNotifier() instanceof PathPlannerTool) {
int featureId = msg.getFeatureID(PathPlannerTool.class);
switch (featureId) {
case ApogyAddonsVehiclePackage.PATH_PLANNER_TOOL__PLANNED_PATH:
updateWayPointPath((WayPointPath) msg.getNewValue());
break;
default:
break;
}
}
}
};
}
return this.adapter;
}
} // PathPlannerToolNodeImpl