NotificationService & Updates [message #757131] |
Wed, 16 November 2011 16:05 |
Matteo Miraz Messages: 38 Registered: March 2011 |
Member |
|
|
Hi,
I have some issues with the notification service.
I have to say that my diagrams only show part of the elements of the model: other elements contribute by decorating shown elements. Let me use an example:
The model class has a list of commands.
There are two types (subclasses) of commands: "Shown" and "Decorator".
Shown are directly shown in the editor, together with their "name" attribute.
Decorator are not shown. They have a reference "using" to a Shown element, which must be decorated.
Doing that is really easy: I only have to implement method ToolBehaviorProvider.getDecorators, inspect the model, and verify if a given function has one or more D element referencing it.
However, the real problem is reacting when the model is changed. In this case, I was not able to use the notification service to update the function being referenced by the newly created Decorator. I think that the problem is in two places: (1) my model is silly (but I'm forced to use it) and (2) the notification service (class DomainModelChangeListener) triggers the updates starting from the notifier of the ResourceSetChangeEvent. This way, when a new Decorator is added, the updates comes from the Model, and I cannot figure out which Decorator is referenced.
How can I solve this? Are there guidelines on how to use Graphiti's service and deal with silly models?
|
|
|
|
|
|
Re: NotificationService & Updates [message #757147 is a reply to message #757145] |
Wed, 16 November 2011 18:45 |
Matteo Miraz Messages: 38 Registered: March 2011 |
Member |
|
|
Hi,
I've debugged the DomainModelChangeListener, and let me show the problem:
public void resourceSetChanged(ResourceSetChangeEvent event) {
[...]
// Compute changed BOs.
final Set<EObject> changedBOs = new HashSet<EObject>();
List<Notification> notifications = event.getNotifications();
for (Notification notification : notifications) {
Object notifier = notification.getNotifier();
if (!(notifier instanceof EObject)) continue;
changedBOs.add((EObject) notifier);
}
As you can see, the changedBOs is calculated by considering notification.getNotifier(), that in my case is the model. I think that normally this is not an issue because elements are added by using an Add/CreateFeature.
In the meanwhile, I implemented my own ResourceSetListener, using DomainModelChangeListener as inspiration. I computed the set of changed elements and the dirty pictogramElements (using notificationService.calculateRelatedPictogramElements). However, if I invoke
notificationService.updatePictogramElements(dirtyPes);
the diagram is not updated correctly. Only a
shows the decorators.
What is the difference between the two methods? (I feel I made other errors, and I'd like to understand what's wrong)
Thanks again,
Matteo
[Updated on: Wed, 16 November 2011 19:43] Report message to a moderator
|
|
|
Re: NotificationService & Updates [message #757234 is a reply to message #757147] |
Thu, 17 November 2011 09:37 |
Matteo Miraz Messages: 38 Registered: March 2011 |
Member |
|
|
Hi,
I (think) I found and solved my errors. Let me know if I'm wrong
The elements I show in the diagram are only composed of a rectangle and a text. For this reason, my update feature only checks if the name is changed, in order to update the text of the rectangle.
Decorators are shown by using graphiti's decorators. These are not recalculated when I issue an update (maybe because my update feature says that everything is up to date). Accordingly, my diagram does not change when I invoke notificationService.updatePictogramElements(dirtyPes).
Conversely, refresh method performs a refresh of the element shown, including their decorators. Since I do have calculated the dirty pictogramElements, I should use the refresh method with a pictogram element as parameter (I did not noticed it), so I can force the refresh only on the dirty elements.
Thank you all for the support! I hope I have nailed it, and that this post might be useful for somebody else!
--
Matteo
|
|
|
Powered by
FUDForum. Page generated in 0.04382 seconds