|Re: Link with Editor in IViewPart [message #880419 is a reply to message #879474]
||Sat, 02 June 2012 00:38
| John Steele
Registered: January 2010
So you are trying to link the selection from one view to another?|
You have a few options, but I personally wouldn't go with CNF because where's the fun in that;)
Option - 1) The most obvious option would be to use the SelectionService. You can register the viewer from your navigation view as the selection provider, and the other views/editors that wish to listen to selection events can register a selection listener with the selection service.
See this article about selection service: eclipse.org/articles/Article-WorkbenchSelections/article.html
Option - 2) Maintain a Singleton object which contains a list of listeners to be notified on selection events. It would also maintain a flag indicating if views are currently linked. When the link command is executed, call the Singleton object LinkingUtil.INSTANCE.enableLinking(), which will then iterate through all the listeners that linking has been enabled. You could also store other information in the Singleton object like the selection object, so that listeners can retrieve it from there instead of having to maintain a reference to the navigational view.
See this article about Singleton: vogella.com/articles/DesignPatternSingleton/article.html
Option - 3) Use PropertyChangeSupport and/or databinding to allow other views to listen to property changes. Of course, when linking is disabled, you would not notify(...).
See this article on databinding:
Option - 4) My favorite way to implement this is to use the EventAdmin OSGi service. You can post events to the EventAdmin service when a selection is made, and then register handlers to be notified when an event occurs.
See this article on view communication: tomsondev.bestsolution.at/2011/01/03/enhanced-rcp-how-views-can-communicate/
Hopefully these ideas can help you derive a solution.
There are a lot more other ways as well.
[Updated on: Sat, 02 June 2012 00:39]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01750 seconds