Skip to main content
summaryrefslogtreecommitdiffstats
blob: 80ae3b6117b893796839b851075adc7be5cec4e8 (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
/*******************************************************************************
 * 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.logging.Level;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.nebula.widgets.xviewer.XViewerColumn;
import org.eclipse.nebula.widgets.xviewer.XViewerLabelProvider;
import org.eclipse.osee.ats.api.commit.CommitStatus;
import org.eclipse.osee.ats.api.commit.ICommitConfigItem;
import org.eclipse.osee.ats.api.team.IAtsTeamDefinition;
import org.eclipse.osee.ats.api.version.IAtsVersion;
import org.eclipse.osee.ats.internal.Activator;
import org.eclipse.osee.ats.internal.AtsClientService;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.TransactionRecord;
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.DateUtil;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.graphics.Image;

/**
 * @author Donald G. Dunne
 */
public class XCommitLabelProvider extends XViewerLabelProvider {

   private final CommitXManager commitXManager;

   public XCommitLabelProvider(CommitXManager commitXManager) {
      super(commitXManager);
      this.commitXManager = commitXManager;
   }

   @Override
   public Image getColumnImage(Object element, XViewerColumn xCol, int columnIndex) throws OseeCoreException {
      BranchId branch = null;
      if (element instanceof ICommitConfigItem) {
         ICommitConfigItem configArt = (ICommitConfigItem) element;
         branch = AtsClientService.get().getBranchService().getBranch(configArt);
      } else if (element instanceof TransactionRecord) {
         TransactionRecord txRecord = (TransactionRecord) element;
         branch = txRecord.getBranch();
      } else {
         throw new OseeArgumentException("Unhandled element type [%s]", element.getClass().toString());
      }

      if (xCol.equals(CommitXManagerFactory.Action_Col)) {
         return ImageManager.getImage(FrameworkImage.ARROW_RIGHT_YELLOW);
      }
      if (branch == null) {
         return null;
      }
      if (xCol.equals(CommitXManagerFactory.Status_Col)) {
         try {
            CommitStatus commitStatus = AtsClientService.get().getBranchService().getCommitStatus(
               commitXManager.getXCommitViewer().getTeamArt(), branch);
            if (commitStatus == CommitStatus.Branch_Not_Configured || commitStatus == CommitStatus.Branch_Commit_Disabled ||
            //
            commitStatus == CommitStatus.Commit_Needed || commitStatus == CommitStatus.Working_Branch_Not_Created) {
               return ImageManager.getImage(FrameworkImage.DOT_RED);
            }

            if (commitStatus == CommitStatus.Merge_In_Progress) {
               return ImageManager.getImage(FrameworkImage.DOT_YELLOW);
            }

            if (commitStatus == CommitStatus.Committed || commitStatus == CommitStatus.Committed_With_Merge || commitStatus == CommitStatus.No_Commit_Needed) {
               return ImageManager.getImage(FrameworkImage.DOT_GREEN);
            }
            return null;
         } catch (Exception ex) {
            OseeLog.log(Activator.class, Level.SEVERE, ex);
         }
      } else if (xCol.equals(CommitXManagerFactory.Merge_Col)) {
         try {
            CommitStatus commitStatus = AtsClientService.get().getBranchService().getCommitStatus(
               commitXManager.getXCommitViewer().getTeamArt(), branch);
            if (commitStatus == CommitStatus.Merge_In_Progress || commitStatus == CommitStatus.Committed_With_Merge) {
               return ImageManager.getImage(FrameworkImage.OUTGOING_MERGED);
            }
            return null;
         } catch (Exception ex) {
            OseeLog.log(Activator.class, Level.SEVERE, ex);
         }
      }
      return null;
   }

   @Override
   public String getColumnText(Object element, XViewerColumn xCol, int columnIndex) throws OseeCoreException {
      Branch branch = null;
      if (element instanceof ICommitConfigItem) {
         ICommitConfigItem configArt = (ICommitConfigItem) element;
         if (!AtsClientService.get().getBranchService().isBranchValid(configArt)) {
            return String.format("Branch not configured for [%s]", element);
         } else {
            branch = BranchManager.getBranch(configArt.getBaselineBranchUuid());
         }
      } else if (element instanceof TransactionRecord) {
         TransactionRecord txRecord = (TransactionRecord) element;
         branch = txRecord.getFullBranch();
      } else {
         throw new OseeArgumentException("Unhandled element type [%s]", element.getClass().toString());
      }

      if (xCol.equals(CommitXManagerFactory.Status_Col)) {
         return AtsClientService.get().getBranchService().getCommitStatus(
            commitXManager.getXCommitViewer().getTeamArt(), branch).getDisplayName();
      } else if (xCol.equals(CommitXManagerFactory.Merge_Col)) {
         return "";
      } else if (xCol.equals(CommitXManagerFactory.Version_Col)) {
         return handleVersionColumn(element);
      } else if (xCol.equals(CommitXManagerFactory.Configuring_Object_Col)) {
         return handleArtifactTypeNameColumn(element);
      } else if (xCol.equals(CommitXManagerFactory.Commit_Date)) {
         return handleCommitDateColumn(branch);
      } else if (xCol.equals(CommitXManagerFactory.Commit_Comment)) {
         return handleCommitCommentColumn(branch);
      } else if (xCol.equals(CommitXManagerFactory.Dest_Branch_Col)) {
         return handleDestBranchColumn(element, branch);
      } else if (xCol.equals(CommitXManagerFactory.Dest_Branch_Create_Date_Col)) {
         return handleDestBranchCreationDateColumn(element, branch);
      } else if (xCol.equals(CommitXManagerFactory.Action_Col)) {
         return handleActionColumn(branch);
      }
      return "unhandled column";
   }

   private String handleVersionColumn(Object element) throws OseeCoreException {
      if (element instanceof ICommitConfigItem) {
         return ((ICommitConfigItem) element).getName();
      } else {
         return "";
      }
   }

   private String handleArtifactTypeNameColumn(Object element) {
      if (element instanceof ICommitConfigItem) {
         return ((ICommitConfigItem) element).getTypeName();
      } else {
         return "";
      }
   }

   private String handleCommitDateColumn(BranchId branch) throws OseeCoreException {
      TransactionRecord transactionRecord =
         (TransactionRecord) AtsClientService.get().getBranchService().getCommitTransactionRecord(
            commitXManager.getXCommitViewer().getTeamArt(), branch);
      if (transactionRecord != null) {
         new DateUtil();
         return DateUtil.getMMDDYYHHMM(transactionRecord.getTimeStamp());
      }
      return "Not Committed";
   }

   private String handleCommitCommentColumn(BranchId branch) throws OseeCoreException {
      TransactionRecord transactionRecord =
         (TransactionRecord) AtsClientService.get().getBranchService().getCommitTransactionRecord(
            commitXManager.getXCommitViewer().getTeamArt(), branch);
      if (transactionRecord != null) {
         return transactionRecord.getComment();
      }
      return "Not Committed";
   }

   private String handleDestBranchColumn(Object element, Branch branch) {
      if (element instanceof IAtsVersion) {
         return branch == null ? "Parent Branch Not Configured for Version [" + element + "]" : branch.getShortName();
      } else if (element instanceof IAtsTeamDefinition) {
         return branch == null ? "Parent Branch Not Configured for Team Definition [" + element + "]" : branch.getShortName();
      } else if (element instanceof TransactionRecord) {
         return branch.getShortName();
      }
      return "";
   }

   private String handleDestBranchCreationDateColumn(Object element, Branch branch) throws OseeCoreException {
      if (element instanceof IAtsVersion) {
         return branch == null ? "Parent Branch Not Configured for Version [" + element + "]" : DateUtil.getMMDDYYHHMM(
            branch.getBaseTransaction().getTimeStamp());
      } else if (element instanceof IAtsTeamDefinition) {
         return branch == null ? "Parent Branch Not Configured for Team Definition [" + element + "]" : DateUtil.getMMDDYYHHMM(
            branch.getBaseTransaction().getTimeStamp());
      } else if (element instanceof TransactionRecord) {
         return DateUtil.getMMDDYYHHMM(branch.getBaseTransaction().getTimeStamp());
      }
      return "";
   }

   private String handleActionColumn(BranchId branch) throws OseeCoreException {
      CommitStatus commitStatus = AtsClientService.get().getBranchService().getCommitStatus(
         commitXManager.getXCommitViewer().getTeamArt(), branch);
      if (commitStatus == CommitStatus.Rebaseline_In_Progress) {
         return "Finish Update";
      } else if (commitStatus == CommitStatus.Branch_Not_Configured) {
         return "Configure Branch";
      } else if (commitStatus == CommitStatus.Branch_Commit_Disabled) {
         return "Enable Branch Commit";
      } else if (commitStatus == CommitStatus.Commit_Needed) {
         return "Start Commit";
      } else if (commitStatus == CommitStatus.No_Commit_Needed) {
         return CommitStatus.No_Commit_Needed.getDisplayName();
      } else if (commitStatus == CommitStatus.Merge_In_Progress) {
         return "Merge Conflicts and Commit";
      } else if (commitStatus == CommitStatus.Committed) {
         return "Show Change Report";
      } else if (commitStatus == CommitStatus.Committed_With_Merge) {
         return "Show Change/Merge Report";
      } else if (commitStatus == CommitStatus.Working_Branch_Not_Created) {
         return "Working Branch Not Created";
      }
      return "Error: Need to handle this";
   }

   @Override
   public void dispose() {
      // do nothing
   }

   @Override
   public boolean isLabelProperty(Object element, String property) {
      return false;
   }

   @Override
   public void addListener(ILabelProviderListener listener) {
      // do nothing
   }

   @Override
   public void removeListener(ILabelProviderListener listener) {
      // do nothing
   }

   public CommitXManager getTreeViewer() {
      return commitXManager;
   }

}

Back to the top