| /******************************************************************************* |
| * 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, |
| * Olivier L. Larouche - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.invocator.provider; |
| |
| import java.util.Collection; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.apogy.common.emf.ApogyCommonEMFFacade; |
| import org.eclipse.apogy.common.emf.edit.utils.ApogyCommonEMFEditUtilsFacade; |
| import org.eclipse.apogy.core.invocator.ApogyCoreInvocatorPackage; |
| import org.eclipse.apogy.core.invocator.EClassArgument; |
| import org.eclipse.emf.common.command.Command; |
| import org.eclipse.emf.common.notify.AdapterFactory; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.EClassifier; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.emf.edit.command.SetCommand; |
| import org.eclipse.emf.edit.domain.EditingDomain; |
| import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
| import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| |
| public class EClassArgumentCustomItemProvider extends EClassArgumentItemProvider { |
| public EClassArgumentCustomItemProvider(AdapterFactory adapterFactory) { |
| super(adapterFactory); |
| } |
| |
| // FIXME Item Provider not required anymore. |
| |
| @Override |
| protected void addValuePropertyDescriptor(Object object) { |
| this.itemPropertyDescriptors.add( |
| new ItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), |
| getResourceLocator(), getString("_UI_EClassArgument_value_feature"), |
| getString("_UI_PropertyDescriptor_description", "_UI_EClassArgument_value_feature", |
| "_UI_EClassArgument_type"), |
| ApogyCoreInvocatorPackage.Literals.ECLASS_ARGUMENT__VALUE, true, false, false, null, null, |
| null) { |
| @Override |
| protected Collection<?> getComboBoxObjects(Object object) { |
| EClassArgument eClassArgument = (EClassArgument) object; |
| |
| /** |
| <<<<<<< HEAD |
| * List of EClasses is returned but the property value is expecting an EObject. |
| * The SetCommand is overridden to handle this. It instantiates the EObject |
| * based on the EClass selected. |
| ======= |
| * List of EClasses is returned but the property value |
| * is expecting an EObject. The SetCommand is overridden |
| * to handle this. It instantiates the EObject based on |
| * the EClass selected. |
| >>>>>>> refs/heads/eclipse_pa |
| * |
| * @see #createSetCommand |
| */ |
| List<EClass> eClasses = ApogyCommonEMFFacade.INSTANCE |
| .getAllSubEClasses((EClass) eClassArgument.getEParameter().getEType()); |
| return eClasses; |
| } |
| }); |
| } |
| |
| @Override |
| protected Command createSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Object value) { |
| |
| if (feature == ApogyCoreInvocatorPackage.Literals.ECLASS_ARGUMENT__VALUE) { |
| if (value instanceof EClass) { |
| return new SetCommand(domain, owner, feature, EcoreUtil.create((EClass) value)); |
| } |
| } |
| return super.createSetCommand(domain, owner, feature, value); |
| } |
| |
| @Override |
| protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { |
| super.collectNewChildDescriptors(newChildDescriptors, object); |
| |
| /** Remove Default EObject. */ |
| ApogyCommonEMFEditUtilsFacade.INSTANCE.removeChildDescriptor(newChildDescriptors, |
| ApogyCoreInvocatorPackage.Literals.ECLASS_ARGUMENT__VALUE); |
| |
| EClassArgument eClassArgument = (EClassArgument) object; |
| EClassifier eClassifier = eClassArgument.getEParameter().getEType(); |
| if (eClassifier instanceof EClass) { |
| Iterator<EClass> eClasses = ApogyCommonEMFFacade.INSTANCE.getAllSubEClasses((EClass) eClassifier) |
| .iterator(); |
| while (eClasses.hasNext()) { |
| EClass currentEClass = eClasses.next(); |
| newChildDescriptors.add(createChildParameter(ApogyCoreInvocatorPackage.Literals.ECLASS_ARGUMENT__VALUE, |
| EcoreUtil.create(currentEClass))); |
| } |
| } |
| |
| } |
| } |