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

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.nebula.widgets.xviewer.XViewerCells;
import org.eclipse.nebula.widgets.xviewer.XViewerLabelProvider;
import org.eclipse.nebula.widgets.xviewer.core.model.XViewerColumn;
import org.eclipse.osee.framework.skynet.core.change.ArtifactChange;
import org.eclipse.osee.framework.skynet.core.change.Change;
import org.eclipse.osee.framework.skynet.core.change.RelationChange;
import org.eclipse.osee.framework.ui.skynet.ArtifactImageManager;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.skynet.widgets.xHistory.column.HistoryTransactionDateColumn;
import org.eclipse.osee.framework.ui.skynet.widgets.xHistory.column.HistoryTransactionIdColumn;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

/**
 * @author Jeff C. Phillips
 */
public class XHistoryLabelProvider extends XViewerLabelProvider {

   private final HistoryXViewer historyXViewer;
   private static Color lightGreyColor;
   private final Map<XViewerColumn, Long> colToTime = new HashMap<XViewerColumn, Long>();
   private final Map<Object, Image> objectToImage = new HashMap<Object, Image>(500);
   private static Image transactionImage = null;

   public XHistoryLabelProvider(HistoryXViewer historyXViewer) {
      super(historyXViewer);
      this.historyXViewer = historyXViewer;
   }

   @Override
   public String getColumnText(Object element, XViewerColumn cCol, int columnIndex) {
      String toReturn = "";
      try {
         if (element instanceof Change) {
            Change data = (Change) element;
            if (cCol.equals(HistoryXViewerFactory.gamma)) {
               toReturn = String.valueOf(data.getGamma());
            } else if (cCol.equals(HistoryXViewerFactory.itemType)) {
               if (data instanceof ArtifactChange && data.getChangeArtifact() == null) {
                  toReturn = "Artifact Does Exist In This Transaction";
               } else {
                  toReturn = data instanceof RelationChange ? data.getName() : data.getItemTypeName();
               }
            } else if (cCol.equals(HistoryXViewerFactory.itemChange)) {
               toReturn = data.getItemKind();
            } else if (cCol.equals(HistoryXViewerFactory.modType)) {
               toReturn = data.getModificationType().getDisplayName();
            } else if (cCol.equals(HistoryXViewerFactory.itemId)) {
               toReturn = String.valueOf(data.getItemId());
            } else if (cCol.equals(HistoryXViewerFactory.was)) {
               toReturn = data.getWasValue();
            } else if (cCol.equals(HistoryXViewerFactory.is)) {
               toReturn = data.getIsValue();
            } else {
               toReturn = "unhandled column";
            }
         }
      } catch (Exception ex) {
         toReturn = XViewerCells.getCellExceptionString(ex);
      }
      return toReturn;
   }

   /**
    * Provides the XViewerSorter the actual Date object to sort instead of having to convert the text back to Date (and
    * loose the precision)
    */
   @Override
   public Object getBackingData(Object element, XViewerColumn xCol, int columnIndex) throws Exception {
      if (!(element instanceof Change)) {
         return "";
      }
      Change data = (Change) element;
      if (xCol.getId().equals(HistoryTransactionDateColumn.ID)) {
         HistoryTransactionDateColumn column =
            ((HistoryXViewerFactory) ((HistoryXViewer) xCol.getXViewer()).getXViewerFactory()).getHistoryTransactionDateColumn();
         Date date = column.getTransactionDate(data.getTxDelta().getEndTx().getId());

         if (date == null) {
            column.populateCachedValues(Collections.singleton(element), column.getPreComputedValueMap());
            date = column.getTransactionDate(data.getTxDelta().getEndTx().getId());
         }

         return date;
      }
      return super.getBackingData(element, xCol, columnIndex);
   }

   @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 HistoryXViewer getTreeViewer() {
      return historyXViewer;
   }

   @Override
   public Image getColumnImage(Object element, XViewerColumn xCol, int columnIndex) {
      Image result = null;
      try {
         if (element instanceof Change) {
            if (xCol.getId().equals(HistoryTransactionIdColumn.ID)) {
               if (transactionImage == null) {
                  transactionImage = ImageManager.getImage(FrameworkImage.DB_ICON_BLUE);
               }
               result = transactionImage;
            } else if (xCol.equals(HistoryXViewerFactory.itemType)) {
               result = objectToImage.get(element);
               objectToImage.put(element, result);
            }
         }
      } catch (Exception ex) {
         // do nothing
      }
      return result;
   }

   @Override
   public Color getBackground(Object element, int columnIndex) {
      if (historyXViewer.isSortByTransaction()) {
         Change change = (Change) element;
         long transactionId = change.getTxDelta().getEndTx().getId();
         if (historyXViewer.getXHistoryViewer().isShaded(transactionId)) {
            return getLightGreyColor();
         }
      }
      return super.getBackground(element, columnIndex);
   }

   private Color getLightGreyColor() {
      if (lightGreyColor == null) {
         lightGreyColor = Displays.getColor(234, 234, 234);
      }
      return lightGreyColor;
   }

   public void calculateImages(Collection<Change> changes) {
      for (Change change : changes) {
         Image result = ArtifactImageManager.getChangeTypeImage(change);
         objectToImage.put(change, result);
      }
   }

}

Back to the top