| /******************************************************************************* |
| * 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.earth.surface.ui.parts; |
| |
| import java.util.HashMap; |
| |
| import javax.inject.Inject; |
| |
| import org.eclipse.apogy.common.emf.ui.parts.AbstractEObjectSelectionPart; |
| import org.eclipse.apogy.core.environment.earth.surface.ui.ApogyCoreEnvironmentSurfaceEarthUIRCPConstants; |
| import org.eclipse.apogy.core.environment.surface.Map; |
| import org.eclipse.apogy.core.environment.surface.ui.composites.OtherLayersComposite; |
| import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
| import org.eclipse.e4.ui.workbench.modeling.EPartService; |
| import org.eclipse.e4.ui.workbench.modeling.ISelectionListener; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public class OtherLayersPart extends AbstractEObjectSelectionPart { |
| @Inject |
| protected EPartService ePartService; |
| |
| private OtherLayersComposite otherLayersComposite; |
| |
| @Override |
| protected EObject getInitializeObject() { |
| if (super.getInitializeObject() == null) { |
| this.eObject = getInitialMap(); |
| } |
| |
| return this.eObject; |
| } |
| |
| @Override |
| protected void setCompositeContents(EObject eObject) { |
| if (eObject instanceof Map) { |
| Map map = (Map) eObject; |
| this.otherLayersComposite.setMap(map); |
| } |
| } |
| |
| @Override |
| protected void createContentComposite(Composite parent, int style) { |
| |
| this.otherLayersComposite = new OtherLayersComposite(parent, SWT.BORDER); |
| } |
| |
| @Override |
| protected HashMap<String, ISelectionListener> getSelectionProvidersIdsToSelectionListeners() { |
| HashMap<String, ISelectionListener> map = new HashMap<>(); |
| |
| map.put(ApogyCoreEnvironmentSurfaceEarthUIRCPConstants.PART__MAPS__ID, new ISelectionListener() { |
| @Override |
| public void selectionChanged(MPart part, Object selection) { |
| if (selection instanceof Map) { |
| Map map = (Map) selection; |
| setEObject(map); |
| } |
| } |
| }); |
| |
| return map; |
| } |
| |
| private Map getInitialMap() { |
| Map map = null; |
| MPart part = this.ePartService.findPart(ApogyCoreEnvironmentSurfaceEarthUIRCPConstants.PART__MAPS__ID); |
| if (part != null && part.getObject() instanceof MapsPart) { |
| MapsPart mapsPart = (MapsPart) part.getObject(); |
| map = mapsPart.getSelectedMap(); |
| } |
| return map; |
| } |
| } |