Created CyclingCellEditor for BooleanEditingSupport
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / tables / mi / CyclingCellEditor.java
1 package net.mograsim.plugin.tables.mi;
2
3 import org.eclipse.jface.viewers.CellEditor;
4 import org.eclipse.swt.widgets.Composite;
5 import org.eclipse.swt.widgets.Control;
6
7 public class CyclingCellEditor extends CellEditor
8 {
9         private final int size;
10         private int index = -1;
11
12         public CyclingCellEditor(int size)
13         {
14                 super();
15                 this.size = size;
16         }
17
18         public CyclingCellEditor(Composite parent, int size)
19         {
20                 super(parent);
21                 this.size = size;
22         }
23
24         public CyclingCellEditor(Composite parent, int size, int style)
25         {
26                 super(parent, style);
27                 this.size = size;
28         }
29
30         @Override
31         protected Control createControl(Composite parent)
32         {
33                 // Nothing to return
34                 return null;
35         }
36
37         @Override
38         protected Object doGetValue()
39         {
40                 return index;
41         }
42
43         @Override
44         protected void doSetFocus()
45         {
46                 // Nothing to focus
47         }
48
49         @Override
50         protected void doSetValue(Object index)
51         {
52                 this.index = (Integer) index;
53         }
54
55         @Override
56         public void activate()
57         {
58                 index = (index + 1) % size;
59                 fireApplyEditorValue();
60         }
61 }