| /******************************************************************************* |
| * 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.surface.orbit.ui.impl; |
| |
| import java.util.Date; |
| |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFPackage; |
| import org.eclipse.apogy.common.emf.TimeSource; |
| import org.eclipse.apogy.common.emf.transaction.ApogyCommonTransactionFacade; |
| import org.eclipse.apogy.core.environment.ApogyCoreEnvironmentFacade; |
| import org.eclipse.apogy.core.environment.ApogyCoreEnvironmentPackage; |
| import org.eclipse.apogy.core.environment.earth.surface.ApogyEarthSurfaceEnvironmentFacade; |
| import org.eclipse.apogy.core.environment.earth.surface.ApogyEarthSurfaceEnvironmentPackage; |
| import org.eclipse.apogy.core.environment.earth.surface.EarthSurfaceWorksite; |
| import org.eclipse.apogy.core.environment.earth.surface.orbit.ui.ApogyEarthSurfaceOrbitEnvironmentUIPackage; |
| import org.eclipse.emf.common.notify.Adapter; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| |
| public abstract class EarthOrbitModelToolCustomImpl extends EarthOrbitModelToolImpl { |
| |
| private Adapter activeEarthSurfaceWorksiteAdapter; |
| private Adapter activeTimeSourceAdapter; |
| private Adapter timeSourceAdapter; |
| |
| @Override |
| public void setActiveTimeSource(TimeSource newActiveTimeSource) { |
| // Unregister from previous time source. |
| if (getActiveTimeSource() != null) |
| getActiveTimeSource().eAdapters().remove(getTimeSourceAdapter()); |
| |
| super.setActiveTimeSource(newActiveTimeSource); |
| |
| // Register to new time source. |
| if (newActiveTimeSource != null) |
| newActiveTimeSource.eAdapters().add(getTimeSourceAdapter()); |
| |
| } |
| |
| @Override |
| public void initialise() { |
| super.initialise(); |
| |
| // Updates the active EarthSurfaceWorksite. |
| updateActiveEarthSurfaceWorksite(ApogyEarthSurfaceEnvironmentFacade.INSTANCE.getActiveEarthSurfaceWorksite()); |
| |
| // Register adapter used to respond to changes in active EarthSurfaceWorksite. |
| ApogyEarthSurfaceEnvironmentFacade.INSTANCE.eAdapters().add(getActiveEarthSurfaceWorksiteAdapter()); |
| |
| // Set the initial TimeSource. |
| setActiveTimeSource(ApogyCoreEnvironmentFacade.INSTANCE.getActiveTimeSource()); |
| |
| // Register adapter used to respond to changes in active ApogyEnvironment. |
| ApogyCoreEnvironmentFacade.INSTANCE.eAdapters().add(getActiveTimeSourceAdapter()); |
| } |
| |
| @Override |
| public void dispose() { |
| // Unregister from the active time source. |
| if (getActiveTimeSource() != null) |
| getActiveTimeSource().eAdapters().remove(getTimeSourceAdapter()); |
| |
| // Un-Register adapter used to respond to changes in active |
| // EarthSurfaceWorksite. |
| ApogyEarthSurfaceEnvironmentFacade.INSTANCE.eAdapters().remove(getActiveEarthSurfaceWorksiteAdapter()); |
| |
| // Un-Register adapter used to respond to changes in active ApogyEnvironment. |
| ApogyCoreEnvironmentFacade.INSTANCE.eAdapters().remove(getActiveTimeSourceAdapter()); |
| |
| super.dispose(); |
| } |
| |
| private void updateActiveEarthSurfaceWorksite(EarthSurfaceWorksite newEarthSurfaceWorksite) { |
| if (getActiveEarthSurfaceWorksite() != newEarthSurfaceWorksite) { |
| // Detach node from old sky. |
| // detachToolNode(); |
| |
| // Updates active worksite. |
| ApogyCommonTransactionFacade.INSTANCE.basicSet(EarthOrbitModelToolCustomImpl.this, |
| ApogyEarthSurfaceOrbitEnvironmentUIPackage.Literals.EARTH_ORBIT_MODEL_TOOL__ACTIVE_EARTH_SURFACE_WORKSITE, |
| ApogyEarthSurfaceEnvironmentFacade.INSTANCE.getActiveEarthSurfaceWorksite(), true); |
| // setActiveEarthSurfaceWorksite(ApogyEarthSurfaceEnvironmentFacade.INSTANCE.getActiveEarthSurfaceWorksite()); |
| |
| // Attaches node to new sky |
| // attachToolNode(); |
| } |
| } |
| |
| /** |
| * Return the Adapter used to monitor the currently active EarthSurfaceWorksite. |
| * |
| * @return The adapter, a singleton. |
| */ |
| private Adapter getActiveEarthSurfaceWorksiteAdapter() { |
| if (this.activeEarthSurfaceWorksiteAdapter == null) { |
| this.activeEarthSurfaceWorksiteAdapter = new AdapterImpl() { |
| @Override |
| public void notifyChanged(Notification msg) { |
| if (msg.getNotifier() instanceof ApogyEarthSurfaceEnvironmentFacade) { |
| int featureId = msg.getFeatureID(ApogyEarthSurfaceEnvironmentFacade.class); |
| switch (featureId) { |
| case ApogyEarthSurfaceEnvironmentPackage.APOGY_EARTH_SURFACE_ENVIRONMENT_FACADE__ACTIVE_EARTH_SURFACE_WORKSITE: { |
| updateActiveEarthSurfaceWorksite( |
| ApogyEarthSurfaceEnvironmentFacade.INSTANCE.getActiveEarthSurfaceWorksite()); |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| } |
| }; |
| } |
| return this.activeEarthSurfaceWorksiteAdapter; |
| } |
| |
| private Adapter getActiveTimeSourceAdapter() { |
| if (this.activeTimeSourceAdapter == null) { |
| this.activeTimeSourceAdapter = 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_TIME_SOURCE: { |
| // Update TimeSource. |
| TimeSource newTimeSource = (TimeSource) msg.getNewValue(); |
| |
| ApogyCommonTransactionFacade.INSTANCE.basicSet(EarthOrbitModelToolCustomImpl.this, |
| ApogyEarthSurfaceOrbitEnvironmentUIPackage.Literals.EARTH_ORBIT_MODEL_TOOL__ACTIVE_TIME_SOURCE, |
| newTimeSource); |
| // setActiveTimeSource(newTimeSource); |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| } |
| }; |
| } |
| return this.activeTimeSourceAdapter; |
| } |
| |
| private Adapter getTimeSourceAdapter() { |
| if (this.timeSourceAdapter == null) { |
| this.timeSourceAdapter = new AdapterImpl() { |
| @Override |
| public void notifyChanged(Notification msg) { |
| if (msg.getNotifier() instanceof TimeSource) { |
| int featureId = msg.getFeatureID(TimeSource.class); |
| switch (featureId) { |
| case ApogyCommonEMFPackage.TIME_SOURCE__TIME: { |
| Date newTime = (Date) msg.getNewValue(); |
| if (newTime != null) |
| updateTime(newTime); |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| } |
| }; |
| } |
| return this.timeSourceAdapter; |
| } |
| |
| } // EarthOrbitModelToolImpl |