Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] how to start threads with monitor?

Hi Andrea.  I think we need more of your intentions.  So usually if you are running with a progress monitor you are NOT in the Display thread so you can't do any UI stuff, much like Swing.  Second that method has a bug so the progress monitor is currently hidden.  I will fix that bug.  For now use runInProgressDialog  So for your example you may want to do:

final Runnable openMessage = new Runnable(){
public void run(){
MessageDialog dialog = new MessageDialog(new Shell(SWT.BORDER | 
SWT.DIALOG_TRIM),
"Warning", null, "Will I show up?",
MessageDialog.WARNING, new String[]{"Ok"}, 0);
                dialog.open();
            }
}
}

IRunnableWithProgress operation = new IRunnableWithProgress(){



public void run( IProgressMonitor monitor ) throws
InvocationTargetException, InterruptedException {
monitor.beginTask("Message!!!", 100);

Display.getDefault().asyncExec( openMessage );

        };


runInProgressDialog( "Running my Operation", true, operation );

Jesse


On Apr 26, 2007, at 2:43 PM, Andrea Antonello wrote:

Hi Jesse,
I think I really miss a piece of the truth...

Reduced to the minimum, I now only try to launch a messagedialog from
within the run method of the  AbstractActionTool retrieved from the
tools extention point. It is really few code:

IRunnableWithProgress runner = new IRunnableWithProgress(){

public void run( IProgressMonitor monitor ) throws
InvocationTargetException, InterruptedException {
monitor.beginTask("Message!!!", 100);
MessageDialog dialog = new MessageDialog(new Shell(SWT.BORDER | 
SWT.DIALOG_TRIM),
"Warning", null, "Will I show up?",
MessageDialog.WARNING, new String[]{"Ok"}, 0);
                dialog.open();
            }

        };

PlatformGIS.run(runner);


This gives the usual error of invealid thread access. What is wrong here?
If I use the runBlockingOperation method it is worse, nothing shows up.

Any idea?
Andrea






Jesse Eichar probaly wrote:
Hi,

Display widgets can only be modified in the display thread.  Take a look
at the methods is PlatformGIS for a bunch of help with regards to
threading.

As mentioned Jobs start up a new thread and allow progress to be
monitored.  If you set the job's setUser( true ) then the progress
dialog will open.  Remember that you have to update UI components in the
Display thread.  Display.asyncExec for example.

Jesse

On Apr 23, 2007, at 6:40 AM, Andrea Antonello wrote:

Thanks for your reply Zlatko,
I tried also the Job way, but I get the same Invalid Thread Access
exception:

Job job = new Job("my job ") {
     protected IStatus run(IProgressMonitor monitor) {
           domyCodeWork()
           return Status.OK_STATUS;
        }
     };

  job.schedule();


Also the code you modified below doesn't work with the same error...

I'm really confused (and I'm rather new to RCP and SWT), sinced in my
opinion it happens often that you launch a dialog and while the dialog
is there you do some work, without freezing the interface. But I can't
find working examples.

In swing there was this SwingUtilities.invokelater that worked pretty
well.

I guess I 'm missing something of the deeper theory.

Isn't there in udig an Action that does something like that?

Andrea



Zlatko Perenda probaly wrote:
Hi,

I did some asking around, this is what a friend of mine came up with....

You have to implement a job, org.eclipse.core.runtime.jobs.Job . You
have
run(IprogressMonitor pm) there, where you implement the method and
change
whatever you want through pm. You can add listeners if you want to do
something after the job is done.

And your code from first post, reworked some

Display display = Display.getCurrent();
            if (display == null)
            {
                display = Display.getDefault();
            }
 display.asyncExec(new Runnableevent)
                    {
                        public void run()
                        {
        IWorkbench wb = PlatformUI.getWorkbench();
        IProgressService ps = wb.getProgressService();
            ps.busyCursorWhile(new IRunnableWithProgress(){
                public void run( IProgressMonitor pm ) {
                    doMyCodeWithMonitorActivity()
                }
            });

     }
                    });

I hope this helps....

Zlatko.

-----Original Message-----
From: Andrea Antonello [mailto:andrea.antonello@xxxxxxxxx]
Sent: Monday, April 23, 2007 2:42 PM
To: Zlatko Perenda
Cc: 'User-friendly Desktop Internet GIS'
Subject: Re: [udig-devel] how to start threads with monitor?

Hi Zlatko,
that is indeed what I am doing to make it work for now (the asyncExec I
mean), but that doesn't supply my the so much loved monitor...
Where do I get the monitor from?

Thanks,
Andrea



Zlatko Perenda probaly wrote:
Hm, seems like you are accesing UI thread, from another....

Try Display.asyncExec(runnable), and let runnable do the neccesary
work. I
think this should work.


-----Original Message-----
Antonello
Sent: Monday, April 23, 2007 2:25 PM
To: User-friendly Desktop Internet GIS
Subject: [udig-devel] how to start threads with monitor?

I know this is more a rcp question than  a udig, but I'm not able to
add
progress tracking to my actions.
The tool extention point doesn't supply a monitor and whenever I try
somethin g like:
        IWorkbench wb = PlatformUI.getWorkbench();
        IProgressService ps = wb.getProgressService();

            ps.busyCursorWhile(new IRunnableWithProgress(){
                public void run( IProgressMonitor pm ) {

                    doMyCodeWithMonitorActivity()
                }
            });
I get an Invalid thread access exception.

Any hint?
Thanks in advance,
Andrea
_______________________________________________
User-friendly Desktop Internet GIS (uDig)




_______________________________________________
User-friendly Desktop Internet GIS (uDig)




Back to the top