| /******************************************************************************* |
| * 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.core.environment.ui.parts; |
| |
| import org.eclipse.apogy.common.emf.ui.parts.AbstractPart; |
| import org.eclipse.apogy.common.ui.composites.NoContentComposite; |
| import org.eclipse.apogy.core.environment.ApogyCoreEnvironmentFacade; |
| import org.eclipse.apogy.core.environment.ApogyCoreEnvironmentPackage; |
| import org.eclipse.apogy.core.environment.ApogyEnvironment; |
| import org.eclipse.apogy.core.environment.ui.composites.TimeSourcesListComposite; |
| 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.EObject; |
| import org.eclipse.jface.viewers.TreeSelection; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public class TimeSourcesListPart extends AbstractPart { |
| private TimeSourcesListComposite timeSourcesListComposite; |
| private Adapter adapter = null; |
| |
| public TimeSourcesListPart() { |
| // Register adapter to listens for changes in the active apogy environment. |
| ApogyCoreEnvironmentFacade.INSTANCE.eAdapters().add(getApogyCoreEnvironmentFacadeAdapter()); |
| } |
| |
| @Override |
| protected EObject getInitializeObject() { |
| |
| return ApogyCoreEnvironmentFacade.INSTANCE.getActiveApogyEnvironment(); |
| } |
| |
| @Override |
| protected void setCompositeContent(EObject eObject) { |
| if (eObject instanceof ApogyEnvironment) { |
| // Sets the current Apogy Environment. |
| this.timeSourcesListComposite.setTimeSourcesList(((ApogyEnvironment) eObject).getTimeSourcesList()); |
| } else { |
| this.timeSourcesListComposite.setTimeSourcesList(null); |
| } |
| } |
| |
| @Override |
| protected void createNoContentComposite(Composite parent, int style) { |
| new NoContentComposite(parent, SWT.None) { |
| @Override |
| protected String getMessage() { |
| return "No active Apogy Environment"; |
| } |
| }; |
| } |
| |
| @Override |
| protected void createContentComposite(Composite parent, int style) { |
| this.timeSourcesListComposite = new TimeSourcesListComposite(parent, style) { |
| @Override |
| protected void newSelection(TreeSelection selection) { |
| TimeSourcesListPart.this.selectionService |
| .setSelection(((TimeSourcesListComposite) getActualComposite()).getSelectedTimeSource()); |
| } |
| }; |
| } |
| |
| @Override |
| public void dispose() { |
| // Un-Register adapter to listens for changes in the active apogy environment. |
| ApogyCoreEnvironmentFacade.INSTANCE.eAdapters().remove(getApogyCoreEnvironmentFacadeAdapter()); |
| super.dispose(); |
| } |
| |
| private Adapter getApogyCoreEnvironmentFacadeAdapter() { |
| if (this.adapter == null) { |
| this.adapter = 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_APOGY_ENVIRONMENT: { |
| if (msg.getNewValue() instanceof ApogyEnvironment) { |
| setEObject((ApogyEnvironment) msg.getNewValue()); |
| } else { |
| setEObject(null); |
| } |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| } |
| }; |
| } |
| |
| return this.adapter; |
| } |
| |
| } |