so each time the table view is created and displayed, it asks the content provider to provide the content, and the latter asks to a DAO to load the data from the database. I'd like to notify the user about what is happening within the DAO logic, so I created a wrapper for a status line manager that is used directly from within the DAO thru the following method:

The problem is that the message is never displayed and a little debugging shows that the thread that is executing the

statusLineManager.setMessage(message);

is the "main" thread, is this correct? How can I get the status line displaying messages from the DAO in sync?

Thanks.]]>Luca Ferrari2010-08-30T14:01:36-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/556018/#msg_556018
fluca1978@infinito.it> wrote in message
news:i5gdk1$qs5$1@build.eclipse.org...
> Hi all,
> in my rcp application I've got the following call chain:
>
> MyTableViewer -> MyContentProvider -> MyDao.loadElementsFromDatabase()
>
>
> so each time the table view is created and displayed, it asks the content
> provider to provide the content, and the latter asks to a DAO to load the
> data from the database. I'd like to notify the user about what is
> happening within the DAO logic, so I created a wrapper for a status line
> manager that is used directly from within the DAO thru the following
> method:
>
> public void setMessage(final String message) {
> PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable(){
>
> public void run() {
> statusLineManager.setMessage(message);
> }
> });
>
> }
>
>
>
> The problem is that the message is never displayed and a little debugging
> shows that the thread that is executing the
> statusLineManager.setMessage(message); is the "main" thread, is this
> correct? How can I get the status line displaying messages from the DAO in
> sync?
>
> Thanks.

You need to fork off the call to the DAO in another thread. You can use the
Eclipse Job API to do this. That will free up the GUI thread to handle
other tasks such as displaying your status update.]]>David Wegener2010-08-30T14:34:30-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/556274/#msg_556274
Luca Ferrari2010-08-31T14:59:11-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/556339/#msg_556339
fluca1978@infinito.it> wrote in message
news:i5j5c7$d16$1@build.eclipse.org...
> The problem is that my DAO returns a list of objects that must be
> displayed in the view, so the call to the DAO cannot be async or done by
> another thread. Someone can better explain how to do this?

There isn't another way to do it. In order for the user interface to get
updated, the Display thread has to continue. If the Display thread is
waiting in your code for the return from the DAO, it can't update the UI.

You need to fork off a thread. In that thread call the DAO. When the DAO
returns, create a runnable whose run method processes the results and
populates the view. Pass this to the Display.asyncExec call.]]>David Wegener2010-08-31T20:44:13-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/558428/#msg_558428
Thanks]]>Luca Ferrari2010-09-12T19:01:24-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/632060/#msg_632060
1) I created a "worker" thread that in its run method loads all the data from the DAO and calls inputChanged on the content provider
2) whithin the content provider I've got an asyncExec that sets the data into the viewer and forces a refresh:

The problem now is that, when the application is closed, I got an exception about the viewer.refresh() call saying that the widget is disposed. The problem is that I don't know what view is exactly disposed and why....any help or possible explaination?

Thanks

org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
at org.eclipse.swt.SWT.error(SWT.java:4083)
at org.eclipse.swt.SWT.error(SWT.java:3998)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3515)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3164)
at org.eclipse.swt.widgets.Display.release(Display.java:3215)
at org.eclipse.swt.graphics.Device.dispose(Device.java:237)
at hrpm.rcp.Application.start(Application.java:31)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4083)
at org.eclipse.swt.SWT.error(SWT.java:3998)
at org.eclipse.swt.SWT.error(SWT.java:3969)
at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:403)
at org.eclipse.swt.widgets.Table.deselectAll(Table.java:956)
at org.eclipse.jface.viewers.TableViewer.doDeselectAll(TableViewer.java:277)
at org.eclipse.jface.viewers.AbstractTableViewer.setSelectionToWidget(AbstractTableViewer.java:908)
at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:1741)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1429)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1383)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1485)
at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1444)
at hrpm.rcp.gui.providers.content.BaseTableContentProvider$1.run(BaseTableContentProvider.java:224)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
... 18 more

]]>Luca Ferrari2010-10-11T12:18:36-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/632063/#msg_632063
> I think I've almost done:
> 1) I created a "worker" thread that in its run method loads all the data
> from the DAO and calls inputChanged on the content provider
> 2) whithin the content provider I've got an asyncExec that sets the data
> into the viewer and forces a refresh:
>
>
> public void inputChanged(final Viewer viewer, Object oldInput, final
> Object newInput) {
>
> PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable(){
>
> @Override
> public void run() {
> ....
> viewer.refresh();
>
> }
> });
>
>
>
> }
>
>
> The problem now is that, when the application is closed, I got an
> exception about the viewer.refresh() call saying that the widget is
> disposed. The problem is that I don't know what view is exactly disposed
> and why....any help or possible explaination?

This situation may always occur with an asyncExec call, because you
don't know when your runnable will be called. Always check first in such
a runnable whether your widget is not already disposed. If so, just
handle this is noop (i.e. exit the runnable).

HTH & Greetings from Bremen,

Daniel Krügler]]>Daniel KrÃ¼gler2010-10-11T12:22:08-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/632481/#msg_632481

viewer.getControl().isDisposed()

but it does not work.
Any suggestion?

Thanks,
Luca]]>Luca Ferrari2010-10-13T06:59:34-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/632555/#msg_632555
> Ok, this is strange, but what is the way to test if a viewer has been
> disposed? I don't find a isDisposed() method in the Viewer class, so I
> tried with viewer.getControl().isDisposed()
> but it does not work.
> Any suggestion?

What does "it does not work" mean? What Viewer class are you using?
I assume there must be a stacktrace that points to the affected widget,
so which one complains?

- Daniel]]>Daniel KrÃ¼gler2010-10-13T12:16:14-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/632766/#msg_632766
However, now that I guess I've understood the asyncExec a little more, does it make sense to use a thread to load the elements and execute a runnable instead of using a Job scheduled immediately?]]>Luca Ferrari2010-10-14T08:33:32-00:00Re: help on status manager and (a)syncExechttps://www.eclipse.org/forums/index.php/mv/msg/174562/632815/#msg_632815
> However, now that I guess I've understood the asyncExec a little more,
> does it make sense to use a thread to load the elements and execute a
> runnable instead of using a Job scheduled immediately?

I think the basic guide-line should be:

1) If you need to interact with the UI, use asyncExec

2) If your work has considerable parts that are UI-independent, use
a job for this. You will run in problematic situations, when
you have several dependent work units of the form

UI -> non-UI -> UI -> non-UI ->...

etc. If possible, try to isolate UI and non-UI work-units in as large
blocks as possible to prevent the overhead of an unnecessary high
number of context switching.