1 11 package org.eclipse.pde.internal.ui.parts; 12 13 import org.eclipse.jface.viewers.TextCellEditor; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.widgets.*; 16 17 public class ModifiedTextCellEditor extends TextCellEditor { 18 private Listener traverseListener; 19 20 public ModifiedTextCellEditor(Composite parent) { 21 super(parent); 22 setValueValid(true); 23 } 24 25 protected void doSetValue(Object object) { 26 if (object==null) object = ""; super.doSetValue(object); 29 } 30 public Control createControl(Composite parent) { 31 Text text = (Text) super.createControl(parent); 32 33 traverseListener = new Listener() { 34 public void handleEvent(Event e) { 35 handleEnter(); 37 e.doit = false; 40 } 41 }; 42 text.addListener(SWT.Traverse, traverseListener); 43 return text; 44 } 45 46 public void dispose() { 47 Control c = getControl(); 48 if (c!=null && !c.isDisposed() && traverseListener!=null) { 49 c.removeListener(SWT.Traverse, traverseListener); 50 } 51 super.dispose(); 52 } 53 54 public void forceCommit() { 55 if (isDirty()) 56 fireApplyEditorValue(); 57 } 58 59 private void handleEnter() { 60 fireApplyEditorValue(); 61 } 62 } 63 | Popular Tags |