how to update a view in real-time? [message #435652] |
Sun, 21 August 2005 02:37 |
Eclipse User |
|
|
|
Originally posted by: Nickwtf.charter.net
lets say I have a class called "CurrentData" that keeps track of some data
that keeps changing, and it has a method like getData() which just returns
the current data
now if I had a view and i wanted to constantly update a table in the view
with the current data, how might i accomplish that?
Ive read how to update a view based on an action that occurs in another view
or from the menumanager, but i want this view to keep updating without being
triggered by any user action.
thanks for any help you can offer
Nick
|
|
|
|
|
Re: how to update a view in real-time? [message #435746 is a reply to message #435653] |
Mon, 22 August 2005 18:46 |
Eclipse User |
|
|
|
Originally posted by: Nickwtf.charter.net
thanks. I used the eventLoopIdle method in the WorkSpace advisor class to
call the setData method in my view and it worked well.
what i was missing was:
MyView myView = (MyView)
MyPlugin.getDefault().getWorkbench().getActiveWorkbenchWindo w().getActivePage().findView( "MyView");
my problem before was that i was just instantiating myView by just doing
MyView myView = new MyView();
this obviously didint work, but its working now with the new statement.
thanks again
"Glenn Marintes" <gmarintes@laseritesystems.com> wrote in message
news:de9645$f26$1@news.eclipse.org...
> Each view in RCP have a unique id. Use that id to findView(..) or
> showView(..) the view that contains the table dat you want to update.
> Those two methods return an IViewPart which is basically the instance
> of your view. You can safely typecast it to the actual class type
> of your view and then call a method in your view ie.. setData(...)
>
> Nick DelRossi wrote:
>> lets say I have a class called "CurrentData" that keeps track of some
>> data that keeps changing, and it has a method like getData() which just
>> returns the current data
>>
>> now if I had a view and i wanted to constantly update a table in the view
>> with the current data, how might i accomplish that?
>>
>> Ive read how to update a view based on an action that occurs in another
>> view or from the menumanager, but i want this view to keep updating
>> without being triggered by any user action.
>>
>> thanks for any help you can offer
>> Nick
|
|
|
Re: how to update a view in real-time? [message #435747 is a reply to message #435709] |
Mon, 22 August 2005 18:52 |
Eclipse User |
|
|
|
Originally posted by: Nickwtf.charter.net
This was a huge help. From what you and Glenn suggested, i was able to
figure it out. Thanks
"Ricky" <ImmortalRick@gmx.de> wrote in message
news:op.svwq6lqaaudqvk@localhost.localdomain...
>> now if I had a view and i wanted to constantly update a table in the view
>> with the current data, how might i accomplish that?
>
> Your CurrentData class could generate change events and your view
> registers as a listener to this events directly at CurrentData. To
> decouple things a bit you could create the class Mediator which listens to
> change events from CurrentData and triggers changes in the view. This way
> your "business logic" is encapsulated in the mediator and your view can
> remain unaware of the model data.
>
> To deflect myself from urgent work here my thoughts as untested code:
>
> // Your Model
> public class CurrentData
> private List changeListeners;
> public void addChangeListener(ChangeListener changeListener){
> this.changeListeners.add(changeListener);
> }
> // Gets called whenever something interessting changed.
> private void fireChangeEvent(){
> EventObject event = new EventObject(this);
> //loop changeListeners and call handleEvent(event).
> }
>
>
> public interface ChangeListener
> public void handleEvent(EventObject event);
>
>
> public class MyView implements ChangeListener
> handleEvent(EventObject event){
> // Something changed in the model, go get it.
> CurrentData currentData = (CurrentData) event.getSource();
> // get the data out of the model and stuff it into your controls.
> }
>
> To make the view unaware of the data source let the view have a proper API
> to access the table from the outside and have a man-in-the-middle
>
> class Mediator implements ChangeListener{
> handleEvent(EventObject event){
> CurrentData currentData = (CurrentData) event.getSource();
> IViewPart myView =
> MyPlugin.getDefault().getWorkbench().getActiveWorkbenchWindo w().getActivePage().findView( "id.of.myview");
> // setData should be more general than getData or this Mediator
> indirection is useless.
> myView.setData(currentData.getData());
>
> If you need a hard real time system you can optimize a bit by having only
> one listener in CurrentData so you do not need to loop. Have only one
> intance of EventObject created in the constructor and be sure that nobody
> manipulates it. Caching the view is also a good idea and have fine
> granular events to change only a bit at a time.
>
> I hope I havent misunderstood you problem complety and this is of any use
> to you.
>
> Ricky
|
|
|
Powered by
FUDForum. Page generated in 0.04337 seconds