1 8 package com.nightlabs.editor2d.properties; 9 10 import org.eclipse.jface.util.Assert; 11 import org.eclipse.jface.viewers.CellEditor; 12 import org.eclipse.swt.widgets.Composite; 13 import org.eclipse.swt.widgets.Control; 14 import org.eclipse.swt.widgets.Text; 15 16 public class DoubleCellEditor 17 extends CellEditor 18 { 19 protected Text text; 20 21 public DoubleCellEditor() { 22 super(); 23 } 24 25 public DoubleCellEditor(Composite parent) { 26 super(parent); 27 } 28 29 public DoubleCellEditor(Composite parent, int style) { 30 super(parent, style); 31 } 32 33 protected Control createControl(Composite parent) { 34 text = new Text(parent, getStyle()); 35 return text; 36 } 37 38 protected Object doGetValue() { 39 String stringVal = text.getText(); 40 Double d = new Double (stringVal); 41 return d; 42 } 43 44 protected void doSetFocus() { 45 if (text != null) { 46 text.selectAll(); 47 text.setFocus(); 48 } 49 } 50 51 protected void doSetValue(Object value) { 52 Assert.isTrue(text != null && (value instanceof Double )); 53 Double val = (Double ) value; 54 String stringVal = Double.toString(val.doubleValue()); 55 text.setText(stringVal); 56 } 57 58 } 59 | Popular Tags |