KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > properties > IntCellEditor


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 03.11.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

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
17 public class IntCellEditor
18 extends CellEditor
19 {
20   protected Text text;
21   
22   /**
23    * @param parent
24    */

25   public IntCellEditor(Composite parent) {
26     super(parent);
27   }
28
29   /**
30    * @param parent
31    * @param style
32    */

33   public IntCellEditor(Composite parent, int style) {
34     super(parent, style);
35   }
36
37   /* (non-Javadoc)
38    * @see org.eclipse.jface.viewers.CellEditor#createControl(org.eclipse.swt.widgets.Composite)
39    */

40   protected Control createControl(Composite parent) {
41     text = new Text(parent, getStyle());
42     return text;
43   }
44
45   /* (non-Javadoc)
46    * @see org.eclipse.jface.viewers.CellEditor#doGetValue()
47    */

48   protected Object JavaDoc doGetValue()
49   {
50     String JavaDoc stringVal = text.getText();
51     Integer JavaDoc i = new Integer JavaDoc(stringVal);
52     return i;
53   }
54
55   /* (non-Javadoc)
56    * @see org.eclipse.jface.viewers.CellEditor#doSetFocus()
57    */

58   protected void doSetFocus()
59   {
60     if (text != null) {
61         text.selectAll();
62         text.setFocus();
63     }
64   }
65
66   /* (non-Javadoc)
67    * @see org.eclipse.jface.viewers.CellEditor#doSetValue(java.lang.Object)
68    */

69   protected void doSetValue(Object JavaDoc value)
70   {
71     Assert.isTrue(text != null && (value instanceof Integer JavaDoc));
72     Integer JavaDoc val = (Integer JavaDoc) value;
73     String JavaDoc stringVal = Integer.toString(val.intValue());
74     text.setText(stringVal);
75   }
76
77 }
78
Popular Tags