View Javadoc

1   /*
2    * $Id: EditLibraryJob.java,v 1.3 2005/05/31 16:04:12 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.core.libraries;
10  
11  import org.eclipse.core.runtime.IProgressMonitor;
12  import org.eclipse.core.runtime.IStatus;
13  import org.eclipse.core.runtime.Status;
14  import org.eclipse.core.runtime.jobs.Job;
15  
16  /***
17   * Job to perform a library edit.  This allows for long-running 
18   * edits to be pushed to the background.  This job runs on a separate 
19   * thread so as not to hamper the UI during long-running operations.
20   * 
21   * @author aperezlo
22   */
23  public class EditLibraryJob extends Job implements Runnable
24  {
25     
26     private ILibraryDescriptor _library;
27     private LibraryEdit _edit;
28     private IProgressMonitor _progress;
29     
30     
31     /***
32      * Constructor.
33      * 
34      * @param ild the library upon which this edit should be performed
35      * @param edit the edit operations that should be performed
36      */
37     public EditLibraryJob(ILibraryDescriptor ild, LibraryEdit edit)
38     {
39        super("Editing Library...");
40        _library = ild;
41        _edit = edit;
42        setPriority(Job.INTERACTIVE);
43        setUser(true);
44        if(ild.getName() != null)
45        {
46           setName("Editing '" + ild.getName() + "'...");
47        }
48     }
49     
50     /*** 
51      * Run the job.
52      *
53      * @see java.lang.Runnable#run()
54      */
55     public void run()
56     {
57        IStatus toReturn = null;
58        toReturn = _library.edit(_edit, _progress);
59        if(_progress.isCanceled())
60        {
61           toReturn = Status.CANCEL_STATUS;
62        }
63        done(toReturn);
64     }
65  
66     /***
67      * Runs the job, using the monitor for progress.
68      * 
69      * This job supports cancelation.
70      * 
71      * @see org.eclipse.core.internal.jobs.InternalJob#run(org.eclipse.core.runtime.IProgressMonitor)
72      */
73     protected IStatus run(IProgressMonitor monitor)
74     {
75        _progress = monitor;
76        Thread t = new Thread(this);
77        setThread(t);
78        t.start();
79        return Job.ASYNC_FINISH; 
80     }
81  }
82