Project

General

Profile

Revision f8485a00

IDf8485a00195becfc6ff2567f7fbf4735b6fb8df6
Parent fd29bcac
Child 3d4be61c

Added by Katja Luther over 4 years ago

ref #5691: avoid invalid thread access in referencing object view by calling updateContentDescription in an extra job

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java
20 20
import org.eclipse.core.runtime.IProgressMonitor;
21 21
import org.eclipse.core.runtime.IStatus;
22 22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
24
import org.eclipse.core.runtime.jobs.IJobChangeListener;
25 23
import org.eclipse.core.runtime.jobs.Job;
26
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
27 24
import org.eclipse.jface.action.MenuManager;
28 25
import org.eclipse.jface.viewers.CellEditor;
29 26
import org.eclipse.jface.viewers.ICellModifier;
......
191 188
	        return ;
192 189
	    }
193 190
	    showEmptyPage();
194
	    if(currentJob!=null){
195
	        boolean success = false;
196
	        //wait for cancel to be done
197
	        while(!success){
198
	            success = currentJob.cancel();
191
	    if(actualMonitor!=null && !actualMonitor.isCanceled()){
192
//	        boolean success = false;
193
//	        //wait for cancel to be done
194
//	        while(!success){
195
//	            success = currentJob.cancel();
196
//	        }
197
//	        currentJob = null;
198
	        while(!actualMonitor.isCanceled()){
199
	            actualMonitor.setCanceled(true);
199 200
	        }
200
	        currentJob = null;
201

  
201 202
	    }
202 203
		currentJob = new Job("Update Referencing Objects " + entityUUID) {
203 204

  
......
205 206
			protected IStatus run(IProgressMonitor monitor) {
206 207
				monitor.beginTask("Calculating referencing objects", 100);
207 208
				actualUuid = entityUUID;
208
				System.out.println("starting job... " + entityUUID);
209

  
209 210
				monitor.worked(5);
210 211
				referencingObjects = new ArrayList<>();
211 212
				if(monitor.isCanceled()) {
......
224 225

  
225 226
	                if(monitor.isCanceled()) {
226 227
	                    actualUuid = null;
227
	                    System.err.println("Job is canceled" + entityUUID);
228

  
228 229
	                    return Status.CANCEL_STATUS;
229 230
	                }
230 231
	                monitor.worked(30);
......
232 233
	                if (referencingObjects == null){
233 234
	                    if (monitor.isCanceled()){
234 235
	                        actualUuid = null;
235
	                        System.err.println("Job is canceled" + entityUUID);
236

  
236 237
	                        return Status.CANCEL_STATUS;
237 238
	                    }
238 239
	                }
......
241 242
	                    if(previousCdmEntitySession != null) {
242 243
	                        previousCdmEntitySession.bind();
243 244
	                    }
244
	                    System.err.println("Job is canceled" + entityUUID);
245

  
245 246
	                    return Status.CANCEL_STATUS;
246 247
	                }
247 248
	                monitor.worked(80);
......
254 255
				}
255 256
				monitor.done();
256 257

  
257
				System.out.println("finishing job " + entityUUID);
258

  
258 259
				return Status.OK_STATUS;
259 260

  
260 261

  
......
263 264
		currentJob.setUser(true);
264 265

  
265 266
		currentJob.schedule();
266
		final IJobChangeListener listener;
267
		listener =  new JobChangeAdapter() {
268
            @Override
269
            public void done(IJobChangeEvent event) {
270
                System.err.println("Job is done" + entityUUID);
271
                //event.getJob().cancel();
272
            }
273

  
274
        };
275
        currentJob.addJobChangeListener(listener);
267
//		final IJobChangeListener listener;
268
//		listener =  new JobChangeAdapter() {
269
//            @Override
270
//            public void done(IJobChangeEvent event) {
271
//                System.err.println("Job is done" + entityUUID);
272
//                //event.getJob().cancel();
273
//            }
274
//
275
//        };
276
//        currentJob.addJobChangeListener(listener);
276 277

  
277 278

  
278 279

  
......
342 343
        } catch (Exception e) {
343 344
            logger.error("Error retrieving referencing objects", e);
344 345
            e.printStackTrace();
345
            setContentDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
346
            updateDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
346 347
        }
347 348
		return null;
348 349
	}
......
398 399

  
399 400
        			}catch(Exception e){
400 401
        			    e.printStackTrace();
401
        				setContentDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
402
        			    updateDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
402 403
        			}
403 404

  
404 405
        		}
......
407 408
	}
408 409

  
409 410

  
410
	private void updateDescription(){
411
	private void updateDescription(final String description){
411 412
	    Display.getDefault().asyncExec(new Runnable() {
412 413
            @Override
413 414
            public void run() {
414 415
        	    if (referencedObjectTitleCache != null){
415
                    setContentDescription("'" + referencedObjectTitleCache + "' is referenced by:");
416
                    setContentDescription(description);
416 417
                } else {
417
                    setContentDescription("");
418
                    setContentDescription(description);
418 419
                }
419 420
            }
420 421

  
......
461 462
                    referencedObjectTitleCache = null;
462 463
                }
463 464
		    }
464
		    updateDescription();
465
		    if (referencedObjectTitleCache != null){
466
		        updateDescription("'" + referencedObjectTitleCache + "' is referenced by:");
467
		    } else{
468
		        updateDescription("");
469
		    }
470

  
465 471
		    updateReferencingObjects(referencedCdmObject.getUuid(),firstElement.getClass() );
466 472

  
467 473
		}
468 474
		else if (firstElement != null){
469 475
		    updateView();
470
            setContentDescription("");
476
            updateDescription("");
471 477
		}
472 478
	}
473 479

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)