Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EMF Compare/Specifications/ExtensionPointForAdapterFactories

THIS PAGE IS ARCHIVED. IT IS PROBABLY OUTDATED AND WILL NOT BE UPDATED

Evolution Specification: Provide an adapter factory extension mechanism

Current status is ARCHIVED

Preamble

It enables to provide his own match adapter factory implementation.

Introduction

There is no actual mechanism to provide his own adapter factory. An extension point mechanism will be useful to allow users to provide their own adapter factories.

Detailed Specification

The aim is to provide a mechanism that allow users to provide their own adapter factory with a specific rank.

The AdapterFactory interface will be extended in order to manage ranking. The new extended AdapterFactory that the users will have to implement will be named RankedAdapterFactory.

The ComposedAdapterFactory will interrogate first the newly created emf compare adapter factory registry (composed of RankedAdapterFactories) to find an appropriate RankedAdapterFactory. If no appropriate adapter factory is found in the first registry, then registry will delegate his research to the "default" ComposedAdapterFactory registry.

With this mechanism you will able to provide, for example, your own CompareItemProviderAdapterFactory that will overrides the default CompareItemProviderAdapterFactory, in order to customize the labels, images... of the emf compare metamodel elements. Another use case you will be able to provide, is to extends the EcoreItemProviderAdapterFactory, in order to customize the labels, images... of the ecore metamodel elements.

Backward Compatibility and Migration Paths

Metamodel Changes

N/A

API Changes

  • New extension point:
    • org.eclipse.emf.compare.edit
<extension-point id="adapterFactory" name="EMF Compare Adapter Factory" schema="schema/adapterFactory.exsd"/>

Example of use:

<extension 
   point="org.eclipse.emf.compare.edit.adapterFactory">
      <factory
            uri="http://www.eclipse.org/emf/compare"
            class="org.eclipse.emf.compare.test.adapterfactory.MyCompareItemProviderAdapterFactorySpec"
            ranking="10"
            supportedTypes=
              "org.eclipse.emf.edit.provider.IEditingDomainItemProvider
               org.eclipse.emf.edit.provider.IStructuredItemContentProvider
               org.eclipse.emf.edit.provider.ITreeItemContentProvider
               org.eclipse.emf.edit.provider.IItemLabelProvider
               org.eclipse.emf.edit.provider.IItemPropertySource
               org.eclipse.emf.compare.provider.IItemStyledLabelProvider
               org.eclipse.emf.compare.provider.IItemDescriptionProvider"/>
</extension>
  • New interfaces:
    • org.eclipse.emf.compare.edit
      • org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactory
public interface RankedAdapterFactory extends AdapterFactory {
 
	int getRanking();
 
	void setRanking(int ranking);
}
      • org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactoryDescriptor
      • org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactoryDescriptor.Registry
public interface RankedAdapterFactoryDescriptor extends ComposedAdapterFactory.Descriptor {
 
        int getRanking();
 
	interface Registry extends ComposedAdapterFactory.Descriptor.Registry {
 
	}
}
  • New implementations:
    • org.eclipse.emf.compare.rcp
      • org.eclipse.emf.compare.rcp.internal.adapterfactory.RankedAdapterFactoryDescriptorImpl
    • org.eclipse.emf.compare.edit
      • org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactoryDescriptorRegistryImpl

User Interface Changes

N/A

Documentation Changes

This documentation will have to be updated:

  • New and Noteworthy
  • Developer Guide

Example of use

Suppose you want to customize the labels of the Matches elements of your emf compare model.

First, you will have to provide your own CompareItemProviderAdapterFactory that will overrides the CompareItemProviderAdapterFactory used by emf compare, and implements the new interface RankedAdapterFactory. You will need to overrides the createMatchAdapter() method to and provide your own MatchItemProvider.

public class MyCompareItemProviderAdapterFactorySpec extends CompareItemProviderAdapterFactorySpec implements RankedAdapterFactory {
 
        private int ranking;
 
        public int getRanking() {
		return ranking;
	}
 
	public void setRanking(int ranking) {
		this.ranking = ranking;
	}
 
	@Override
	public Adapter createMatchAdapter() {
		if (matchItemProvider == null) {
			matchItemProvider = new MyMatchItemProviderSpec(this);
		}
		return matchItemProvider;
	}
}
 
public class MyMatchItemProviderSpec extends MatchItemProviderSpec implements IItemStyledLabelProvider, IItemDescriptionProvider {
 
        @Override
	public String getText(Object object) {
             return " Customized Match : " + super.getText(object);
        }
}

Last, contribute a new extension of type org.eclipse.emf.compare.edit.adapterFactory in your plugin.xml:

<extension 
   point="org.eclipse.emf.compare.edit.adapterFactory">
      <factory
            uri="http://www.eclipse.org/emf/compare"
            class="org.eclipse.emf.compare.test.adapterfactory.MyCompareItemProviderAdapterFactorySpec"
            ranking="10"
            supportedTypes=
              "org.eclipse.emf.edit.provider.IEditingDomainItemProvider
               org.eclipse.emf.edit.provider.IStructuredItemContentProvider
               org.eclipse.emf.edit.provider.ITreeItemContentProvider
               org.eclipse.emf.edit.provider.IItemLabelProvider
               org.eclipse.emf.edit.provider.IItemPropertySource
               org.eclipse.emf.compare.provider.IItemStyledLabelProvider
               org.eclipse.emf.compare.provider.IItemDescriptionProvider"/>
</extension>

You can see the result of the example below. The right image shows the emf compare editor with the custom contribution:

alt Default Item Provider Adapter Factory alt Custom Item Provider Adapter Factory

Tests and Non-regression strategy

JUnit tests: EMFCompareAdapterFactoryTest.java in o.e.e.c.tests.

Implementation choices and tradeoffs

N/A

Back to the top