Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » RCP and MVC
RCP and MVC [message #437443] Wed, 28 September 2005 12:24 Go to next message
Eclipse UserFriend
Originally posted by: kristof.taveirne.intec.ugent.be

Hi all,
I just recently (yesterday :-) ) started do to some research on Eclipse and
the RCP.
I managed to create a simple gui with 2 perspectives and a couple of views.

What I'm trying to do is to transform my SWT-based application to RCP. In
my SWT-based app I'm using the MVC design pattern to keep my views up to
date with my datamodel. The data is gathered through web services calls.
Some calculations need to be done on the data recieved and then the result
should be displayed.

What I'm looking for now is a way to implement MVC in my RCP application.
How can I notify the different views/perspectives to update their GUI elements
according to the Model class?

I don't quite see yet how I can add references to a datamodel in a view because
of the use of ID-strings instead of object references.

Can somebody give me some quick directions? I'm still in the discovery fase
here, but I'm kinda stuck on this.

This is probably a very newbee question, my apologies for that :-)

Thanks in advance

Kristof Taveirne
Re: RCP and MVC [message #437445 is a reply to message #437443] Wed, 28 September 2005 13:57 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

One way of doing that is to have your view implement some kind of model
listener on your data model.

As for allowing the view to register itself with the model, I've seen
people use their plugin class as a factory for those kinds of things
(providing access to singletons as well).

In your IViewPart#init(...) methods you can register yourself with the
model from your plugin.

Later,
PW


Re: RCP and MVC [message #437446 is a reply to message #437443] Wed, 28 September 2005 14:07 Go to previous messageGo to next message
Charles H Martin is currently offline Charles H MartinFriend
Messages: 79
Registered: July 2009
Member
Kristof

I think this is an excellent question!
I myself have had to make a decision on this several times, and it was not obvious to me.

You can pretty much use any MVC pattern your want...Observer-Observable, EventListenerList, etc

One solution I used was to create Context class with a Swing-like EventListenerList, and then I registered all my plugin views with the context during their initialization:

public MyView() {
instance = this;
getContext().addListener(DataLoadedListener.class, this.dataListener);
}

In this model, each of my views has specific listener classes, and they receive events just like a view in Swing

I could post a complex example to the board if this would be helpful.

Sincerely

Charles




}


> Hi all,
> I just recently (yesterday :-) ) started do to some
> research on Eclipse and
> the RCP.
> I managed to create a simple gui with 2 perspectives
> and a couple of views.
>
> What I'm trying to do is to transform my SWT-based
> application to RCP. In
> my SWT-based app I'm using the MVC design pattern to
> keep my views up to
> date with my datamodel. The data is gathered through
> web services calls.
> Some calculations need to be done on the data
> recieved and then the result
> should be displayed.
>
> What I'm looking for now is a way to implement MVC in
> my RCP application.
> How can I notify the different views/perspectives to
> update their GUI elements
> according to the Model class?
>
> I don't quite see yet how I can add references to a
> datamodel in a view because
> of the use of ID-strings instead of object
> references.
>
> Can somebody give me some quick directions? I'm still
> in the discovery fase
> here, but I'm kinda stuck on this.
>
> This is probably a very newbee question, my apologies
> for that :-)
>
> Thanks in advance
>
> Kristof Taveirne
>
>
Re: RCP and MVC [message #437448 is a reply to message #437446] Wed, 28 September 2005 14:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kristof.taveirne.intec.ugent.be

Hello,


>
> One solution I used was to create Context class with a Swing-like
> EventListenerList, and then I registered all my plugin views with the
> context during their initialization:
>
> public MyView() {
> instance = this;
> getContext().addListener(DataLoadedListener.class,
> this.dataListener);
> }
> In this model, each of my views has specific listener classes, and
> they receive events just like a view in Swing

This looks exactly what I want to do.
But what I don't yet understand is
1) how the reference to the Context-object could be obtained.
2) when the MyView contructor is called.

The only point in the code I see a "reference" to MyView is in MyPerspective#createInitialLayout(IPageLayout
layout):
layout.addView(MyView.ID, IPageLayout.LEFT, 1.0f, editorArea);

(I used one of the templates in eclipse to build on)

I don't get where and when the constructor you mentioned is called.

I find it indeed a very good idea to have my view implement a model listener
interface ( like Paul Webster sugested (thanks P.)) or to have a DataLoadedListener
class. But to register the views to the model's EventListenerList there must
be some central point where I can access the different views to pass them
the data model so they can register themself to it.

Is there a way to get references to the different views in the workbench
from a certain point in the code?

>
> I could post a complex example to the board if this would be
> helpful.

That would be awesome! :-) Maybe it would help me to understand everything
a bit better.

>
> Sincerely
>
> Charles

Thanks alot Charles and Paul for your replies,

Greetings,
Kristof Taveirne
Re: RCP and MVC [message #437450 is a reply to message #437448] Wed, 28 September 2005 15:24 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

kristof taveirne wrote:
>
> The only point in the code I see a "reference" to MyView is in
> MyPerspective#createInitialLayout(IPageLayout layout):
> layout.addView(MyView.ID, IPageLayout.LEFT, 1.0f, editorArea);

That's the setup, but the view constructor won't be called until someone
either switches to your perspective, or uses Window>showView to start
your view.

>
> (I used one of the templates in eclipse to build on)
>
> I don't get where and when the constructor you mentioned is called.
>
> I find it indeed a very good idea to have my view implement a model
> listener interface ( like Paul Webster sugested (thanks P.)) or to have
> a DataLoadedListener class. But to register the views to the model's
> EventListenerList there must be some central point where I can access
> the different views to pass them the data model so they can register
> themself to it.
>
> Is there a way to get references to the different views in the workbench
> from a certain point in the code?


Your views can know their plugin, so you can put a singleton in the
plugin and reference from a static method to get your datamodel, and
from there you can register as a listener for whatever events your
datamodel can provide. i.e.

public void init(IViewSite site) throws PartInitException {
super.init(site);
MyDataModel model = MyPlugin.getDefault().getCommonModel();
setModel(model);
model.addPropertyListener(this);
}


If you want to get ahold of your views from some place (like an action
or something), globally you can start with:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().findView( "id")
or findViewReference(...).

It's better to start from somewhere in your object hierarchy if
possible. i.e.

* if you are an IViewPart, use IViewPart#getSite()#getPage(),
* if you are in an IWorkbenchWindowActionDelegate, use "window" saved as
a member from your IWorkbenchWindowActionDelegate#init(...) method,
* etc

Later,
PW


Re: RCP and MVC [message #437451 is a reply to message #437450] Wed, 28 September 2005 15:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kristof.taveirne.intec.ugent.be

Hi Paul,
I think I know everything I needed to know to get on with it now.

Thanks alot,
Greetings,
Kristof Taveirne

> kristof taveirne wrote:
>
>> The only point in the code I see a "reference" to MyView is in
>> MyPerspective#createInitialLayout(IPageLayout layout):
>> layout.addView(MyView.ID, IPageLayout.LEFT, 1.0f, editorArea);
>>
> That's the setup, but the view constructor won't be called until
> someone either switches to your perspective, or uses Window>showView
> to start your view.
>
>> (I used one of the templates in eclipse to build on)
>>
>> I don't get where and when the constructor you mentioned is called.
>>
>> I find it indeed a very good idea to have my view implement a model
>> listener interface ( like Paul Webster sugested (thanks P.)) or to
>> have a DataLoadedListener class. But to register the views to the
>> model's EventListenerList there must be some central point where I
>> can access the different views to pass them the data model so they
>> can register themself to it.
>>
>> Is there a way to get references to the different views in the
>> workbench from a certain point in the code?
>>
> Your views can know their plugin, so you can put a singleton in the
> plugin and reference from a static method to get your datamodel, and
> from there you can register as a listener for whatever events your
> datamodel can provide. i.e.
>
> public void init(IViewSite site) throws PartInitException {
> super.init(site);
> MyDataModel model = MyPlugin.getDefault().getCommonModel();
> setModel(model);
> model.addPropertyListener(this);
> }
> If you want to get ahold of your views from some place (like an action
> or something), globally you can start with:
>
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().f
> indView("id") or findViewReference(...).
>
> It's better to start from somewhere in your object hierarchy if
> possible. i.e.
>
> * if you are an IViewPart, use IViewPart#getSite()#getPage(),
> * if you are in an IWorkbenchWindowActionDelegate, use "window" saved
> as
> a member from your IWorkbenchWindowActionDelegate#init(...) method,
> * etc
> Later,
> PW
Re: RCP and MVC [message #437454 is a reply to message #437451] Wed, 28 September 2005 16:20 Go to previous messageGo to next message
Charles H Martin is currently offline Charles H MartinFriend
Messages: 79
Registered: July 2009
Member
Good luck.

Again, if you like, I can post an article on this which includes sample source code.

Indeed, I myself would like to see some different examples of this.

What Iam mostly interested in is how to create a common notification model so that other plugins can see the events that my plugin is posting. I used the Swing EventListenerList model...perhaps someone else has used the IResource approach in Eclipse?
Re: RCP and MVC [message #437455 is a reply to message #437454] Wed, 28 September 2005 16:37 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Charles Martin wrote:
> Good luck.
>
> Again, if you like, I can post an article on this which includes sample source code.
>
> Indeed, I myself would like to see some different examples of this.
>
> What Iam mostly interested in is how to create a common notification model so that other plugins can see the events that my plugin is posting. I used the Swing EventListenerList model...perhaps someone else has used the IResource approach in Eclipse?

You might have seen these already, JFace has a couple of utility classes
that fire events for model changes, like AbstractConcurrentModel and
subclasses. There are also classes in JFace like
IPropertyChangeListener/PropertyChangeEvent.

Later,
PW


Re: RCP and MVC [message #437456 is a reply to message #437455] Wed, 28 September 2005 16:56 Go to previous messageGo to next message
Charles H Martin is currently offline Charles H MartinFriend
Messages: 79
Registered: July 2009
Member
Using the JFace approach makes a lot of sense as well, thanks


I guess what I was hoping for was to create an example for cross-plugin communications for something like IResources (which are not properties), but for which the Resources are not necessarily Files or even Logical Files, but simply containers (i.e: a tree of resources)

That is, there are many applications that have a tree chooser on the left, and some view on the right, and there is a need to track global and local state (i.e for undo, playback, etc).

Maybe someone would like to put an example together?
Re: RCP and MVC [message #437470 is a reply to message #437456] Thu, 29 September 2005 09:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kristof.taveirne.intec.ugent.be

Hello Charles,

I think I've found something interesting.
I think EclipseTrader has a very nice way of handling MVC with RCP.
It has a class (DataProvider) that extends Plugin and implements IBasicDataProvider,
IExecutableExtension

The class has the typical methods like
public void start(BundleContext context) throws Exception {}
public void stop(BundleContext context) throws Exception {}

IBasisDataProvider defines the typical MVC methods like:
public void addDataListener(IDataUpdateListener listener);
public void addDataListener(IBasicData data, IDataUpdateListener listener);
public void fireDataUpdated();
public void removeDataListener(IDataUpdateListener listener);
etc. etc.

In plugin.xml I see things like:
<extension-point id="dataProvider" name="Data Provider" schema="schema/dataProvider.exsd"/>
(I haven't figured out what this is all about yet)

Then in one of the views (HistoryChartView) I've found the following line
in the createPartControl method:

IBasicData bd = TraderPlugin.getData(symbol);
where symbol is:
String id = getViewSite().getSecondaryId();
String symbol = ViewsPlugin.getDefault().getPreferenceStore().getString("chart. "
+ id); //$NON-NLS-1$

The Difference I see with the way suggested by Paul is that in the EclipseTrader
plugin the dataProvider (datamodel) has OSGi related start and stop functions,
and it is mentioned in plugin.xml.
I figured out that the OSGi related functions are things that are used by
the update manager ( is that correct?). But what the extension-point and
the extension-point schema is all about, I haven't figured out yet.
Can somebody give me some directions here? Maybe a clear article that explains
it all?


Charles: I would be very interested to read the article you have been talking
about. Could you please post it?
I'm also gonna write a small example and an article with my findings when
i've figured everything out.

Thanks in advance,
Kristof Taveirne.


> Using the JFace approach makes a lot of sense as well, thanks
>
> I guess what I was hoping for was to create an example for
> cross-plugin communications for something like IResources (which are
> not properties), but for which the Resources are not necessarily Files
> or even Logical Files, but simply containers (i.e: a tree of
> resources)
>
> That is, there are many applications that have a tree chooser on the
> left, and some view on the right, and there is a need to track global
> and local state (i.e for undo, playback, etc).
>
> Maybe someone would like to put an example together?
>
Re: RCP and MVC [message #437518 is a reply to message #437470] Thu, 29 September 2005 13:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

kristof taveirne wrote:
> [... snip ...]
> I figured out that the OSGi related functions are things that are used
> by the update manager ( is that correct?). But what the extension-point
> and the extension-point schema is all about, I haven't figured out yet.
> Can somebody give me some directions here? Maybe a clear article that
> explains it all?


I haven't seen this particular product, but:

> public void start(BundleContext context) throws Exception {}
> public void stop(BundleContext context) throws Exception {}

Are eclipse OSGi methods ... they're on every plugin, and are called
when the plugin is activated and deactivated. You can do plugin
initialization that's not taken care of elsewhere and save things like
your BundleContext, which allows access to other services in the OSGi
framework if you need them.


> [... snip ...]
> In plugin.xml I see things like:
> <extension-point id="dataProvider" name="Data Provider"
> schema="schema/dataProvider.exsd"/>
> (I haven't figured out what this is all about yet)

This plugin declares an extension point ... just standard eclipse stuff,
it says that you can write your own plugin to provide a "Data Provider"
and your extension will conform to schema/dataProvider.exsd.

Functionally, I guess it means if you provide your own dataprovider
plugin, they'll show it in their HistoryChartView for you.

Sorry I don't have a good article reference that lays this out for us.

Later,
PW


Re: RCP and MVC [message #437532 is a reply to message #437518] Thu, 29 September 2005 16:33 Go to previous message
Charles H Martin is currently offline Charles H MartinFriend
Messages: 79
Registered: July 2009
Member
I guess what I was getting at is how an RCP like Eclipse Trader can or should deal with application-application messaging

For example, Eclipse Trader has a Watchlist which contains Stock Ticker symbols. Suppose i want to integrate another application, such as an options trading application into Eclipse Trader. When i am in Eclipse Trader, and I selec an asset, I want to send a message to the options app so it will then load all options data for that stock symbol. In a more complex example, suppose I want to sync the watchlist in Eclipse Trader with the options watchlist...

Eclipse Trader does store its Watchlist as an XML file, but it is a bit of a strecth to use the IResource/IFile mechanism for messaging here. On the other hand, perhaps it would make sense to use the IResource/IContainer interfaces. Or maybe it just make sense to make some new Plugin, like an IResources plugin, but which deals with arbitrary Resources?

Any thoughts on this?
Previous Topic:Size of a RCP application
Next Topic:RCP application and BuildAction action
Goto Forum:
  


Current Time: Mon Dec 09 10:12:40 GMT 2024

Powered by FUDForum. Page generated in 0.06317 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top