[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [udig-devel] how to start threads with monitor?
|
alright, I'm not as good as I would like in describing things :)
So here I go:
I used the tool extention point to create an Action. This is a button in
the toolbar that launches a dialog used to configure the module.
So I click on the button and a fancy dialog appears. I set my variables
and maps and push the start button. At that point I would like to have
my whole gui not to be blocked, while the algorithm does its work.
Also I would give feedback to the user about what is going on, so I need
the monitor instance.
Your example below has two problems;
- it starts up a progress window while the user has to first fill in
stuff in the dialog, so no work is done at that point (only after
pushing start button on the dialog)
- I do not have the monitor instance yet
Andrea
Jesse Eichar probaly wrote:
> 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-----
>>>>>> From: udig-devel-bounces@xxxxxxxxxxxxxxxxxxxxx
>>>>>> <mailto:udig-devel-bounces@xxxxxxxxxxxxxxxxxxxxx>
>>>>>> [mailto:udig-devel-bounces@xxxxxxxxxxxxxxxxxxxxx] On Behalf Of Andrea
>>>>>> 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)
>>>>>> http://udig.refractions.net
>>>>>> http://lists.refractions.net/mailman/listinfo/udig-devel
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>> _______________________________________________
>>>> User-friendly Desktop Internet GIS (uDig)
>>>> http://udig.refractions.net
>>>> http://lists.refractions.net/mailman/listinfo/udig-devel
>>>
>>>
>