Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5f1c9a5fa98164155860460f0b881af3d8d37f93 (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
/*******************************************************************************
 * 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.defect;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.nebula.widgets.xviewer.IXViewerFactory;
import org.eclipse.nebula.widgets.xviewer.XPromptChange;
import org.eclipse.nebula.widgets.xviewer.XPromptChange.Option;
import org.eclipse.nebula.widgets.xviewer.XViewer;
import org.eclipse.nebula.widgets.xviewer.XViewerColumn;
import org.eclipse.nebula.widgets.xviewer.util.EnumStringSingleSelectionDialog;
import org.eclipse.osee.ats.internal.AtsPlugin;
import org.eclipse.osee.ats.util.widgets.defect.DefectItem.Disposition;
import org.eclipse.osee.ats.util.widgets.defect.DefectItem.InjectionActivity;
import org.eclipse.osee.ats.util.widgets.defect.DefectItem.Severity;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.ui.skynet.widgets.dialog.UserListDialog;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;

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

   private final XDefectViewer xDefectViewer;
   private Action editSeverityAction;
   private Action editDispositionAction;
   private Action editClosedAction;
   private Action editUserAction;
   private Action editCreatedDateAction;
   private Action editInjectionAction;
   private Action editDescriptionAction;
   private Action editLocationAction;
   private Action editResolutionAction;

   /**
    * @param parent
    * @param style
    */
   DefectXViewer(Composite parent, int style, XDefectViewer xDefectViewer) {
      this(parent, style, new DefectXViewerFactory(), xDefectViewer);
   }

   public DefectXViewer(Composite parent, int style, IXViewerFactory xViewerFactory, XDefectViewer xDefectViewer) {
      super(parent, style, xViewerFactory);
      this.xDefectViewer = xDefectViewer;
   }

   @Override
   protected void createSupportWidgets(Composite parent) {
      super.createSupportWidgets(parent);
      parent.addDisposeListener(new DisposeListener() {
         @Override
         public void widgetDisposed(DisposeEvent e) {
            ((DefectContentProvider) getContentProvider()).clear();
         }
      });
      createMenuActions();
   }

   public void createMenuActions() {
      setColumnMultiEditEnabled(true);
      MenuManager mm = getMenuManager();
      mm.createContextMenu(getControl());

      editSeverityAction = new Action("Edit Severity", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Severity_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editClosedAction = new Action("Edit Closed ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Closed_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editCreatedDateAction = new Action("Edit Created Date ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Created_Date_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editDescriptionAction = new Action("Edit Description ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Description_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editDispositionAction = new Action("Edit Disposition ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Disposition_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editInjectionAction = new Action("Edit Injection ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Injection_Activity_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editLocationAction = new Action("Edit Location ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Location_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editResolutionAction = new Action("Edit Resolution ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.Resolution_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };

      editUserAction = new Action("Edit User ", IAction.AS_PUSH_BUTTON) {
         @Override
         public void run() {
            boolean columnMultiEdit = false;
            // grab the data, prompt change
            try {
               promptChangeData(DefectXViewerFactory.User_Col, getSelectedDefectItems(), columnMultiEdit);
            } catch (OseeCoreException ex) {
               OseeLog.log(DefectXViewer.class, OseeLevel.SEVERE_POPUP, ex.toString());
            }
         }
      };
   }

   public void updateEditMenuActions() {
      MenuManager mm = getMenuManager();
      // EDIT MENU BLOCK
      mm.insertBefore(MENU_GROUP_PRE, editSeverityAction);
      editSeverityAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editClosedAction);
      editClosedAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editCreatedDateAction);
      editCreatedDateAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editDescriptionAction);
      editDescriptionAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editDispositionAction);
      editDispositionAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editInjectionAction);
      editInjectionAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editLocationAction);
      editLocationAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editResolutionAction);
      editResolutionAction.setEnabled(true);
      mm.insertBefore(MENU_GROUP_PRE, editUserAction);
      editUserAction.setEnabled(true);

   }

   @Override
   public void updateMenuActionsForTable() {
      MenuManager mm = getMenuManager();
      updateEditMenuActions();
      mm.insertBefore(MENU_GROUP_PRE, new Separator());
   }

   public Collection<DefectItem> getLoadedDefectItems() {
      return ((DefectContentProvider) getContentProvider()).getRootSet();
   }

   public void add(Collection<DefectItem> defectItems) {
      if ((DefectContentProvider) getContentProvider() != null) {
         ((DefectContentProvider) getContentProvider()).add(defectItems);
      }
   }

   public void set(Collection<? extends DefectItem> defectItems) {
      if ((DefectContentProvider) getContentProvider() != null) {
         ((DefectContentProvider) getContentProvider()).set(defectItems);
      }
   }

   public void clear() {
      if ((DefectContentProvider) getContentProvider() != null) {
         ((DefectContentProvider) getContentProvider()).clear();
      }
   }

   /**
    * Release resources
    */
   @Override
   public void dispose() {
      // Dispose of the table objects is done through separate dispose listener off tree
      // Tell the label provider to release its resources
      getLabelProvider().dispose();
   }

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

   @Override
   public void handleColumnMultiEdit(TreeColumn treeColumn, Collection<TreeItem> treeItems) {
      if (!xDefectViewer.isEditable()) {
         return;
      }
      ArrayList<DefectItem> defectItems = new ArrayList<DefectItem>();
      for (TreeItem item : treeItems) {
         defectItems.add((DefectItem) item.getData());
      }
      try {
         promptChangeData((XViewerColumn) treeColumn.getData(), defectItems, isColumnMultiEditEnabled());
      } catch (OseeCoreException ex) {
         OseeLog.log(AtsPlugin.class, OseeLevel.SEVERE_POPUP, ex);
      }
   }

   @Override
   public boolean handleLeftClickInIconArea(TreeColumn treeColumn, TreeItem treeItem) {
      XViewerColumn xCol = (XViewerColumn) treeColumn.getData();
      if (xCol.equals(DefectXViewerFactory.User_Col) || xCol.equals(DefectXViewerFactory.Injection_Activity_Col) || xCol.equals(DefectXViewerFactory.Closed_Col) || xCol.equals(DefectXViewerFactory.Severity_Col)) {
         return handleAltLeftClick(treeColumn, treeItem);
      }
      return false;
   }

   @Override
   public boolean handleAltLeftClick(TreeColumn treeColumn, TreeItem treeItem) {
      if (!xDefectViewer.isEditable()) {
         return false;
      }
      try {
         XViewerColumn xCol = (XViewerColumn) treeColumn.getData();
         DefectItem defectItem = (DefectItem) treeItem.getData();
         List<DefectItem> defectItems = new ArrayList<DefectItem>();
         defectItems.add(defectItem);
         if (xCol.equals(DefectXViewerFactory.Severity_Col) || xCol.equals(DefectXViewerFactory.Disposition_Col) || xCol.equals(DefectXViewerFactory.Created_Date_Col) || xCol.equals(DefectXViewerFactory.Closed_Col) || xCol.equals(DefectXViewerFactory.Description_Col) || xCol.equals(DefectXViewerFactory.Resolution_Col) || xCol.equals(DefectXViewerFactory.Location_Col) || xCol.equals(DefectXViewerFactory.User_Col) || xCol.equals(DefectXViewerFactory.Injection_Activity_Col)) {
            return promptChangeData(xCol, defectItems, false);
         }
      } catch (Exception ex) {
         OseeLog.log(AtsPlugin.class, OseeLevel.SEVERE_POPUP, ex);
      }
      return false;
   }

   private boolean setInjectionActivity(Collection<DefectItem> defectItems, InjectionActivity newInjectionActivity) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (!defectItem.getInjectionActivity().equals(newInjectionActivity)) {
            defectItem.setInjectionActivity(newInjectionActivity);
            // at least one in the list has been changed.
            if (!modified) {
               modified = true;
            }
         }
      }
      return modified;
   }

   private boolean setUser(Collection<DefectItem> defectItems, User user) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (!defectItem.getUser().equals(user)) {
            defectItem.setUser(user);
            // at least one in the list has been changed.
            if (!modified) {
               modified = true;
            }
         }
      }
      return modified;
   }

   private boolean setLocation(Collection<DefectItem> defectItems, String loc) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (!defectItem.getLocation().equals(loc)) {
            defectItem.setLocation(loc);
            if (!modified) {
               modified = true;
            }
         }
      }
      return modified;
   }

   private boolean setDescription(Collection<DefectItem> defectItems, String desc) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (!defectItem.toString().equals(desc)) {
            defectItem.setDescription(desc);
            if (!modified) {
               modified = true;
            }
         }

      }
      return modified;
   }

   private boolean setClosed(Collection<DefectItem> defectItems, boolean closed) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (defectItem.isClosed() != closed) {
            defectItem.setClosed(closed);
            if (!modified) {
               modified = true;
            }
         }
      }
      return modified;
   }

   private boolean setSeverity(Collection<DefectItem> defectItems, Severity severity) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (!defectItem.getSeverity().equals(severity)) {
            defectItem.setSeverity(severity);
            if (!modified) {
               modified = true;
            }
         }
      }
      return modified;
   }

   private boolean setDisposition(Collection<DefectItem> defectItems, Disposition disposition) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (!defectItem.getDisposition().equals(disposition)) {
            defectItem.setDisposition(disposition);
            if (!modified) {
               modified = true;
            }
         }
      }
      return modified;
   }

   private boolean setDate(Collection<DefectItem> defectItems, Date date) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         if (!defectItem.getDate().equals(date)) {
            defectItem.setDate(date);
            if (!modified) {
               modified = true;
            }
         }
      }
      return modified;
   }

   private boolean setResolution(Collection<DefectItem> defectItems, String resolution) {
      boolean modified = false;
      for (DefectItem defectItem : defectItems) {
         defectItem.setResolution(resolution);
         if (!modified) {
            modified = true;
         }
      }
      return modified;
   }

   public boolean promptChangeData(XViewerColumn xCol, Collection<DefectItem> defectItems, boolean columnMultiEdit) throws OseeCoreException {
      boolean modified = false;
      if (defectItems != null && !defectItems.isEmpty()) {
         DefectItem defectItem = (DefectItem) defectItems.toArray()[0];
         if (xCol.equals(DefectXViewerFactory.Severity_Col)) {
            EnumStringSingleSelectionDialog enumDialog =
               XPromptChange.promptChangeSingleSelectEnumeration(xCol.getName(), Severity.strValues(),
                  (columnMultiEdit ? null : defectItem.getSeverity().name()));
            if (enumDialog != null && enumDialog.getResult() != null) {
               modified = setSeverity(defectItems, Severity.valueOf((String) enumDialog.getResult()[0]));
            }
         } else if (xCol.equals(DefectXViewerFactory.Disposition_Col)) {
            EnumStringSingleSelectionDialog enumDialog =
               XPromptChange.promptChangeSingleSelectEnumeration(xCol.getName(), Disposition.strValues(),
                  (columnMultiEdit ? null : defectItem.getDisposition().name()));
            if (enumDialog != null && enumDialog.getResult() != null) {
               modified = setDisposition(defectItems, Disposition.valueOf((String) enumDialog.getResult()[0]));
            }
         } else if (xCol.equals(DefectXViewerFactory.Created_Date_Col)) {
            Date selDate =
               XPromptChange.promptChangeDate(xCol.getName(), (columnMultiEdit ? defectItem.getDate() : null));
            if (selDate != null) {
               modified = setDate(defectItems, selDate);
            }
         } else if (xCol.equals(DefectXViewerFactory.Closed_Col)) {
            Boolean closed =
               XPromptChange.promptChangeBoolean(xCol.getName(), xCol.getName(),
                  (columnMultiEdit ? false : defectItem.isClosed()));
            if (closed != null) {
               modified = setClosed(defectItems, closed);
            }
         } else if (xCol.equals(DefectXViewerFactory.Description_Col)) {
            String desc =
               XPromptChange.promptChangeString(xCol.getName(), (columnMultiEdit ? null : defectItem.getDescription()),
                  null, Option.MULTI_LINE);
            if (desc != null) {
               modified = setDescription(defectItems, desc);
            }
         } else if (xCol.equals(DefectXViewerFactory.Resolution_Col)) {
            String resolution =
               XPromptChange.promptChangeString(xCol.getName(), (columnMultiEdit ? null : defectItem.getResolution()),
                  null, Option.MULTI_LINE);
            if (resolution != null) {
               modified = setResolution(defectItems, resolution);
            }
         } else if (xCol.equals(DefectXViewerFactory.Location_Col)) {
            String loc =
               XPromptChange.promptChangeString(xCol.getName(), (columnMultiEdit ? null : defectItem.getLocation()),
                  null, Option.MULTI_LINE);
            if (loc != null) {
               modified = setLocation(defectItems, loc);
            }
         } else if (xCol.equals(DefectXViewerFactory.User_Col)) {
            UserListDialog ld = new UserListDialog(Displays.getActiveShell(), "Select New User");
            int result = ld.open();
            if (result == 0) {
               modified = setUser(defectItems, ld.getSelection());
            }
         } else if (xCol.equals(DefectXViewerFactory.Injection_Activity_Col)) {
            EnumStringSingleSelectionDialog enumDialog =
               XPromptChange.promptChangeSingleSelectEnumeration(xCol.getName(), InjectionActivity.strValues(),
                  (columnMultiEdit ? null : defectItem.getInjectionActivity().name()));
            if (enumDialog != null && enumDialog.getResult() != null) {
               modified =
                  setInjectionActivity(defectItems, InjectionActivity.valueOf((String) enumDialog.getResult()[0]));
            }
         }
         if (modified) {
            return executeTransaction(defectItems);
         }
      }
      return false;
   }

   public boolean executeTransaction(Collection<DefectItem> defectItems) throws OseeCoreException {
      SkynetTransaction transaction =
         new SkynetTransaction(xDefectViewer.getReviewArt().getArtifact().getBranch(), "Modify Review Defects");
      for (DefectItem defectItem : defectItems) {
         xDefectViewer.getReviewArt().getDefectManager().addOrUpdateDefectItem(defectItem, false, transaction);
         update(defectItem, null);
      }
      transaction.execute();
      xDefectViewer.notifyXModifiedListeners();
      return true;
   }
}

Back to the top