1 11 package org.eclipse.jdt.internal.ui.refactoring.nls; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Control; 17 18 import org.eclipse.jface.viewers.CellEditor; 19 20 21 public class MultiStateCellEditor extends CellEditor { 22 23 private int fValue; 24 private final int fStateCount; 25 26 30 public MultiStateCellEditor(Composite parent, int stateCount, int initialValue) { 31 super(parent); 32 Assert.isTrue(stateCount > 1, "incorrect state count"); fStateCount= stateCount; 34 35 Assert.isTrue(initialValue >= 0 && initialValue < stateCount, "incorrect initial value"); fValue= initialValue; 37 38 setValueValid(true); 39 } 40 41 44 public void activate() { 45 fValue= getNextValue(fStateCount, fValue); 46 fireApplyEditorValue(); 47 } 48 49 public static int getNextValue(int stateCount, int currentValue){ 50 Assert.isTrue(stateCount > 1, "incorrect state count"); Assert.isTrue(currentValue >= 0 && currentValue < stateCount, "incorrect initial value"); return (currentValue + 1) % stateCount; 53 } 54 55 58 protected Control createControl(Composite parent) { 59 return null; 60 } 61 62 66 protected Object doGetValue() { 67 return new Integer (fValue); 68 } 69 70 73 protected void doSetFocus() { 74 } 76 77 82 protected void doSetValue(Object value) { 83 Assert.isTrue(value instanceof Integer , "value must be Integer"); fValue = ((Integer ) value).intValue(); 85 Assert.isTrue(fValue >= 0 && fValue < fStateCount, "invalid value"); } 87 } 88 | Popular Tags |