| /******************************************************************************* |
| * 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 - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.environment.earth.atmosphere.impl; |
| |
| import java.util.Date; |
| |
| import org.eclipse.apogy.core.environment.ApogyCoreEnvironmentFacade; |
| import org.eclipse.apogy.core.environment.ApogyCoreEnvironmentPackage; |
| import org.eclipse.apogy.core.environment.earth.atmosphere.ApogyEarthAtmosphereEnvironmentFactory; |
| import org.eclipse.apogy.core.environment.earth.atmosphere.EarthAtmosphereWorksite; |
| import org.eclipse.apogy.core.environment.earth.surface.ApogyEarthSurfaceEnvironmentFacade; |
| import org.eclipse.apogy.core.environment.earth.surface.EarthSky; |
| import org.eclipse.emf.common.notify.Adapter; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| public class ApogyEarthAtmosphereFacadeCustomImpl extends ApogyEarthAtmosphereFacadeImpl { |
| |
| private static final Logger Logger = LoggerFactory.getLogger(ApogyEarthAtmosphereFacadeImpl.class); |
| |
| private Adapter activeWorksiteAdapter = null; |
| |
| protected ApogyEarthAtmosphereFacadeCustomImpl() { |
| super(); |
| |
| // Register to the ApogyCoreEnvironmentFacade for changes in the active |
| // worksite. |
| ApogyCoreEnvironmentFacade.INSTANCE.eAdapters().add(getWorksiteAdapter()); |
| |
| if (ApogyCoreEnvironmentFacade.INSTANCE.getActiveWorksite() instanceof EarthAtmosphereWorksite) { |
| setActiveEarthAtmosphereWorksite( |
| (EarthAtmosphereWorksite) ApogyCoreEnvironmentFacade.INSTANCE.getActiveWorksite()); |
| } |
| } |
| |
| public EarthAtmosphereWorksite createAndInitializeDefaultCSAEarthAtmosphereWorksite() { |
| EarthAtmosphereWorksite worksite = null; |
| |
| try { |
| Date now = new Date(); |
| |
| // Initialise the worksite. |
| worksite = ApogyEarthAtmosphereEnvironmentFactory.eINSTANCE.createEarthAtmosphereWorksite(); |
| worksite.setName("CSA AT"); |
| worksite.setDescription("The CSA Default Worksite."); |
| |
| // Sets the coordinates. |
| worksite.setGeographicalCoordinates( |
| ApogyEarthSurfaceEnvironmentFacade.INSTANCE.getMarsYardGeographicalCoordinates()); |
| |
| // Creates the Earth Sky. |
| EarthSky earthSky = ApogyEarthSurfaceEnvironmentFacade.INSTANCE |
| .createEarthSky(worksite.getGeographicalCoordinates()); |
| |
| // Sets the worksite sky. |
| worksite.setSky(earthSky); |
| earthSky.setWorksite(worksite); |
| |
| // Sets time stamp. |
| worksite.getEarthSky().setTime(now); |
| } catch (Exception e) { |
| Logger.error(e.getMessage(), e); |
| } |
| |
| return worksite; |
| } |
| |
| /** |
| * Adapter that listens to the active AbstractWorksite and updates the active |
| * EarthSurfaceWorksite. |
| * |
| * @return The adapter. |
| */ |
| private Adapter getWorksiteAdapter() { |
| |
| if (this.activeWorksiteAdapter == null) { |
| this.activeWorksiteAdapter = new AdapterImpl() { |
| @Override |
| public void notifyChanged(Notification msg) { |
| if (msg.getNotifier() instanceof ApogyCoreEnvironmentFacade) { |
| int featureID = msg.getFeatureID(ApogyCoreEnvironmentFacade.class); |
| |
| switch (featureID) { |
| case ApogyCoreEnvironmentPackage.APOGY_CORE_ENVIRONMENT_FACADE__ACTIVE_WORKSITE: { |
| if (msg.getNewValue() == null) { |
| setActiveEarthAtmosphereWorksite(null); |
| } else if (msg.getNewValue() instanceof EarthAtmosphereWorksite) { |
| setActiveEarthAtmosphereWorksite((EarthAtmosphereWorksite) msg.getNewValue()); |
| } |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| } |
| }; |
| } |
| return this.activeWorksiteAdapter; |
| } |
| |
| } // ApogyEarthAtmosphereFacadeImpl |