| /******************************************************************************* |
| * 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.ui.utils; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.emf.common.notify.Notifier; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| import org.eclipse.emf.ecore.EObject; |
| |
| public class MultiEObjectsAdapter extends AdapterImpl { |
| private final List<EObject> eObjects = new ArrayList<EObject>(); |
| |
| @Override |
| public void setTarget(Notifier newTarget) { |
| super.setTarget(newTarget); |
| |
| if (newTarget instanceof EObject) { |
| EObject eObject = (EObject) newTarget; |
| if (!this.eObjects.contains(newTarget)) |
| this.eObjects.add(eObject); |
| } |
| } |
| |
| @Override |
| public void unsetTarget(Notifier oldTarget) { |
| super.unsetTarget(oldTarget); |
| |
| if (oldTarget instanceof EObject) { |
| EObject eObject = (EObject) oldTarget; |
| this.eObjects.remove(eObject); |
| } |
| |
| } |
| |
| public void unregisterFromAllObjects() { |
| List<EObject> tmpList = new ArrayList<EObject>(); |
| tmpList.addAll(this.eObjects); |
| for (EObject eObject : tmpList) { |
| eObject.eAdapters().remove(this); |
| } |
| } |
| |
| public void registerToEObject(EObject eObject) { |
| if (!this.eObjects.contains(eObject)) { |
| eObject.eAdapters().add(this); |
| this.eObjects.add(eObject); |
| } |
| } |
| |
| public void unregisterFromEObject(EObject eObject) { |
| eObject.eAdapters().remove(this); |
| this.eObjects.remove(eObject); |
| } |
| |
| public void dispose() { |
| unregisterFromAllObjects(); |
| } |
| } |