]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/ViewerRowReference.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 / ViewerRowReference.java
1 package org.simantics.browsing.ui.swt;
2
3 import org.eclipse.jface.viewers.ViewerCell;
4 import org.eclipse.jface.viewers.ViewerRow;
5 import org.simantics.browsing.ui.common.internal.UIElementReference;
6
7 public class ViewerRowReference implements UIElementReference{
8         
9         private final Object element;
10         
11         public static ViewerRowReference create(ViewerCell cell) {
12                 return new ViewerRowReference(cell.getViewerRow());
13         }
14         
15         public static ViewerRowReference create(ViewerRow row) {
16                 return new ViewerRowReference(row);
17         }
18         
19         public static ViewerRowReference create(Object element) {
20                 return new ViewerRowReference(element);
21         }
22         
23         private ViewerRowReference(ViewerRow row) {
24                 this.element = row.getElement();
25         }
26         
27         private ViewerRowReference(Object element) {
28                 this.element = element;
29         }
30         
31         @Override
32         public boolean hasReference() {
33                 return element != null;
34         }
35         
36         @Override
37         public boolean isDisposed() {
38                 if (element == null)
39                         return true;
40                 return false;
41         }
42         
43         public Object getElement() {
44                 return element;
45         }
46         
47         @Override
48         public int hashCode() {
49                 if (element != null)
50                         return element.hashCode();
51                 return 0;
52         }
53         
54         @Override
55         public boolean equals(Object obj) {
56                 if (obj == null)
57                         return false;
58                 if (obj.getClass() != getClass())
59                         return false;
60                 if (element == null)
61                         return false;
62                 ViewerRowReference other = (ViewerRowReference)obj;
63                 return element.equals(other.element);
64         }
65 }