[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[News.eclipse.technology.gmf] Re: How can I understand that new element is added or deleted from container?
|
Hi, Trifonov,
You can attach a ResourceSetListener to your TransactionalEditingDomain to
be notified, in the resourceSetChanged() call-back, of changes that were
committed to the model (domain and/or diagram) by a Transaction. The
ResourceSetChangedEvent has a list of Notifications, each of which
indicates a discrete change.
You should consider a notification of type Notification.ADD in which the
newly added object (or objects, in the case of ADD_MANY) is still contained
by the notification's notifier as a newly added object. Likewise, a
notification of type REMOVE or REMOVE_MANY indicates one or more objects
removed from a container, if those removed objects now have no containers.
I qualify these statements with a need to check that the current state of an
object matches what the Notification indicates, because these notifications
are provided to the ResourceSetListener after *all* changes in a
transaction have occurred. Thus, it may happen the the added object in an
ADD notification is contained by a different object than the notifier,
because a subsequent change in the same transaction moved it to another
container. Similarly, a REMOVE notification may indicate that an object
was detached from a container, but a subsequent change may have re-attached
it somewhere else.
To avoid some of these considerations, you can also access the
ChangeDescription of the Transaction that committed (available from the
ResourceSetChangedEvent). This provides a single delta view of the changes
performed by the transaction, but in reverse. It describes what changes
would be required to revert the model to its previous state.
HTH,
Christian
Trifonov wrote:
> Hi All,
>
> I've got element, named 'Container' that can contain other elements. I
> have to perform some additional jobs when a component was added to
> 'Container' and when a component was removed from 'Container'. How can I
> listen for these changes?
>
> Best regards,
> Trifonov