|
|
|
Re: updating table from server push in RAP [message #126820 is a reply to message #126808] |
Wed, 01 April 2009 20:54 |
Austin Riddle Messages: 128 Registered: July 2009 |
Senior Member |
|
|
Hi Tom,
Without understanding your situation, here are two considerations to keep
in mind for "pushing" information from the server:
1. The only normal way that something can get back to the client-side is
through the request life-cycle.
2. You must have a reference to the Display that belongs to the client you
are trying to "push" something to.
The idea of "pushing" something to the clients is sort of a misnomer,
since the request life-cycle only occurs when the user does something, or
while you have a UI callback active. We have a dirty little trick in our
app that actually embeds a heartbeat (a little javascript that will
initiate the life-cycle at an interval) because we found that the
UICallback mechanism was not adequate in our situation. With any of these
means you can push information to a display from application scope.
Now, in terms of updating clients, another dirty trick is to register
listeners from session scope on the data you are interested in as OSGi
services. Then when the data is changed, all of the listeners will be
notified. If those listeners have a reference to the display for that
client then the UI can be updated. Just make sure that when your app is
disposed, that those listeners are unregistered.
There are some issues with this approach (I am sure the RAP guys are
rolling their eyes right now) :). But it is perfectly viable in certain
circumstances.
Anyway, hope this helps.
|
|
|
Re: updating table from server push in RAP [message #126833 is a reply to message #126808] |
Thu, 02 April 2009 01:44 |
|
Hi.
First step.
1. You make TableViewer.
....
tableViewer = new TableViewer(container, SWT.BORDER);
// data define
tableViewer.setContentProvider(new ShowErrorContentProvider());
tableViewer.setInput(getViewSite());
// table refresh
UICallBack.activate(ShowErrorViewer.ID);
Thread notifierThread = new Thread(createRunnable(tableViewer));
notifierThread.setDaemon(true);
notifierThread.setName("ShowErrorViewer notifier");
notifierThread.start();
.....
@Override
public void dispose() {
// call back thread stop code
ControlStatus.getInstance().setSHOWERROR_VIEWER_THREAD(false );
super.dispose();
}
// runnable define
private Runnable createRunnable(final TableViewer tableViewer) {
return new Runnable() {
public void run() {
.........
// Table refresh code. refresh code is called the
ShowErrorContentProvider#getElements()
tableViewer.refresh();
.....
// refresh term code is Thread.sleep()
Thread.sleep(
ControlStatus.getInstance().getRefershSecode() * 1000 );
...
2. ContentProvider define.
public class ShowErrorContentProvider implements
IStructuredContentProvider {
..........
/**
* ControlStatus thread is get latest of the data.
*/
public Object[] getElements(Object inputElement) {
ControlStatus status = ControlStatus.getInstance();
return status.getStatusList();
}
.........
3. server push data define. DB or Socket code define there.
public class ControlStatus extends Thread {
public void run() {
... server push data there
...
}
// The latest of the data
public Object[] getStatusList() {
return (agentDAO.toArray()).clone();
}
End.
|
|
|
|
|
Re: updating table from server push in RAP [message #127201 is a reply to message #127026] |
Sat, 04 April 2009 14:33 |
Eclipse User |
|
|
|
Originally posted by: ben.fern.yahoo.com
Hello,
In fact I'd like to update a view's tableviewer of all others users that
have the same view displayed in their browser.
In fact, I have a view (Tableview) which has a tableviewer (filled with
object from a database). In this tableviewer, I have modify and delete
actions.
So when USER1 (for example) uses these actions, I'd like to update
automatically USER2's Tableview as a consequence.
I though to use server push for make that work.
Perhaps I should open a new entry in this newsgroup.
|
|
|
|
Powered by
FUDForum. Page generated in 0.05828 seconds