]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ViewerCellReference.java
Added Chart Preferences action to time series chart editor context menu
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / ViewerCellReference.java
1 package org.simantics.browsing.ui.swt;
2
3 import org.eclipse.jface.viewers.ViewerCell;
4 import org.simantics.browsing.ui.common.internal.UIElementReference;
5
6 /**
7  * "Reference" to a viewer cell.
8  * 
9  * ViewerCell is an object, which is not immutable, and has a very short lifespan. Hence we store its element and columnIndex.
10  * 
11  * 
12  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
13  *
14  */
15 public class ViewerCellReference implements UIElementReference{
16         
17         private final Object element;
18         private final int column;
19         
20         public static ViewerCellReference create(ViewerCell cell) {
21                 return new ViewerCellReference(cell);
22         }
23         
24         private ViewerCellReference(ViewerCell cell) {
25                 this.element = cell.getElement();
26                 this.column = cell.getColumnIndex();
27         }
28         
29         @Override
30         public boolean hasReference() {
31                 return element != null;
32         }
33         
34         @Override
35         public boolean isDisposed() {
36                 if (element == null)
37                         return true;
38                 return false;
39         }
40         
41         public Object getElement() {
42                 return element;
43         }
44         
45         public int getColumn() {
46                 return column;
47         }
48         
49         @Override
50         public int hashCode() {
51                 return element.hashCode() + column;
52                 
53         }
54         
55         @Override
56         public boolean equals(Object obj) {
57                 if (obj == null)
58                         return false;
59                 if (obj.getClass() != getClass())
60                         return false;
61                 ViewerCellReference other = (ViewerCellReference)obj;
62                 if (column != other.column)
63                         return false;
64                 return element.equals(other.element);
65         }
66 }