Skip to main content
summaryrefslogtreecommitdiffstats
blob: 03de0e352d3a1a2b3c0c53c079516488c0d915ac (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
/*******************************************************************************
 * 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.ote.ui.define.jobs;

import java.util.Arrays;
import java.util.HashSet;
import java.util.logging.Level;
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.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.osee.ote.define.artifacts.ArtifactTestRunOperator;
import org.eclipse.osee.ote.ui.define.OteDefineImage;
import org.eclipse.osee.ote.ui.define.OteUiDefinePlugin;
import org.eclipse.osee.ote.ui.define.dialogs.CommitDialog;
import org.eclipse.osee.ote.ui.define.dialogs.OverrideInvalidScriptRevisions;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.progress.UIJob;

/**
 * @author Roberto E. Escobar
 */
class CommitJobDialog extends UIJob {
   private static final Image CHILD_BRANCH_IMAGE = ImageManager.getImage(OteDefineImage.CHILD_BRANCH);

   private static String JOB_NAME = "Commit Test Run";
   private String message;
   private Object[] items;

   private final Artifact[] allItems;
   private final Artifact[] preSelected;
   private final Artifact[] unselectable;
   private final boolean isOverrideAllowed;

   public CommitJobDialog(Artifact[] allitems, Artifact[] preSelected, boolean isOverrideAllowed) {
      this(allitems, preSelected, null, isOverrideAllowed);
   }

   public CommitJobDialog(Artifact[] allitems, Artifact[] preSelected, Artifact[] unselectable, boolean isOverrideAllowed) {
      super(JOB_NAME);
      this.allItems = allitems;
      this.preSelected = preSelected;
      this.unselectable = unselectable;
      setUser(false);
      setPriority(Job.LONG);
      if (unselectable == null) {
         unselectable = new Artifact[0];
      }
      this.isOverrideAllowed = isOverrideAllowed;
      this.message = null;
      this.items = null;
   }

   public String getMessage() {
      return message;
   }

   public Object[] getSelected() {
      return items;
   }

   @Override
   public IStatus runInUIThread(IProgressMonitor monitor) {
      IStatus toReturn = Status.CANCEL_STATUS;
      monitor.setTaskName(getName());
      Shell shell = AWorkbench.getActiveShell();
      CommitDialog dialog = new CommitDialog(shell, CommitColumnEnum.toStringArray(), new TestRunTableLabelProvider());
      dialog.setBlockOnOpen(true);
      dialog.setInput(allItems);
      dialog.setUnSelectable(unselectable);
      dialog.setSelected(preSelected);
      if (isOverrideAllowed != false) {
         dialog.setOverrideHandler(new OverrideInvalidScriptRevisions());
      }
      int result = dialog.open();
      if (result == Window.OK) {
         message = dialog.getComments();
         items = dialog.getSelectedResources();
         toReturn = Status.OK_STATUS;
      }
      return toReturn;
   }

   private enum CommitColumnEnum {

      Branch,
      Name,
      Id,
      Outfile;

      public static String[] toStringArray() {

         CommitColumnEnum[] cols = CommitColumnEnum.values();
         String[] toReturn = new String[cols.length];
         for (int index = 0; index < cols.length; index++) {
            toReturn[index] = cols[index].name();
         }
         return toReturn;
      }
   }

   private final class TestRunTableLabelProvider extends BaseLabelProvider implements ITableLabelProvider {
      private final HashSet<Object> unselectableItems = new HashSet<>();
      private final int DUMMY_COLUMNS = 1;

      public TestRunTableLabelProvider() {
         if (unselectable != null) {
            this.unselectableItems.addAll(Arrays.asList(unselectable));
         }
      }

      @Override
      public Image getColumnImage(Object element, int columnIndex) {
         Image toReturn = null;
         if (columnIndex >= DUMMY_COLUMNS) {
            CommitColumnEnum column = CommitColumnEnum.values()[columnIndex - DUMMY_COLUMNS];
            switch (column) {
               case Branch:
                  toReturn = CHILD_BRANCH_IMAGE;
                  break;
               default:
                  break;
            }
         }
         return toReturn;
      }

      @Override
      public String getColumnText(Object element, int columnIndex) {
         String toReturn = "";
         if (columnIndex >= DUMMY_COLUMNS) {
            if (element instanceof Artifact) {
               Artifact artifact = (Artifact) element;
               if (artifact != null && artifact.isDeleted() != true) {
                  CommitColumnEnum column = CommitColumnEnum.values()[columnIndex - DUMMY_COLUMNS];
                  switch (column) {
                     case Branch:
                        toReturn = artifact.getBranch().getName();
                        break;
                     case Id:
                        try {
                           toReturn = new ArtifactTestRunOperator(artifact).getChecksum();
                        } catch (Exception ex) {
                           OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, "Error getting Checksum", ex);
                        }
                        break;
                     case Name:
                        toReturn = artifact.getName();
                        break;
                     case Outfile:
                        try {
                           toReturn = new ArtifactTestRunOperator(artifact).getOutfileAttribute().getDisplayableString();
                        } catch (Exception ex) {
                           OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, "Error getting Outfile", ex);
                        }
                        break;
                     default:
                        break;
                  }
               }
            }
         }
         return toReturn;
      }
   }
}

Back to the top