capint
10/15/2015 - 10:30 AM

EMF >> Editing domain >> Get object's editing domain

EMF >> Editing domain >> Get object's editing domain

public static EditingDomain getEditingDomain(Object object_p) {
	if (object_p instanceof Collection) {
		for (Object it : (Collection) object_p) {
			EditingDomain domain = getEditingDomain(it);
			if (domain != null) {
				return domain;
			}
		}
	}
	EditingDomain domain = (AdapterFactoryEditingDomain) AdapterFactoryEditingDomain
				.getEditingDomainFor(object_p);
	if (domain == null && object_p != null) {
		domain = TransactionUtil.getEditingDomain(object_p);
	}
	if (domain == null) {
	  //*** ComposedAdapterFactory's adapt method will find the ItemProviderAdapterFactory for the given object
	  //*** => the returned AdapterFactoryEditingDomain is good to go
		ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
				ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
		adapterFactory
				.addAdapterFactory(new ResourceItemProviderAdapterFactory());
		adapterFactory
				.addAdapterFactory(new EcoreItemProviderAdapterFactory());
		adapterFactory
				.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
		return new AdapterFactoryEditingDomain(adapterFactory,
				new BasicCommandStack());
	}
	return domain;