KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > parts > ModifiedTextCellEditor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc object) {
26         // Workaround for 32926
27
if (object==null) object = ""; //$NON-NLS-1$
28
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                 // do whatever it is you want to do on commit
36
handleEnter();
37                 // this will prevent the return from
38
// traversing to the button
39
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