/** * Copyright (c) 2002-2005 IBM Corporation and others. * 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: * IBM - Initial API and implementation * Michal Antkiewicz - modifications */ package ca.uwaterloo.gsd.fsml.ecoreview.provider; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.ResourceLocator; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.EcoreFactory; import org.eclipse.emf.ecore.EcorePackage; import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; import org.eclipse.emf.edit.provider.IItemLabelProvider; import org.eclipse.emf.edit.provider.IItemPropertySource; import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; import org.eclipse.emf.edit.provider.ITreeItemContentProvider; import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; import org.eclipse.emf.edit.provider.ViewerNotification; /** * @author Michal Antkiewicz <mantkiew@gsd.uwaterloo.ca> * * This is the item provider adapter for a {@link org.eclipse.emf.ecore.EPackage} object. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public class EPackageItemProvider extends ENamedElementItemProvider implements IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource { /** * This constructs an instance from a factory and a notifier. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EPackageItemProvider(AdapterFactory adapterFactory) { super(adapterFactory); } /** * This returns the property descriptors for the adapted class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public List getPropertyDescriptors(Object object) { if (itemPropertyDescriptors == null) { super.getPropertyDescriptors(object); addNsURIPropertyDescriptor(object); addNsPrefixPropertyDescriptor(object); addEFactoryInstancePropertyDescriptor(object); } return itemPropertyDescriptors; } /** * This adds a property descriptor for the Ns URI feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void addNsURIPropertyDescriptor(Object object) { itemPropertyDescriptors.add (createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_EPackage_nsURI_feature"), getString("_UI_PropertyDescriptor_description", "_UI_EPackage_nsURI_feature", "_UI_EPackage_type"), EcorePackage.Literals.EPACKAGE__NS_URI, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null)); } /** * This adds a property descriptor for the Ns Prefix feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void addNsPrefixPropertyDescriptor(Object object) { itemPropertyDescriptors.add (createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_EPackage_nsPrefix_feature"), getString("_UI_PropertyDescriptor_description", "_UI_EPackage_nsPrefix_feature", "_UI_EPackage_type"), EcorePackage.Literals.EPACKAGE__NS_PREFIX, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null)); } /** * This adds a property descriptor for the EFactory Instance feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void addEFactoryInstancePropertyDescriptor(Object object) { itemPropertyDescriptors.add (createItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_EPackage_eFactoryInstance_feature"), getString("_UI_PropertyDescriptor_description", "_UI_EPackage_eFactoryInstance_feature", "_UI_EPackage_type"), EcorePackage.Literals.EPACKAGE__EFACTORY_INSTANCE, false, false, false, null, null, null)); } /** * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Collection getChildrenFeatures(Object object) { if (childrenFeatures == null) { super.getChildrenFeatures(object); childrenFeatures.add(EcorePackage.Literals.EPACKAGE__ECLASSIFIERS); childrenFeatures.add(EcorePackage.Literals.EPACKAGE__ESUBPACKAGES); } return childrenFeatures; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected EStructuralFeature getChildFeature(Object object, Object child) { // Check the type of the specified child object and return the proper feature to use for // adding (see {@link AddCommand}) it as a child. return super.getChildFeature(object, child); } /** * This returns EPackage.gif. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Object getImage(Object object) { return overlayImage(object, getResourceLocator().getImage("full/obj16/EPackage")); } /** * This returns the label text for the adapted class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public String getText(Object object) { EPackage ePackage = (EPackage)object; StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(ePackage.getName()); return stringBuffer.toString(); } /** * This handles model notifications by calling {@link #updateChildren} to update any cached * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void notifyChanged(Notification notification) { updateChildren(notification); switch (notification.getFeatureID(EPackage.class)) { case EcorePackage.EPACKAGE__NS_URI: case EcorePackage.EPACKAGE__NS_PREFIX: case EcorePackage.EPACKAGE__EFACTORY_INSTANCE: fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); return; case EcorePackage.EPACKAGE__ECLASSIFIERS: case EcorePackage.EPACKAGE__ESUBPACKAGES: fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); return; } super.notifyChanged(notification); } /** * This adds to the collection of {@link org.eclipse.emf.edit.command.CommandParameter}s * describing all of the children that can be created under this object. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) { super.collectNewChildDescriptors(newChildDescriptors, object); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, EcoreFactory.eINSTANCE.createEClass())); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, EcoreFactory.eINSTANCE.createEDataType())); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.EPACKAGE__ECLASSIFIERS, EcoreFactory.eINSTANCE.createEEnum())); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.EPACKAGE__ESUBPACKAGES, EcoreFactory.eINSTANCE.createEPackage())); } /** * Return the resource locator for this item provider's resources. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public ResourceLocator getResourceLocator() { return EcoreEditPlugin.INSTANCE; } @Override public Collection getChildren(Object object) { // show all classes which are not contained by any containment reference. HashMap<EClass, Boolean> containedClasses = new HashMap<EClass, Boolean>(); EPackage ePackage = (EPackage) object; // store all reference types in the hash map for (Object aux : ePackage.getEClassifiers()) if (aux instanceof EClass) { EClass eClass = (EClass) aux; for (Object refAux : eClass.getEReferences()) { EReference ref = (EReference) refAux; if (!ref.isContainment()) continue; containedClasses.put(ref.getEReferenceType(), true); } } // find root classes Collection<EClass> rootClasses = new ArrayList<EClass>(); for (Object aux : ePackage.getEClassifiers()) if (aux instanceof EClass) { EClass eClass = (EClass) aux; // check super types ArrayList<EClass> superTypes = new ArrayList<EClass>(); superTypes.add(eClass); boolean isContained = false; while (!superTypes.isEmpty()) { EClass superClass = superTypes.remove(0); if (containedClasses.containsKey(superClass)) { isContained = true; break; } superTypes.addAll(superClass.getEAllSuperTypes()); } // all super types were examined... if (!isContained) rootClasses.add(eClass); } return rootClasses; } }