Skip to main content
summaryrefslogtreecommitdiffstats
blob: dc81a3b3d4b1b74def15555e4708f491ab00c439 (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
/*******************************************************************************
 * 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.ats.util.widgets.commit;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.nebula.widgets.xviewer.XViewer;
import org.eclipse.osee.ats.api.commit.ICommitConfigArtifact;
import org.eclipse.osee.ats.core.client.branch.AtsBranchManagerCore;
import org.eclipse.osee.ats.core.client.branch.CommitStatus;
import org.eclipse.osee.ats.internal.Activator;
import org.eclipse.osee.ats.util.AtsBranchManager;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.util.RebaselineInProgressHandler;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TreeItem;

/**
 * @author Donald G. Dunne
 */
public class CommitXManager extends XViewer {

   private final XCommitManager xCommitManager;

   public CommitXManager(Composite parent, int style, XCommitManager xRoleViewer) {
      super(parent, style, new CommitXManagerFactory());
      this.xCommitManager = xRoleViewer;
   }

   @Override
   public void updateMenuActionsForTable() {
      MenuManager mm = getMenuManager();

      mm.insertBefore(MENU_GROUP_PRE, new Separator());
   }

   /**
    * Release resources
    */
   @Override
   public void dispose() {
      getLabelProvider().dispose();
   }

   public List<Object> getSelectedArtifacts() {
      List<Object> arts = new ArrayList<Object>();
      TreeItem items[] = getTree().getSelection();
      if (items.length > 0) {
         for (TreeItem item : items) {
            arts.add(item.getData());
         }
      }
      return arts;
   }

   /**
    * @return the xUserRoleViewer
    */
   public XCommitManager getXCommitViewer() {
      return xCommitManager;
   }

   @Override
   public void handleDoubleClick() {
      try {
         Object firstSelectedArt = getSelectedArtifacts().iterator().next();
         Branch branch = null;
         String displayName = "";
         ICommitConfigArtifact configArt = null;
         if (firstSelectedArt instanceof ICommitConfigArtifact) {
            configArt = (ICommitConfigArtifact) firstSelectedArt;
            String baslineBranchGuid = configArt.getBaslineBranchGuid();
            if (Strings.isValid(baslineBranchGuid)) {
               branch = BranchManager.getBranchByGuid(baslineBranchGuid);
            }
            displayName = configArt.toString();
         } else if (firstSelectedArt instanceof TransactionRecord) {
            TransactionRecord txRecord = (TransactionRecord) firstSelectedArt;
            branch = txRecord.getBranch();
            displayName = txRecord.toString();
         } else {
            throw new OseeArgumentException("Unhandled element type [%s]", firstSelectedArt.getClass().toString());
         }

         CommitStatus commitStatus =
            AtsBranchManagerCore.getCommitStatus(xCommitManager.getTeamArt(), branch, configArt);
         if (commitStatus == CommitStatus.Rebaseline_In_Progress) {
            RebaselineInProgressHandler.handleRebaselineInProgress(xCommitManager.getTeamArt().getWorkingBranch());
         } else if (commitStatus == CommitStatus.Working_Branch_Not_Created) {
            AWorkbench.popup(commitStatus.getDisplayName(), "Need to create a working branch");
         } else if (commitStatus == CommitStatus.No_Commit_Needed) {
            AWorkbench.popup(commitStatus.getDisplayName(),
               "Destination Branch creation date is after commit to Parent Destination Branch; No Action Needed");
         } else if (commitStatus == CommitStatus.Branch_Not_Configured) {
            AWorkbench.popup(commitStatus.getDisplayName(),
               "Talk to project lead to configure branch for version [" + displayName + "]");
         } else if (commitStatus == CommitStatus.Branch_Commit_Disabled) {
            AWorkbench.popup(commitStatus.getDisplayName(),
               "Talk to project lead as to why commit disabled for version [" + displayName + "]");
         } else if (commitStatus == CommitStatus.Commit_Needed || commitStatus == CommitStatus.Merge_In_Progress) {
            IOperation operation =
               AtsBranchManager.commitWorkingBranch(xCommitManager.getTeamArt(), true, false, branch,
                  AtsBranchManagerCore.isBranchesAllCommittedExcept(xCommitManager.getTeamArt(), branch));
            Operations.executeAsJob(operation, true);
         } else if (commitStatus == CommitStatus.Committed) {
            AtsBranchManager.showChangeReportForBranch(xCommitManager.getTeamArt(), branch);
         } else if (commitStatus == CommitStatus.Committed_With_Merge) {
            handleCommittedWithMerge(branch);
         }
      } catch (OseeCoreException ex) {
         OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
      }
   }

   private void handleCommittedWithMerge(Branch branch) throws OseeCoreException {
      MessageDialog dialog =
         new MessageDialog(Displays.getActiveShell(), "Select Report", null,
            "Both Change Report and Merge Manager exist.\n\nSelect to open.", MessageDialog.QUESTION, new String[] {
               "Show Change Report",
               "Show Merge Manager",
               "Cancel"}, 0);
      int result = dialog.open();
      if (result == 2) {
         return;
      }
      // change report
      if (result == 0) {
         AtsBranchManager.showChangeReportForBranch(xCommitManager.getTeamArt(), branch);
      }
      // merge manager
      else {
         AtsBranchManager.showMergeManager(xCommitManager.getTeamArt(), branch);
      }
   }
}

Back to the top