| /******************************************************************************* |
| * 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, |
| * Sebastien Gemme - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.environment.impl; |
| |
| import java.util.Date; |
| |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFPackage; |
| import org.eclipse.apogy.common.emf.CurrentTimeSource; |
| import org.eclipse.apogy.common.emf.TimeSource; |
| import org.eclipse.emf.common.notify.Adapter; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| |
| public class ApogyEnvironmentCustomImpl extends ApogyEnvironmentImpl { |
| |
| private Adapter timeSourceAdapter = null; |
| |
| public void setTime(Date newTime) { |
| if (getActiveWorksite() != null) { |
| getActiveWorksite().setTime(newTime); |
| } |
| |
| super.setTime(newTime); |
| } |
| |
| |
| @Override |
| public void setActiveTimeSource(TimeSource newActiveTimeSource) { |
| if (this.activeTimeSource != null) { |
| this.activeTimeSource.eAdapters().remove(getTimeSourceAdapter()); |
| } |
| |
| if (newActiveTimeSource != null) { |
| newActiveTimeSource.eAdapters().add(getTimeSourceAdapter()); |
| setTime(newActiveTimeSource.getTime()); |
| } |
| |
| super.setActiveTimeSource(newActiveTimeSource); |
| |
| if (getActiveTimeSource() instanceof CurrentTimeSource) { |
| CurrentTimeSource currentTimeSource = (CurrentTimeSource) getActiveTimeSource(); |
| |
| if (!currentTimeSource.isPaused()) { |
| currentTimeSource.resume(); |
| } |
| } |
| } |
| |
| 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); |
| if (featureId == ApogyCommonEMFPackage.TIME_SOURCE__TIME) { |
| if (msg.getNewValue() instanceof Date) { |
| Date newDate = (Date) msg.getNewValue(); |
| setTime(new Date(newDate.getTime())); |
| } |
| } |
| } |
| } |
| }; |
| } |
| |
| return this.timeSourceAdapter; |
| } |
| } // ApogyEnvironmentImpl |