Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9bfc8a6b622742611af458b05706d8e994772ab0 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/*******************************************************************************
 * 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.framework.ui.skynet.widgets.xmerge;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Level;
import org.eclipse.core.runtime.IAdaptable;
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.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osee.framework.core.data.SystemUser;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.plugin.core.IActionable;
import org.eclipse.osee.framework.plugin.core.util.Jobs;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.IATSArtifact;
import org.eclipse.osee.framework.skynet.core.conflict.Conflict;
import org.eclipse.osee.framework.skynet.core.conflict.ConflictManagerExternal;
import org.eclipse.osee.framework.skynet.core.revision.ConflictManagerInternal;
import org.eclipse.osee.framework.skynet.core.types.IArtifact;
import org.eclipse.osee.framework.ui.plugin.OseeUiActions;
import org.eclipse.osee.framework.ui.plugin.PluginUiImage;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.plugin.util.ListSelectionDialogNoSave;
import org.eclipse.osee.framework.ui.skynet.ArtifactImageManager;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
import org.eclipse.osee.framework.ui.skynet.change.ChangeUiUtil;
import org.eclipse.osee.framework.ui.skynet.cm.OseeCm;
import org.eclipse.osee.framework.ui.skynet.cm.OseeCmEditor;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
import org.eclipse.osee.framework.ui.skynet.render.RendererManager;
import org.eclipse.osee.framework.ui.skynet.widgets.XWidget;
import org.eclipse.osee.framework.ui.swt.ALayout;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.IDirtiableEditor;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Tree;

/**
 * @author Donald G. Dunne
 * @author Theron Virgin
 */
public class MergeXWidget extends XWidget implements IAdaptable {
   private static final String COMPLETE_COMMIT_ACTION_ID = "complete.commit.action.id";
   private static final String REFRESH_ACTION_ID = "refresh.action.id";
   private MergeXViewer mergeXViewer;
   private IDirtiableEditor editor;
   public final static String normalColor = "#EEEEEE";
   private static final String LOADING = "Loading ...";
   private static final String NO_CONFLICTS = "No conflicts were found";
   private static final String CONFLICTS_NOT_LOADED = "Cleared on shutdown.  Refresh to Reload.";
   private Label extraInfoLabel;
   private String displayLabelText;
   private Action openAssociatedArtifactAction;
   private Action completeCommitAction;
   private Branch sourceBranch;
   private Branch destBranch;
   private TransactionRecord commitTrans;
   private TransactionRecord tranId;
   private MergeView mergeView;
   private IToolBarManager toolBarManager;
   private final static String CONFLICTS_RESOLVED = "\nAll Conflicts Are Resolved";

   public MergeXWidget() {
      super("Merge Manager");
   }

   @Override
   protected void createControls(Composite parent, int horizontalSpan) {
      Composite mainComp = new Composite(parent, SWT.BORDER);
      Composite taskComp = new Composite(mainComp, SWT.NONE);
      taskComp.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
      taskComp.setLayout(ALayout.getZeroMarginLayout());
      createTextWidgets(parent);
      createMainComposite(mainComp);
      mergeXViewer = new MergeXViewer(mainComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION, this);
      createMergeXViewer();
      createTaskActionBar(taskComp);
      if (toolkit != null) {
         toolkit.adapt(mergeXViewer.getStatusLabel(), false, false);
      }
      Tree tree = mergeXViewer.getTree();
      createTree(tree);
   }

   private void createTextWidgets(Composite parent) {
      if (isDisplayLabel() && !getLabel().equals("")) {
         labelWidget = new Label(parent, SWT.NONE);
         labelWidget.setText(getLabel() + ":");
         if (getToolTip() != null) {
            labelWidget.setToolTipText(getToolTip());
         }
      }
   }

   private void createMainComposite(Composite mainComp) {
      mainComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      mainComp.setLayout(ALayout.getZeroMarginLayout());
      if (toolkit != null) {
         toolkit.paintBordersFor(mainComp);
      }

   }

   private void createMergeXViewer() {
      mergeXViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
      XMergeLabelProvider labelProvider = new XMergeLabelProvider(mergeXViewer);
      mergeXViewer.addLabelProvider(labelProvider);
      mergeXViewer.setSorter(new MergeXViewerSorter(mergeXViewer, labelProvider));
      mergeXViewer.setContentProvider(new XMergeContentProvider());
      mergeXViewer.setLabelProvider(new XMergeLabelProvider(mergeXViewer));
   }

   private void createTree(Tree tree) {
      GridData gridData = new GridData(GridData.FILL_BOTH);
      gridData.heightHint = 100;
      tree.setLayout(ALayout.getZeroMarginLayout());
      tree.setLayoutData(gridData);
      tree.setHeaderVisible(true);
      tree.setLinesVisible(true);
   }

   public void createTaskActionBar(Composite parent) {
      Composite composite = new Composite(parent, SWT.NONE);
      GridLayout layout = ALayout.getZeroMarginLayout(2, false);
      layout.marginLeft = 5;
      composite.setLayout(layout);
      composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      extraInfoLabel = new Label(composite, SWT.NONE);
      extraInfoLabel.setAlignment(SWT.LEFT);
      extraInfoLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      extraInfoLabel.setText("\n");

      IToolBarManager manager = getToolBarManager();
      ((ToolBarManager) manager).createControl(composite);
      manager.add(new RefreshAction());
      manager.add(new Separator());
      openAssociatedArtifactAction = new OpenAssociatedArtifactAction();
      manager.add(openAssociatedArtifactAction);
      manager.add(new Separator());
      manager.add(new ApplyPriorMergeResultsAction());
      manager.add(new Separator());
      manager.add(new ShowSourceBranchChangeReportAction());
      manager.add(new ShowDestinationBranchChangeReportAction());
      manager.add(new Separator());
      manager.add(mergeXViewer.getCustomizeAction());
      manager.add(OseeUiActions.createBugAction(SkynetGuiPlugin.getInstance(), this, MergeView.VIEW_ID, "Merge Manager"));
      manager.update(true);
   }

   private IToolBarManager getToolBarManager() {
      if (toolBarManager == null) {
         toolBarManager = new ToolBarManager(SWT.FLAT);
      }
      return toolBarManager;
   }

   private void applyPreviousMerge(final int destBranchId) {
      Job job = new Job("Apply Previous Merge") {

         @Override
         protected IStatus run(final IProgressMonitor monitor) {
            Conflict[] conflicts = getConflicts();

            monitor.beginTask("ApplyingPreviousMerge", conflicts.length);
            for (Conflict conflict : conflicts) {
               try {
                  Branch destinationBranch = BranchManager.getBranch(destBranchId);
                  Branch mergeBranch = BranchManager.getMergeBranch(conflict.getSourceBranch(), destinationBranch);
                  conflict.applyPreviousMerge(mergeBranch.getId(), destBranchId);
               } catch (OseeCoreException ex) {
                  OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
               } finally {
                  monitor.worked(1);
               }
            }
            monitor.done();
            return Status.OK_STATUS;
         }
      };

      Jobs.startJob(job, new JobChangeAdapter() {
         @Override
         public void done(IJobChangeEvent event) {
            loadTable();
         }
      });
   }

   public void refreshTable() {
      Job job = new Job("Loading Merge Manager") {
         @Override
         protected IStatus run(IProgressMonitor monitor) {
            try {
               Conflict[] conflicts = getConflicts();
               if (conflicts.length >= 0) {
                  Conflict[] artifactChanges = new Conflict[0];
                  if (conflicts[0].getToTransactionId() != null) {
                     setConflicts(ConflictManagerInternal.getConflictsPerBranch(conflicts[0].getSourceBranch(),
                        conflicts[0].getDestBranch(), conflicts[0].getToTransactionId(), monitor).toArray(
                        artifactChanges));
                  } else {
                     setConflicts(ConflictManagerInternal.getConflictsPerBranch(conflicts[0].getCommitTransactionId(),
                        monitor).toArray(artifactChanges));
                  }
               }
            } catch (Exception ex) {
               OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
            }

            return Status.OK_STATUS;
         }
      };
      Jobs.startJob(job, new JobChangeAdapter() {
         @Override
         public void done(IJobChangeEvent event) {
            loadTable();
         }
      });
   }

   public void loadTable() {
      Displays.ensureInDisplayThread(new Runnable() {
         @Override
         public void run() {
            refresh();
         }
      });
   }

   public ArrayList<Conflict> getSelectedConflicts() {
      ArrayList<Conflict> items = new ArrayList<Conflict>();
      if (mergeXViewer != null && !mergeXViewer.getSelection().isEmpty()) {
         IStructuredSelection structuredSelection = (IStructuredSelection) mergeXViewer.getSelection();
         Iterator<?> i = structuredSelection.iterator();
         while (i.hasNext()) {
            Object obj = i.next();
            items.add((Conflict) obj);
         }
      }
      return items;
   }

   @Override
   public Control getControl() {
      return mergeXViewer.getTree();
   }

   @Override
   public void dispose() {
      mergeXViewer.dispose();
   }

   @Override
   public void setFocus() {
      mergeXViewer.getTree().setFocus();
   }

   public Conflict[] getConflicts() {
      return mergeXViewer != null ? mergeXViewer.getConflicts() : MergeXViewer.EMPTY_CONFLICTS;
   }

   @Override
   public void refresh() {
      mergeXViewer.refresh();
      validate();
      mergeView.showConflicts(true);
      int resolved = 0;
      int informational = 0;
      Conflict[] conflicts = getConflicts();
      if (conflicts.length > 0) {
         for (Conflict conflict : conflicts) {
            if (conflict.statusResolved() || conflict.statusCommitted()) {
               resolved++;
            }
            if (conflict.statusInformational()) {
               informational++;
            }
         }
         if (resolved == conflicts.length) {
            extraInfoLabel.setText(displayLabelText + CONFLICTS_RESOLVED);
         } else {
            extraInfoLabel.setText(displayLabelText + "\nConflicts : " + (conflicts.length - informational) + " <=> Resolved : " + resolved + (informational == 0 ? " " : "\nInformational Conflicts : " + informational));
         }
      }
      checkForCompleteCommit();
   }

   private boolean areAllConflictsResolved() {
      int resolved = 0;
      Conflict[] conflicts = getConflicts();
      for (Conflict conflict : conflicts) {
         if (conflict.statusResolved() || conflict.statusCommitted() || conflict.statusInformational()) {
            resolved++;
         }
      }
      return resolved == conflicts.length;
   }

   @Override
   public IStatus isValid() {
      return Status.OK_STATUS;
   }

   @Override
   public void setXmlData(String str) {
      // do nothing
   }

   @Override
   public String getXmlData() {
      return null;
   }

   @Override
   public String toHTML(String labelFont) {
      return AHTML.simplePage("Unhandled");
   }

   @Override
   public String getReportData() {
      return null;
   }

   /**
    * @return Returns the xViewer.
    */
   public MergeXViewer getXViewer() {
      return mergeXViewer;
   }

   @Override
   public Object getData() {
      return getConflicts();
   }

   public IDirtiableEditor getEditor() {
      return editor;
   }

   public void setEditor(IDirtiableEditor editor) {
      this.editor = editor;
   }

   public void setInputData(final Branch sourceBranch, final Branch destBranch, final TransactionRecord tranId, final MergeView mergeView, final TransactionRecord commitTrans, boolean showConflicts) {
      setInputData(sourceBranch, destBranch, tranId, mergeView, commitTrans, "", showConflicts);
   }

   public void setInputData(final Branch sourceBranch, final Branch destBranch, final TransactionRecord tranId, final MergeView mergeView, final TransactionRecord commitTrans, String loadingText, final boolean showConflicts) {
      this.sourceBranch = sourceBranch;
      this.destBranch = destBranch;
      this.tranId = tranId;
      this.mergeView = mergeView;
      this.commitTrans = commitTrans;
      extraInfoLabel.setText(LOADING + loadingText);
      Job job = new Job("Loading Merge Manager") {
         @Override
         protected IStatus run(IProgressMonitor monitor) {
            try {
               if (showConflicts) {
                  Conflict[] conflicts;
                  if (commitTrans == null) {
                     conflicts =
                        ConflictManagerInternal.getConflictsPerBranch(sourceBranch, destBranch, tranId, monitor).toArray(
                           new Conflict[0]);
                  } else {
                     conflicts =
                        ConflictManagerInternal.getConflictsPerBranch(commitTrans, monitor).toArray(new Conflict[0]);
                  }
                  mergeXViewer.setConflicts(conflicts);
               }
            } catch (Exception ex) {
               OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
            }
            return Status.OK_STATUS;
         }
      };
      Jobs.startJob(job, new JobChangeAdapter() {

         @Override
         public void done(IJobChangeEvent event) {
            Displays.ensureInDisplayThread(new Runnable() {
               @Override
               public void run() {
                  if (showConflicts) {
                     Conflict[] conflicts = getConflicts();
                     if (conflicts.length == 0) {
                        extraInfoLabel.setText(NO_CONFLICTS);
                     } else {
                        setConflicts(conflicts);
                        refresh();
                     }
                  } else {
                     extraInfoLabel.setText(CONFLICTS_NOT_LOADED);
                  }
                  checkForCompleteCommit();
               }
            });
         }

      });
      if (sourceBranch != null) {
         refreshAssociatedArtifactItem(sourceBranch);
      }
   }

   private void refreshAssociatedArtifactItem(Branch sourceBranch) {
      try {
         IArtifact branchAssociatedArtifact = BranchManager.getAssociatedArtifact(sourceBranch);
         if (branchAssociatedArtifact != null) {
            openAssociatedArtifactAction.setImageDescriptor(ArtifactImageManager.getImageDescriptor(branchAssociatedArtifact));
            openAssociatedArtifactAction.setEnabled(true);
         }
      } catch (Exception ex) {
         OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
      }
   }

   public void setConflicts(Conflict[] conflicts) throws IllegalStateException {
      mergeXViewer.setConflicts(conflicts);
      loadTable();
      int resolved = 0;
      int informational = 0;
      for (Conflict conflict : getConflicts()) {
         if (conflict.statusResolved() || conflict.statusCommitted()) {
            resolved++;
         }
         if (conflict.statusInformational()) {
            informational++;
         }
      }
      Conflict[] storedConflicts = getConflicts();
      if (storedConflicts.length > 0) {
         StringBuilder builder = new StringBuilder();
         if (sourceBranch != null) {
            builder.append("Source Branch :  ");
            builder.append(sourceBranch.getName());
            builder.append("\nDestination Branch :  ");
            builder.append(destBranch.getName());
         } else {
            builder.append("Commit Transaction ID :  ");
            builder.append(commitTrans);
            builder.append(" ");
            builder.append(commitTrans.getComment());
         }
         displayLabelText = builder.toString();

         if (resolved == storedConflicts.length - informational) {
            extraInfoLabel.setText(displayLabelText + CONFLICTS_RESOLVED);
         } else {
            String message =
               String.format("%s\nConflicts : %s <=> Resolved : %s%s", displayLabelText,
                  (storedConflicts.length - informational), resolved,
                  (informational == 0 ? " " : "\nInformational Conflicts : " + informational));
            extraInfoLabel.setText(message);
         }
      }

   }

   @SuppressWarnings("rawtypes")
   @Override
   public Object getAdapter(Class adapter) {
      if (IActionable.class.equals(adapter)) {
         return new MergeViewerActionable();
      }
      return null;
   }

   private Action getCompleteCommitAction() {
      if (completeCommitAction == null) {
         completeCommitAction = new CompleteCommitAction();
      }
      return completeCommitAction;
   }

   private Branch getMergeBranch() {
      Conflict[] conflicts = getConflicts();
      return conflicts.length > 0 ? conflicts[0].getMergeBranch() : null;
   }

   private boolean hasMergeBranchBeenCommitted() {
      final Branch mergeBranch = getMergeBranch();
      return mergeBranch != null && !mergeBranch.isEditable();
   }

   private void checkForCompleteCommit() {
      boolean isVisible = !hasMergeBranchBeenCommitted() && areAllConflictsResolved();
      isVisible &= sourceBranch != null && sourceBranch.getBranchState().isRebaselineInProgress();
      setCompleteCommitItemVisible(isVisible);
   }

   private void setCompleteCommitItemVisible(boolean isVisible) {
      IToolBarManager manager = getToolBarManager();
      boolean wasFound = manager.find(COMPLETE_COMMIT_ACTION_ID) != null;
      if (isVisible) {
         if (!wasFound) {
            manager.insertBefore(REFRESH_ACTION_ID, getCompleteCommitAction());
         }
      } else if (wasFound) {
         manager.remove(COMPLETE_COMMIT_ACTION_ID);
      }
      manager.update(true);
   }

   private final class MergeViewerActionable implements IActionable {
      @Override
      public String getActionDescription() {
         StringBuilder sb = new StringBuilder();
         if (sourceBranch != null) {
            sb.append("\nSource Branch: ");
            sb.append(sourceBranch);
         }
         if (destBranch != null) {
            sb.append("\nDestination Branch: ");
            sb.append(destBranch);
         }
         if (tranId != null) {
            sb.append("\nTransactionId: ");
            sb.append(tranId);
         }
         if (commitTrans != null) {
            sb.append("\nCommit TransactionId: ");
            sb.append(commitTrans);
         }
         return sb.toString();
      }
   }

   private final class CompleteCommitAction extends Action {
      public CompleteCommitAction() {
         super();
         setImageDescriptor(FrameworkImage.BRANCH_COMMIT.createImageDescriptor());
         setToolTipText("Commit changes into destination branch");
         setId(COMPLETE_COMMIT_ACTION_ID);
      }

      @Override
      public void run() {
         if (sourceBranch.getBranchState().isRebaselineInProgress()) {
            ConflictManagerExternal conflictManager = new ConflictManagerExternal(destBranch, sourceBranch);
            BranchManager.completeUpdateBranch(conflictManager, true, false);
         }
      }
   }

   private final class OpenAssociatedArtifactAction extends Action {

      public OpenAssociatedArtifactAction() {
         super();
         setToolTipText("Open Associated Artifact");
         setEnabled(false);
      }

      @Override
      public void run() {
         Conflict[] storedConflicts = getConflicts();
         try {
            Branch sourceBranch = storedConflicts[0].getSourceBranch();
            Artifact branchAssociatedArtifact = BranchManager.getAssociatedArtifact(sourceBranch);
            if (branchAssociatedArtifact instanceof IATSArtifact) {
               OseeCm.getInstance().openArtifact(branchAssociatedArtifact, OseeCmEditor.CmPcrEditor);
            } else if (!branchAssociatedArtifact.equals(UserManager.getUser(SystemUser.OseeSystem))) {
               RendererManager.open(branchAssociatedArtifact, PresentationType.SPECIALIZED_EDIT);
            } else {
               AWorkbench.popup("ERROR", "Unknown branch association");
            }
         } catch (Exception ex) {
            OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
         }
      }
   }

   private final class ShowSourceBranchChangeReportAction extends Action {

      public ShowSourceBranchChangeReportAction() {
         super();
         //         setImageDescriptor(SkynetGuiPlugin.getInstance().getImageDescriptor("branch_change_source.gif"));
         setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.BRANCH_CHANGE_SOURCE));
         setToolTipText("Show Source Branch Change Report");
      }

      @Override
      public void run() {
         Conflict[] conflicts = getConflicts();
         if (conflicts.length > 0) {
            Conflict firstConflict = conflicts[0];
            Branch sourceBranch = firstConflict.getSourceBranch();
            if (sourceBranch != null) {
               try {
                  ChangeUiUtil.open(sourceBranch);
               } catch (Exception ex) {
                  OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
               }
            } else {
               try {
                  ChangeUiUtil.open(firstConflict.getCommitTransactionId());
               } catch (Exception ex) {
                  OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
               }
            }
         }
      }
   }

   private final class ShowDestinationBranchChangeReportAction extends Action {

      public ShowDestinationBranchChangeReportAction() {
         super();
         setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.BRANCH_CHANGE_DEST));
         setToolTipText("Show Destination Branch Change Report");
      }

      @Override
      public void run() {
         Conflict[] conflicts = getConflicts();
         if (conflicts.length > 0) {
            try {
               ChangeUiUtil.open(conflicts[0].getDestBranch());
            } catch (Exception ex) {
               OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
            }
         }
      }
   }

   private final class RefreshAction extends Action {

      public RefreshAction() {
         super();
         setImageDescriptor(ImageManager.getImageDescriptor(PluginUiImage.REFRESH));
         setToolTipText("Refresh");
         setId(REFRESH_ACTION_ID);
      }

      @Override
      public void run() {
         setInputData(sourceBranch, destBranch, tranId, mergeView, commitTrans, true);
      }
   }

   private final class ApplyPriorMergeResultsAction extends Action {
      public ApplyPriorMergeResultsAction() {
         super();
         setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.OUTGOING_MERGED));
         setToolTipText("Apply Merge Results From Prior Merge");
      }

      @Override
      public void run() {
         Conflict[] conflicts = getConflicts();
         if (conflicts.length != 0) {
            if (conflicts[0].getSourceBranch() != null) {
               ArrayList<String> selections = new ArrayList<String>();
               ArrayList<Integer> branchIds = new ArrayList<Integer>();
               try {
                  Collection<Integer> destBranches =
                     ConflictManagerInternal.getDestinationBranchesMerged(sourceBranch.getId());
                  for (Integer integer : destBranches) {
                     if (integer.intValue() != destBranch.getId()) {
                        selections.add(BranchManager.getBranch(integer).getName());
                        branchIds.add(integer);
                     }
                  }
                  if (selections.size() > 0) {
                     ListSelectionDialogNoSave dialog =
                        new ListSelectionDialogNoSave(selections.toArray(), Displays.getActiveShell().getShell(),
                           "Apply Prior Merge Resolution", null,
                           "Select the destination branch that the previous commit was appplied to", 2, new String[] {
                              "Apply",
                              "Cancel"}, 1);
                     if (dialog.open() == 0) {
                        System.out.print("Applying the merge found for Branch " + branchIds.toArray()[dialog.getSelection()]);
                        applyPreviousMerge(branchIds.get(dialog.getSelection()));
                     }
                  }
                  if (selections.isEmpty()) {
                     new MessageDialog(Displays.getActiveShell().getShell(), "Apply Prior Merge Resolution", null,
                        "This Source Branch has had No Prior Merges", 2, new String[] {"OK"}, 1).open();
                  }
               } catch (OseeCoreException ex) {
                  OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
               }
            }
         }
      }
   }
}

Back to the top