Package org.eclipse.emf.compare.merge

## Class ResourceChangeAdapter

- java.lang.Object
- - org.eclipse.emf.common.notify.impl.AdapterImpl
  - - org.eclipse.emf.compare.merge.ResourceChangeAdapter

All Implemented Interfaces:
  `Adapter`, `Adapter.Internal`

    public class ResourceChangeAdapter
    extends AdapterImpl

This adapter is supposed to be installed on a `Comparison`'s `ResourceSet`s and their `Resource`s to react to content changes. Participants can then react to such changes to jointly decide whether a resource must be marked for deletion. The same instance of adapter should be used for all the resources of a comparison's `ResourceSet`s. EMFCompare installs such an adapter on the comparison to make it easy to retrieve.

### Nested Class Summary

Nested Classes
`static interface` `ResourceChangeAdapter.IResourceChangeParticipant` A participant in a Resource content change, useful to indicate whether an empty resource must actually be deleted or not, and which other resources need to be deleted/undeleted along.

### Nested classes/interfaces inherited from interface org.eclipse.emf.common.notify.Adapter

`Adapter.Internal`

### Field Summary

### Fields inherited from class org.eclipse.emf.common.notify.impl.AdapterImpl

`target`

### Constructor Summary

Constructors
`ResourceChangeAdapter​(Comparison comparison, IComparisonScope scope)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addParticipant​(ResourceChangeAdapter.IResourceChangeParticipant participant)` Register the given participant.
`protected org.eclipse.emf.compare.merge.ResourceChangeAdapter.ResourceMatch` `getResourceMatch​(Resource resource)` Returns the MatchResource corresponding to the given `resource`.
`protected ResourceSet` `getResourceSetOnOtherSide​(Resource r)` Get the resource set on the other side of the given resource.
`boolean` `isAdapterForType​(Object type)`
`boolean` `isEmptyAndMissingOnOtherSide​(Resource resource)` Indicate whether a resource is empty and is only on its side of the comparison (i.e. if it should be deleted unless a special restriction prevents it).
`boolean` `mustDelete​(Resource r)` Indicate whether a given Resource needs to be deleted.
`void` `notifyChanged​(Notification msg)`
`void` `removeParticipant​(ResourceChangeAdapter.IResourceChangeParticipant participant)` Unregister the given participant, has no action if the participant was not previously registered.
`protected void` `resourceAdded​(Resource resource)` Callback invoked when a resource has just been added to a resource set.
`protected void` `resourceContentsChanged​(Resource resource, Notification msg)` React to a Resource contents change to determine if this change involves the deletion of one or several resources.

### Methods inherited from class org.eclipse.emf.common.notify.impl.AdapterImpl

`getTarget, setTarget, unsetTarget`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ResourceChangeAdapter

    public ResourceChangeAdapter​(Comparison comparison,
                                 IComparisonScope scope)

Constructor.

Parameters:
  `comparison` - The comparison, cannot be `null`.
  `scope` - The scope, cannot be `null`. Moreover, the left and right notifiers of the scope must be `ResourceSet`s.

### Method Detail

#### notifyChanged

    public void notifyChanged​(Notification msg)

Specified by:
  `notifyChanged` in interface `Adapter`
Overrides:
  `notifyChanged` in class `AdapterImpl`

#### isAdapterForType

    public boolean isAdapterForType​(Object type)

Specified by:
  `isAdapterForType` in interface `Adapter`
Overrides:
  `isAdapterForType` in class `AdapterImpl`

#### addParticipant

    public void addParticipant​(ResourceChangeAdapter.IResourceChangeParticipant participant)

Register the given participant.

Parameters:
  `participant` - The participant, must not be `null`

#### removeParticipant

    public void removeParticipant​(ResourceChangeAdapter.IResourceChangeParticipant participant)

Unregister the given participant, has no action if the participant was not previously registered.

Parameters:
  `participant` - The participant to unregister

#### mustDelete

    public boolean mustDelete​(Resource r)

Indicate whether a given Resource needs to be deleted.

Parameters:
  `r` - The resource
Returns:
  `true` if the given resource has been marked for deletion.

#### resourceAdded

    protected void resourceAdded​(Resource resource)

Callback invoked when a resource has just been added to a resource set. By default, it walks over the interested participants and creates all the associated resources that these participants declare as associated to the given resource.

Parameters:
  `resource` - The newly added resource

#### getResourceSetOnOtherSide

    protected ResourceSet getResourceSetOnOtherSide​(Resource r)

Get the resource set on the other side of the given resource.

Parameters:
  `r` - The resource, which must be either on the left or on the right of the comparison.
Returns:
  The ResourceSet on the other side, never `null`.
Throws:
  `IllegalArgumentException` - If the given resource is neither on the left nor on the right.

#### resourceContentsChanged

    protected void resourceContentsChanged​(Resource resource,
                                           Notification msg)

React to a Resource contents change to determine if this change involves the deletion of one or several resources. A Resource must be deleted if:

1. Their contents is `null` or empty;
2. It is not matched on the other side of the comparison;
3. Every participant is OK to delete it.

Otherwise, it must not be deleted. When a resource is detected as 'to be deleted', all interested participants are asked for associated resources to delete along with it, and all these resources are marked for deletion without any further test. When a resource is detected as 'not to be deleted', and it had previously been marked for deletion (in the case of an undo for instance), then all interested participants are asked for associated resources which are all marked as 'not te be deleted'.

Parameters:
  `resource` - The resource the contents of which have changed
  `msg` - The notification of the change

#### isEmptyAndMissingOnOtherSide

    public boolean isEmptyAndMissingOnOtherSide​(Resource resource)

Indicate whether a resource is empty and is only on its side of the comparison (i.e. if it should be deleted unless a special restriction prevents it).

Parameters:
  `resource` - The resource
Returns:
  `true` if the resource is empty and is not matched on the other side of the comparison.

#### getResourceMatch

    protected org.eclipse.emf.compare.merge.ResourceChangeAdapter.ResourceMatch getResourceMatch​(Resource resource)

Returns the MatchResource corresponding to the given `resource`.

Parameters:
  `resource` - Resource for which we need a MatchResource.
Returns:
  The MatchResource corresponding to the given `resource`, `null` if the resource is not in any side of this comparison (package, profiles, ...).