[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: how to update a view in real-time?

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().getActiveWorkbenchWindow().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