I have an application with a part (part-A) and a part stack with other part. When the user clicks on an item in part-A a certain part in the part stack (part-B) should become visible.
I implemented this by sending an event in part-A via the IEventBroker and part-B catches this event, makes itself visible (by calling partService.activate(me)), and does whatever it has to do.
This works fine if the user manually selected part-B before. If part-B was never selected, the object associated with part-B is not created and therefore the event is not received.
Of cause part-A could call the partService.activate(part-B) before sending the event, but normally the sender of an event should not make any assumptions about the receiver of the event.
It the a way to force the creation of the associated object of part-B? Or is my approach completly wrong and there is a better solution?
Yes I can do that but, this shifts the problem to the addon. The addon must know about the real receiver of the event and that is not much better as if the sender must know the receiver.
Sopot Cela Messages: 448 Registered: December 2010
Senior Member
If I got this correctly the part B is not getting the event because the contributor (backing POJO) is not instantiated. That is a normal thing as it is lazy loading the part.
As Christoph said you can supply an addon which activates the part-B. You can do a quick show/hide just to create it from the addon and I would not consider it a publisher-receiver link as the publisher is a separate thing from the addon. The addon's job is just to circumvent the lazy loading of the part, not publish events. The publisher (part A) does not know and has no reference to part B so I don't see where the link is.
There are other alternatives as creating the contributions programmatically using contribution factories but it is better to stick to the services.
Out of curiosity why are you not pushing stuff to the IEclipseContext
(e.g. of the perspective, window or even application) and when the part
gets activated the value will get injected, this sounds the correct
solution. Your current approach e.g. does not allow closing and
reopening the view.
IMHO one uses:
* DI if you want to have the values available all time
* Event-System if the information is import for those currently active
but not interesting for those currently not shown/rendered
Tom
Am 16.10.12 14:16, schrieb Sopot Cela:
> Fair enough. Providing your own renderer is a good solution also.
I don't think that pushing the data in an eclipse context helps in my situation. The producing part of the information does not know what the receiving part is and what it likes to do with the data. In my situation the receiver may decide that the data is important to the user and it forces its visibility (with partService.activate(...)). I can't wait until the user activates the part manually. So I have a problem if the associated object is not yet created. I can't see what it helps (in my situation) when I push the data in an eclipse context. Pushing it an a context does not create the object.
According to your list, what mechanism I should use, I have a third situation:
* Data that should not be avaibable all the time and is important for parts not visible.