Skip to main content
summaryrefslogtreecommitdiffstats
blob: 694ac2b6243e1540086183180c9d68ab63e6c9c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.define.traceability.jobs;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.osee.define.DefinePlugin;
import org.eclipse.osee.define.traceability.operations.FindTraceUnitFromResource;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.plugin.core.util.IExceptionableRunnable;
import org.eclipse.osee.framework.plugin.core.util.Jobs;
import org.eclipse.osee.framework.ui.skynet.branch.BranchSelectionDialog;
import org.eclipse.ui.progress.UIJob;

/**
 * @author Roberto E. Escobar
 */
public class FindTraceUnitJob extends Job {
   private final IResource[] resources;

   public FindTraceUnitJob(String name, IResource... resources) {
      super(name);
      if (resources != null) {
         this.resources = resources;
      } else {
         this.resources = new IResource[0];
      }
   }

   @Override
   protected IStatus run(IProgressMonitor monitor) {
      if (resources != null && resources.length > 0) {
         FetchBranchJob job = new FetchBranchJob(getName());
         Jobs.startJob(job, true, new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
               FetchBranchJob fetcherJob = (FetchBranchJob) event.getJob();
               final Branch branch = fetcherJob.getSelectedBranch();
               if (branch != null) {
                  IExceptionableRunnable runnable = new IExceptionableRunnable() {

                     @Override
                     public IStatus run(IProgressMonitor monitor) throws Exception {
                        if (branch != null) {
                           FindTraceUnitFromResource.search(branch, resources);
                        }
                        return Status.OK_STATUS;
                     }
                  };
                  Jobs.runInJob(getName(), runnable, DefinePlugin.class, DefinePlugin.PLUGIN_ID);
               }
            }
         });
      }
      return Status.OK_STATUS;
   }
   private static final class FetchBranchJob extends UIJob {
      private Branch branch;

      public FetchBranchJob(String name) {
         super(name);
         branch = null;
      }

      @Override
      public IStatus runInUIThread(IProgressMonitor monitor) {
         branch = BranchSelectionDialog.getBranchFromUser();
         return Status.OK_STATUS;
      }

      public Branch getSelectedBranch() {
         return branch;
      }
   }
}

Back to the top