Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2c4ec6f618bdfc6135525ec56411c9a65fd20321 (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
/*******************************************************************************
 * Copyright (c) 2010 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.framework.ui.skynet.change;

import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.window.Window;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.plugin.core.util.Jobs;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.IBranchProvider;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.branch.BranchSelectionDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.progress.UIJob;

public final class UiOtherBranchDialogProvider implements IBranchProvider {
   private final ChangeUiData uiData;

   public UiOtherBranchDialogProvider(ChangeUiData uiData) {
      this.uiData = uiData;
   }

   @Override
   public IOseeBranch getBranch(IProgressMonitor monitor) throws OseeCoreException {
      final IOseeBranch[] selectedBranch = new IOseeBranch[1];
      final Collection<? extends BranchId> selectable = BranchManager.getBaselineBranches();
      selectable.remove(uiData.getTxDelta().getStartTx().getBranch());
      IStatus status = executeInUiThread(selectable, selectedBranch);
      monitor.setCanceled(status.getSeverity() == IStatus.CANCEL);
      return selectedBranch[0];
   }

   private IStatus executeInUiThread(final Collection<? extends BranchId> selectable, final BranchId[] selectedBranch) throws OseeCoreException {
      IStatus status = null;
      Display display = AWorkbench.getDisplay();
      if (display.getThread().equals(Thread.currentThread())) {
         status = getUserSelection(selectable, selectedBranch);
      } else {
         Job job = new UIJob("Select Branch") {
            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
               return getUserSelection(selectable, selectedBranch);
            }
         };
         try {
            Jobs.startJob(job).join();
         } catch (InterruptedException ex) {
            OseeCoreException.wrapAndThrow(ex);
         }
         status = job.getResult();
      }
      return status;
   }

   private IStatus getUserSelection(Collection<? extends BranchId> selectable, BranchId[] selectedBranch) {
      IStatus status = Status.OK_STATUS;
      BranchSelectionDialog dialog = new BranchSelectionDialog("Select branch to compare against", selectable);
      int result = dialog.open();
      if (result == Window.OK) {
         selectedBranch[0] = dialog.getSelection();
      } else {
         status = Status.CANCEL_STATUS;
      }
      return status;
   }
}

Back to the top