Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TextAndDialogCellEditor(events in a JFace Dialog problem)
TextAndDialogCellEditor [message #946456] Tue, 16 October 2012 08:05
Joaquin Morcate is currently offline Joaquin MorcateFriend
Messages: 52
Registered: March 2010
Hi all,

I'm trying to use the following editor that combines a DialogCellEditor with a text editor:
 * Copyright (c) 2006, 2009 Eric Rizzo and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * Contributors:
 *     Eric Rizzo - initial implementation
package org.eclipse.jface.snippets.viewers;
import .....

 * A CellEditor that is a blending of DialogCellEditor and TextCellEditor. The user can either type
 * directly into the Text or use the button to open a Dialog for editing the cell's value.
public class TextAndDialogCellEditor extends DialogCellEditor {

	private Text textField;
	private String dialogMessage;
	private String dialogTitle;

	public TextAndDialogCellEditor(Composite parent) {

	public void setDialogMessage(String dialogMessage) {
		this.dialogMessage = dialogMessage;

	public void setDialogTitle(String dialogTitle) {
		this.dialogTitle = dialogTitle;

	protected Control createContents(Composite cell) {
		textField = new Text(cell, SWT.NONE);
		textField.addFocusListener(new FocusAdapter() {
				public void focusLost(FocusEvent event) {

		textField.addKeyListener(new KeyAdapter() {
				public void keyPressed(KeyEvent event) {

		return textField;

	protected void keyReleaseOccured(KeyEvent keyEvent) {
		if (keyEvent.keyCode == SWT.CR || keyEvent.keyCode == SWT.KEYPAD_CR) { // Enter key

	protected void setValueToModel() {
	 	String newValue = textField.getText();
        boolean newValidState = isCorrect(newValue);
        if (newValidState) {
        } else {
            // try to insert the current value into the error message.
            setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { newValue.toString() }));

	protected void updateContents(Object value) {
		if (textField == null) {

        String text = "";
        if (value != null) {
			text = value.toString();

	protected void doSetFocus() {
		// Overridden to set focus to the Text widget instead of the Button.

	protected Object openDialogBox(Control cellEditorWindow) {
		InputDialog dialog = new InputDialog(cellEditorWindow.getShell(), dialogTitle, dialogMessage, getDialogInitialValue(), null);
		if ( == Window.OK) {
			return dialog.getValue();
		} else {
			return null;

	protected String getDialogInitialValue() {
		Object value = getValue();
		if (value == null) {
			return null;
		} else {
			return value.toString();

I have the following problem. If I modify the value using the text field the editor works fine. When I press CR the editor is deactivated and my model is updated. If I open the dialog to modify the value it works also fine. But after that if I activate the editor again and I press CR on the text field, it doesn't work any more. Actually the event never arrives to keyReleaseOccured. All the key are processed properly, so I can modify the text in the Text widget, I can even press ESCAPE to cancel the application but not CR. I looks like if the event is consumed somewhere before, maybe in the dialog that disappeared. I'm lost. I don't understand how the dialog register its listeners. The CR will fire the action for the default value, but where is that association made? Finally, any idea about it?

Thank you.
Previous Topic:CheckboxTableViewer looses Checked State after Filter
Next Topic:FormText inside ScrolledFormText
Goto Forum:

Current Time: Mon Apr 23 21:32:47 GMT 2018

Powered by FUDForum. Page generated in 0.01836 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software