Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to communicate between various views/models(How to communicate between various views/models)
How to communicate between various views/models [message #498223] Sun, 15 November 2009 19:26 Go to next message
Ewan is currently offline Ewan
Messages: 5
Registered: July 2009
Junior Member
Hello,

I have really searched through a lot of documentation before posting so any help would be greatly appreciated.

There are two problems that I would like to solve

1) I have created some views in a plugin. However, in all of the examples I can find on the web all of the sample view have a mock data model within the actual view. In my instance I have a model that I would like to share between various views/preferences page. For example - I have a preferences page that I would like to bring up and allow the user to change preferences. Once preferences have been changed the view would change some element of its presentation.

My questions is - what is the eclipse best practice for sharing a single data store/model between a number of views?

Is the best practice to go to the workbench and look up other views by id? This seems a bit nasty as you have the view ids spread throughout the code. I really dont want to use singletons either (IoC fanatic). I have looked at the spring OSGI integration and using spring to inject beans into views. However, it looks massively complex and a bit bleeding edge at the moment and unfortunately I can not justify using it for this simple requirement I have.

2) Second question related to the first. Looking at a lot of the eclipse code it is completely impossible to test/run individual views outside of an eclipse runtime container. When developing with swing/outside of eclipse I prefer to make each view/panel independently runnable. This would be achieved by having a main in each panel which would create a frame, create any mocks that the panel is dependent on, create a frame and add. Is there any way to do this with SWT views that usually run within eclipse. I generally find this very difficult as all of the panels are heavily dependent on the runtime and too much is required to be mocked out.

Any help on either of the questions would be appreciated.

Cheers
Re: How to communicate between various views/models [message #498225 is a reply to message #498223] Sun, 15 November 2009 20:01 Go to previous messageGo to next message
Eclipse User
Originally posted by: wangqs_eclipse.yahoo.com

This is a multi-part message in MIME format.
--------------000906030201050005080105
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

For Q1 I'd suggest Observe patter. E.g. register your view to the model
as a listener. Trigger an event for the model changes. View can then
receive the event and determine if the event shall cause a refresh of
the view.

For Q2, you can write a test plugin and run it as plug-in unit test
which will run the test in the plugin environment. You can read the
article at
http://www.eclipse.org/articles/article.php?file=Article-PDE JUnitAntAutomation/index.html

Q.S. Wang





Ewan wrote:
> Hello,
>
> I have really searched through a lot of documentation before posting so
> any help would be greatly appreciated.
>
> There are two problems that I would like to solve
>
> 1) I have created some views in a plugin. However, in all of the
> examples I can find on the web all of the sample view have a mock data
> model within the actual view. In my instance I have a model that I would
> like to share between various views/preferences page. For example - I
> have a preferences page that I would like to bring up and allow the user
> to change preferences. Once preferences have been changed the view would
> change some element of its presentation.
>
> My questions is - what is the eclipse best practice for sharing a single
> data store/model between a number of views?
>
> Is the best practice to go to the workbench and look up other views by
> id? This seems a bit nasty as you have the view ids spread throughout
> the code. I really dont want to use singletons either (IoC fanatic). I
> have looked at the spring OSGI integration and using spring to inject
> beans into views. However, it looks massively complex and a bit bleeding
> edge at the moment and unfortunately I can not justify using it for this
> simple requirement I have.
>
> 2) Second question related to the first. Looking at a lot of the eclipse
> code it is completely impossible to test/run individual views outside of
> an eclipse runtime container. When developing with swing/outside of
> eclipse I prefer to make each view/panel independently runnable. This
> would be achieved by having a main in each panel which would create a
> frame, create any mocks that the panel is dependent on, create a frame
> and add. Is there any way to do this with SWT views that usually run
> within eclipse. I generally find this very difficult as all of the
> panels are heavily dependent on the runtime and too much is required to
> be mocked out.
>
> Any help on either of the questions would be appreciated.
>
> Cheers


--
http://www.myeclipsedev.com/

--------------000906030201050005080105
Content-Type: text/x-vcard; charset=utf-8;
name="wangqs_eclipse.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="wangqs_eclipse.vcf"

YmVnaW46dmNhcmQNCmVtYWlsO2ludGVybmV0Ondhbmdxc19lY2xpcHNlQHlh aG9vLmNvbQ0K
dXJsOmh0dHA6Ly93d3cubXllY2xpcHNlZGV2LmNvbQ0KdmVyc2lvbjoyLjEN CmVuZDp2Y2Fy
ZA0KDQo=
--------------000906030201050005080105--
Re: How to communicate between various views/models [message #500205 is a reply to message #498225] Wed, 25 November 2009 06:35 Go to previous messageGo to next message
Ewan is currently offline Ewan
Messages: 5
Registered: July 2009
Junior Member
Thanks,

perhaps if I could rephrase the question. I was intending on writing in MVC design pattern. My question is a bit more fundamental.

How, from the view/controller do I locate the model bean.

i.e. the view is instantiated by rcp. I have a model instance which is part of the plugin. How do I actually get a handle from the view without going singleton/static?

Thanks
Re: How to communicate between various views/models [message #500213 is a reply to message #498223] Wed, 25 November 2009 07:11 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 417
Registered: September 2009
Senior Member
Some kind soul suggested me the following snippet:
	IWorkbenchWindow ww = HandlerUtil.getActiveWorkbenchWindow(event);
	IWorkbenchPage wp = ww.getActivePage();
	Book b = (Book) wp.findView(Book.ID);
where, obviously, Book is my ViewPart. This code is called from within the OpenHandler to setup my model.

HiH
Mauro
Re: How to communicate between various views/models [message #501187 is a reply to message #500213] Tue, 01 December 2009 08:25 Go to previous messageGo to next message
T. Wilhelm is currently offline T. Wilhelm
Messages: 129
Registered: July 2009
Senior Member
If you dont like Singletons (I also dont like them because they will be raped so often as simple access mechanism) you could use Services. This is a very independent and convinient way to access your Model.

Look for Eclipse RCP services, if you have more questions or need more details, just ask.

Greetz
Thomas
Re: How to communicate between various views/models [message #501233 is a reply to message #501187] Tue, 01 December 2009 10:50 Go to previous message
Luca Ferrari is currently offline Luca Ferrari
Messages: 159
Registered: November 2009
Senior Member
In an application I'm developing now I've got a lot of master/slave views based on tables. I use content providers to communicate: once I need to change the input of view X I lookup the view X thru eclipse, get its content provider and change the input on it.
It is not very handy, but it works fine and does not couple very strongly objects.
Previous Topic:Progress Monitor freezes when app loses focus
Next Topic:Trying to Understand RCP & its Platform dependencies
Goto Forum:
  


Current Time: Thu Aug 28 05:13:38 EDT 2014

Powered by FUDForum. Page generated in 0.14865 seconds