Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [JFace] Text and Dialog button CellEditor?
[JFace] Text and Dialog button CellEditor? [message #332934] Fri, 14 November 2008 16:25 Go to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

There is DialogCellEditor and TextCellEditor, but what I need is a
combination of the two, a CellEditor that allows the user to type in
text and also has the ... button for opening a Dialog to select a value.
I've trying to write one by extending DialogCellEditor and adding a Text
field (lots of code copied from TextCellEditor) but I'm having annoying
difficulties getting focus handling to work properly (this is only the
latest issue in a painful progression of them).
Has anyone seen such a CellEditor that I could use rather than continue
to flounder writing my own?

Eric
Re: [JFace] Text and Dialog button CellEditor? [message #332935 is a reply to message #332934] Fri, 14 November 2008 16:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 11/14/2008 11:25 AM, Eric Rizzo wrote:
> There is DialogCellEditor and TextCellEditor, but what I need is a
> combination of the two, a CellEditor that allows the user to type in
> text and also has the ... button for opening a Dialog to select a value.
> I've trying to write one by extending DialogCellEditor and adding a Text
> field (lots of code copied from TextCellEditor) but I'm having annoying
> difficulties getting focus handling to work properly (this is only the
> latest issue in a painful progression of them).
> Has anyone seen such a CellEditor that I could use rather than continue
> to flounder writing my own?

I guess I'll (try to) describe the issue I'm facing in case someone has
an idea for getting past it.
The problem with combining a Text and a Button in the same CellEditor
seems to be related to how to handle focus-lost events. The Text needs
to have a focus-lost handler that calls CellEditor.focusLost() so that
the value from the Text is pushed to the model [focusLost() calls
fireApplyEditorValue()] - when someone activates the editor, types into
the Text and then clicks elsewhere, the value they typed is pushed to
the model.
However, this interferes when the CellEditor open-dialog button is
pushed, because that triggers focus-lost to the Text which in turn
triggers fireApplyEditorValue() - the problem is that this indirectly
causes the ColumnViewerEditor to remove its listener from the cell
editor [see code buried deep in ColumnViewerEditor.applyEditorValue()].
So when the dialog is closed with a new value chose, the
ColumnViewerEditor is no longer listening to that CellEditor and doesn't
get the update.

Any ideas how to get around this conundrum?

Eric
Re: [JFace] Text and Dialog button CellEditor? [message #332944 is a reply to message #332935] Sat, 15 November 2008 13:31 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Do you have code for me to play with?

Tom

Eric Rizzo schrieb:
> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>> There is DialogCellEditor and TextCellEditor, but what I need is a
>> combination of the two, a CellEditor that allows the user to type in
>> text and also has the ... button for opening a Dialog to select a value.
>> I've trying to write one by extending DialogCellEditor and adding a Text
>> field (lots of code copied from TextCellEditor) but I'm having annoying
>> difficulties getting focus handling to work properly (this is only the
>> latest issue in a painful progression of them).
>> Has anyone seen such a CellEditor that I could use rather than continue
>> to flounder writing my own?
>
> I guess I'll (try to) describe the issue I'm facing in case someone has
> an idea for getting past it.
> The problem with combining a Text and a Button in the same CellEditor
> seems to be related to how to handle focus-lost events. The Text needs
> to have a focus-lost handler that calls CellEditor.focusLost() so that
> the value from the Text is pushed to the model [focusLost() calls
> fireApplyEditorValue()] - when someone activates the editor, types into
> the Text and then clicks elsewhere, the value they typed is pushed to
> the model.
> However, this interferes when the CellEditor open-dialog button is
> pushed, because that triggers focus-lost to the Text which in turn
> triggers fireApplyEditorValue() - the problem is that this indirectly
> causes the ColumnViewerEditor to remove its listener from the cell
> editor [see code buried deep in ColumnViewerEditor.applyEditorValue()].
> So when the dialog is closed with a new value chose, the
> ColumnViewerEditor is no longer listening to that CellEditor and doesn't
> get the update.
>
> Any ideas how to get around this conundrum?
>
> Eric


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: [JFace] Text and Dialog button CellEditor? [message #332972 is a reply to message #332944] Mon, 17 November 2008 15:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 11/15/2008 8:31 AM, Tom Schindl wrote:
> Do you have code for me to play with?

This extends another of our home-grown classes,
SelectionDialogCellEditor. You can either change it to extend
org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r or get
SelectionDialogCellEditor from
< https://www.skywayperspectives.org/fisheye/browse/CVS_OpenSo urce/skyway/common/plugins/org.skyway.ui/src/org/skyway/ui/t ables>

Thanks for the help,
Eric


import java.text.MessageFormat;

import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;


public abstract class TextAndDialogCellEditor extends
SelectionDialogCellEditor {

private Text textField;
private Button button;
private FocusListener textFocusListener;

public TextAndDialogCellEditor(ColumnViewer parent, ILabelProvider
labelProvider) {
super(parent, labelProvider);
}


@Override
protected Control createContents(Composite cell) {
textField = new Text(cell, SWT.NONE);
textField.setFont(cell.getFont());
textField.setBackground(cell.getBackground());

textField.addFocusListener(getTextFocusListener());

textField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
keyReleaseOccured(event);
}
});

// Prevent Enter and Esc key traversal from esacping the Text and
being bubbled up to
// parent Controls (for example, to prevent a containing dialog from
getting the Enter or
// Esc key event that occur in this Text)
textField.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail ==
SWT.TRAVERSE_RETURN) {
e.doit = false;
}
}
});

return textField;
}


@Override
protected Button createButton(Composite parent) {
this.button = super.createButton(parent);

button.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
System.out.println("Button gained focus");
}
});

button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println("Button selected");
}
});
return button;
}

protected FocusListener getTextFocusListener() {
if (textFocusListener == null) {
textFocusListener = new FocusAdapter() {
@Override
public void focusLost(FocusEvent event) {
System.out.println("Text lost focus");
setValue();
TextAndDialogCellEditor.this.focusLost();
}
};
}

return textFocusListener;
}


@Override
protected void keyReleaseOccured(KeyEvent keyEvent) {
if (keyEvent.keyCode == SWT.CR) { // Return key
setValue();
}
super.keyReleaseOccured(keyEvent);
}


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

@Override
protected void updateContents(Object object) {
if (textField != null && labelProvider != null) {
textField.setText(labelProvider.getText(object));
}
}

@Override
protected void doSetFocus() {
// Overridden to set focus to the Text widget instead of the Button.
textField.setFocus();
textField.selectAll();
}

}



> Eric Rizzo schrieb:
>> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>>> There is DialogCellEditor and TextCellEditor, but what I need is a
>>> combination of the two, a CellEditor that allows the user to type in
>>> text and also has the ... button for opening a Dialog to select a value.
>>> I've trying to write one by extending DialogCellEditor and adding a Text
>>> field (lots of code copied from TextCellEditor) but I'm having annoying
>>> difficulties getting focus handling to work properly (this is only the
>>> latest issue in a painful progression of them).
>>> Has anyone seen such a CellEditor that I could use rather than continue
>>> to flounder writing my own?
>> I guess I'll (try to) describe the issue I'm facing in case someone has
>> an idea for getting past it.
>> The problem with combining a Text and a Button in the same CellEditor
>> seems to be related to how to handle focus-lost events. The Text needs
>> to have a focus-lost handler that calls CellEditor.focusLost() so that
>> the value from the Text is pushed to the model [focusLost() calls
>> fireApplyEditorValue()] - when someone activates the editor, types into
>> the Text and then clicks elsewhere, the value they typed is pushed to
>> the model.
>> However, this interferes when the CellEditor open-dialog button is
>> pushed, because that triggers focus-lost to the Text which in turn
>> triggers fireApplyEditorValue() - the problem is that this indirectly
>> causes the ColumnViewerEditor to remove its listener from the cell
>> editor [see code buried deep in ColumnViewerEditor.applyEditorValue()].
>> So when the dialog is closed with a new value chose, the
>> ColumnViewerEditor is no longer listening to that CellEditor and doesn't
>> get the update.
>>
>> Any ideas how to get around this conundrum?
>>
>> Eric
>
>
Re: [JFace] Text and Dialog button CellEditor? [message #333229 is a reply to message #332972] Mon, 01 December 2008 15:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Bump. Did anyone have a chance to look at this code or offer an
alternative implementation idea?

Eric


On 11/17/2008 10:55 AM, Eric Rizzo wrote:
> On 11/15/2008 8:31 AM, Tom Schindl wrote:
>> Do you have code for me to play with?
>
> This extends another of our home-grown classes,
> SelectionDialogCellEditor. You can either change it to extend
> org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r or get
> SelectionDialogCellEditor from
> < https://www.skywayperspectives.org/fisheye/browse/CVS_OpenSo urce/skyway/common/plugins/org.skyway.ui/src/org/skyway/ui/t ables>
>
>
> Thanks for the help,
> Eric
>
>
> import java.text.MessageFormat;
>
> import org.eclipse.jface.viewers.ColumnViewer;
> import org.eclipse.jface.viewers.ILabelProvider;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.FocusAdapter;
> import org.eclipse.swt.events.FocusEvent;
> import org.eclipse.swt.events.FocusListener;
> import org.eclipse.swt.events.KeyAdapter;
> import org.eclipse.swt.events.KeyEvent;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.events.TraverseEvent;
> import org.eclipse.swt.events.TraverseListener;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Text;
>
>
> public abstract class TextAndDialogCellEditor extends
> SelectionDialogCellEditor {
>
> private Text textField;
> private Button button;
> private FocusListener textFocusListener;
>
> public TextAndDialogCellEditor(ColumnViewer parent, ILabelProvider
> labelProvider) {
> super(parent, labelProvider);
> }
>
>
> @Override
> protected Control createContents(Composite cell) {
> textField = new Text(cell, SWT.NONE);
> textField.setFont(cell.getFont());
> textField.setBackground(cell.getBackground());
>
> textField.addFocusListener(getTextFocusListener());
>
> textField.addKeyListener(new KeyAdapter() {
> @Override
> public void keyPressed(KeyEvent event) {
> keyReleaseOccured(event);
> }
> });
>
> // Prevent Enter and Esc key traversal from esacping the Text and being
> bubbled up to
> // parent Controls (for example, to prevent a containing dialog from
> getting the Enter or
> // Esc key event that occur in this Text)
> textField.addTraverseListener(new TraverseListener() {
> public void keyTraversed(TraverseEvent e) {
> if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
> e.doit = false;
> }
> }
> });
>
> return textField;
> }
>
>
> @Override
> protected Button createButton(Composite parent) {
> this.button = super.createButton(parent);
>
> button.addFocusListener(new FocusAdapter() {
> @Override
> public void focusGained(FocusEvent e) {
> System.out.println("Button gained focus");
> }
> });
>
> button.addSelectionListener(new SelectionAdapter() {
> @Override
> public void widgetSelected(SelectionEvent e) {
> System.out.println("Button selected");
> }
> });
> return button;
> }
>
> protected FocusListener getTextFocusListener() {
> if (textFocusListener == null) {
> textFocusListener = new FocusAdapter() {
> @Override
> public void focusLost(FocusEvent event) {
> System.out.println("Text lost focus");
> setValue();
> TextAndDialogCellEditor.this.focusLost();
> }
> };
> }
>
> return textFocusListener;
> }
>
>
> @Override
> protected void keyReleaseOccured(KeyEvent keyEvent) {
> if (keyEvent.keyCode == SWT.CR) { // Return key
> setValue();
> }
> super.keyReleaseOccured(keyEvent);
> }
>
>
> protected void setValue() {
> String newValue = textField.getText();
> boolean newValidState = isCorrect(newValue);
> if (newValidState) {
> markDirty();
> doSetValue(newValue);
> } else {
> // try to insert the current value into the error message.
> setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] {
> newValue.toString() }));
> }
> }
>
> @Override
> protected void updateContents(Object object) {
> if (textField != null && labelProvider != null) {
> textField.setText(labelProvider.getText(object));
> }
> }
>
> @Override
> protected void doSetFocus() {
> // Overridden to set focus to the Text widget instead of the Button.
> textField.setFocus();
> textField.selectAll();
> }
>
> }
>
>
>
>> Eric Rizzo schrieb:
>>> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>>>> There is DialogCellEditor and TextCellEditor, but what I need is a
>>>> combination of the two, a CellEditor that allows the user to type in
>>>> text and also has the ... button for opening a Dialog to select a
>>>> value.
>>>> I've trying to write one by extending DialogCellEditor and adding a
>>>> Text
>>>> field (lots of code copied from TextCellEditor) but I'm having annoying
>>>> difficulties getting focus handling to work properly (this is only the
>>>> latest issue in a painful progression of them).
>>>> Has anyone seen such a CellEditor that I could use rather than continue
>>>> to flounder writing my own?
>>> I guess I'll (try to) describe the issue I'm facing in case someone has
>>> an idea for getting past it.
>>> The problem with combining a Text and a Button in the same CellEditor
>>> seems to be related to how to handle focus-lost events. The Text needs
>>> to have a focus-lost handler that calls CellEditor.focusLost() so that
>>> the value from the Text is pushed to the model [focusLost() calls
>>> fireApplyEditorValue()] - when someone activates the editor, types into
>>> the Text and then clicks elsewhere, the value they typed is pushed to
>>> the model.
>>> However, this interferes when the CellEditor open-dialog button is
>>> pushed, because that triggers focus-lost to the Text which in turn
>>> triggers fireApplyEditorValue() - the problem is that this indirectly
>>> causes the ColumnViewerEditor to remove its listener from the cell
>>> editor [see code buried deep in ColumnViewerEditor.applyEditorValue()].
>>> So when the dialog is closed with a new value chose, the
>>> ColumnViewerEditor is no longer listening to that CellEditor and doesn't
>>> get the update.
>>>
>>> Any ideas how to get around this conundrum?
>>>
>>> Eric
>>
>>
>
Re: [JFace] Text and Dialog button CellEditor? [message #333827 is a reply to message #333229] Wed, 07 January 2009 17:41 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Answering another question reminds me that I haven't answered your
question for quite some time.

Eric could you please create a fully running snippet. I can download the
missing class from your repo (though it looks like it's released under
GPL :-( but the binding domain-code would help me to get started maybe
you could provide a snippet without the need for this super-class
because the we could make up a snippet from it.

Tom

Eric Rizzo schrieb:
> Bump. Did anyone have a chance to look at this code or offer an
> alternative implementation idea?
>
> Eric
>
>
> On 11/17/2008 10:55 AM, Eric Rizzo wrote:
>> On 11/15/2008 8:31 AM, Tom Schindl wrote:
>>> Do you have code for me to play with?
>>
>> This extends another of our home-grown classes,
>> SelectionDialogCellEditor. You can either change it to extend
>> org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r or get
>> SelectionDialogCellEditor from
>> < https://www.skywayperspectives.org/fisheye/browse/CVS_OpenSo urce/skyway/common/plugins/org.skyway.ui/src/org/skyway/ui/t ables>
>>
>>
>>
>> Thanks for the help,
>> Eric
>>
>>
>> import java.text.MessageFormat;
>>
>> import org.eclipse.jface.viewers.ColumnViewer;
>> import org.eclipse.jface.viewers.ILabelProvider;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.events.FocusAdapter;
>> import org.eclipse.swt.events.FocusEvent;
>> import org.eclipse.swt.events.FocusListener;
>> import org.eclipse.swt.events.KeyAdapter;
>> import org.eclipse.swt.events.KeyEvent;
>> import org.eclipse.swt.events.SelectionAdapter;
>> import org.eclipse.swt.events.SelectionEvent;
>> import org.eclipse.swt.events.TraverseEvent;
>> import org.eclipse.swt.events.TraverseListener;
>> import org.eclipse.swt.widgets.Button;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.widgets.Control;
>> import org.eclipse.swt.widgets.Text;
>>
>>
>> public abstract class TextAndDialogCellEditor extends
>> SelectionDialogCellEditor {
>>
>> private Text textField;
>> private Button button;
>> private FocusListener textFocusListener;
>>
>> public TextAndDialogCellEditor(ColumnViewer parent, ILabelProvider
>> labelProvider) {
>> super(parent, labelProvider);
>> }
>>
>>
>> @Override
>> protected Control createContents(Composite cell) {
>> textField = new Text(cell, SWT.NONE);
>> textField.setFont(cell.getFont());
>> textField.setBackground(cell.getBackground());
>>
>> textField.addFocusListener(getTextFocusListener());
>>
>> textField.addKeyListener(new KeyAdapter() {
>> @Override
>> public void keyPressed(KeyEvent event) {
>> keyReleaseOccured(event);
>> }
>> });
>>
>> // Prevent Enter and Esc key traversal from esacping the Text and being
>> bubbled up to
>> // parent Controls (for example, to prevent a containing dialog from
>> getting the Enter or
>> // Esc key event that occur in this Text)
>> textField.addTraverseListener(new TraverseListener() {
>> public void keyTraversed(TraverseEvent e) {
>> if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
>> e.doit = false;
>> }
>> }
>> });
>>
>> return textField;
>> }
>>
>>
>> @Override
>> protected Button createButton(Composite parent) {
>> this.button = super.createButton(parent);
>>
>> button.addFocusListener(new FocusAdapter() {
>> @Override
>> public void focusGained(FocusEvent e) {
>> System.out.println("Button gained focus");
>> }
>> });
>>
>> button.addSelectionListener(new SelectionAdapter() {
>> @Override
>> public void widgetSelected(SelectionEvent e) {
>> System.out.println("Button selected");
>> }
>> });
>> return button;
>> }
>>
>> protected FocusListener getTextFocusListener() {
>> if (textFocusListener == null) {
>> textFocusListener = new FocusAdapter() {
>> @Override
>> public void focusLost(FocusEvent event) {
>> System.out.println("Text lost focus");
>> setValue();
>> TextAndDialogCellEditor.this.focusLost();
>> }
>> };
>> }
>>
>> return textFocusListener;
>> }
>>
>>
>> @Override
>> protected void keyReleaseOccured(KeyEvent keyEvent) {
>> if (keyEvent.keyCode == SWT.CR) { // Return key
>> setValue();
>> }
>> super.keyReleaseOccured(keyEvent);
>> }
>>
>>
>> protected void setValue() {
>> String newValue = textField.getText();
>> boolean newValidState = isCorrect(newValue);
>> if (newValidState) {
>> markDirty();
>> doSetValue(newValue);
>> } else {
>> // try to insert the current value into the error message.
>> setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] {
>> newValue.toString() }));
>> }
>> }
>>
>> @Override
>> protected void updateContents(Object object) {
>> if (textField != null && labelProvider != null) {
>> textField.setText(labelProvider.getText(object));
>> }
>> }
>>
>> @Override
>> protected void doSetFocus() {
>> // Overridden to set focus to the Text widget instead of the Button.
>> textField.setFocus();
>> textField.selectAll();
>> }
>>
>> }
>>
>>
>>
>>> Eric Rizzo schrieb:
>>>> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>>>>> There is DialogCellEditor and TextCellEditor, but what I need is a
>>>>> combination of the two, a CellEditor that allows the user to type in
>>>>> text and also has the ... button for opening a Dialog to select a
>>>>> value.
>>>>> I've trying to write one by extending DialogCellEditor and adding a
>>>>> Text
>>>>> field (lots of code copied from TextCellEditor) but I'm having
>>>>> annoying
>>>>> difficulties getting focus handling to work properly (this is only the
>>>>> latest issue in a painful progression of them).
>>>>> Has anyone seen such a CellEditor that I could use rather than
>>>>> continue
>>>>> to flounder writing my own?
>>>> I guess I'll (try to) describe the issue I'm facing in case someone has
>>>> an idea for getting past it.
>>>> The problem with combining a Text and a Button in the same CellEditor
>>>> seems to be related to how to handle focus-lost events. The Text needs
>>>> to have a focus-lost handler that calls CellEditor.focusLost() so that
>>>> the value from the Text is pushed to the model [focusLost() calls
>>>> fireApplyEditorValue()] - when someone activates the editor, types into
>>>> the Text and then clicks elsewhere, the value they typed is pushed to
>>>> the model.
>>>> However, this interferes when the CellEditor open-dialog button is
>>>> pushed, because that triggers focus-lost to the Text which in turn
>>>> triggers fireApplyEditorValue() - the problem is that this indirectly
>>>> causes the ColumnViewerEditor to remove its listener from the cell
>>>> editor [see code buried deep in ColumnViewerEditor.applyEditorValue()].
>>>> So when the dialog is closed with a new value chose, the
>>>> ColumnViewerEditor is no longer listening to that CellEditor and
>>>> doesn't
>>>> get the update.
>>>>
>>>> Any ideas how to get around this conundrum?
>>>>
>>>> Eric
>>>
>>>
>>
>
Re: [JFace] Text and Dialog button CellEditor? [message #333830 is a reply to message #333827] Wed, 07 January 2009 21:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/7/2009 12:41 PM, Tom Schindl wrote:
> Answering another question reminds me that I haven't answered your
> question for quite some time.
>
> Eric could you please create a fully running snippet.

I'll try to put one together in the next few days.



>
> Eric Rizzo schrieb:
>> Bump. Did anyone have a chance to look at this code or offer an
>> alternative implementation idea?
>>
>> Eric
>>
>>
>> On 11/17/2008 10:55 AM, Eric Rizzo wrote:
>>> On 11/15/2008 8:31 AM, Tom Schindl wrote:
>>>> Do you have code for me to play with?
>>>
>>> This extends another of our home-grown classes,
>>> SelectionDialogCellEditor. You can either change it to extend
>>> org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r or get
>>> SelectionDialogCellEditor from
>>> < https://www.skywayperspectives.org/fisheye/browse/CVS_OpenSo urce/skyway/common/plugins/org.skyway.ui/src/org/skyway/ui/t ables>
>>>
>>>
>>>
>>> Thanks for the help,
>>> Eric
>>>
>>>
>>> import java.text.MessageFormat;
>>>
>>> import org.eclipse.jface.viewers.ColumnViewer;
>>> import org.eclipse.jface.viewers.ILabelProvider;
>>> import org.eclipse.swt.SWT;
>>> import org.eclipse.swt.events.FocusAdapter;
>>> import org.eclipse.swt.events.FocusEvent;
>>> import org.eclipse.swt.events.FocusListener;
>>> import org.eclipse.swt.events.KeyAdapter;
>>> import org.eclipse.swt.events.KeyEvent;
>>> import org.eclipse.swt.events.SelectionAdapter;
>>> import org.eclipse.swt.events.SelectionEvent;
>>> import org.eclipse.swt.events.TraverseEvent;
>>> import org.eclipse.swt.events.TraverseListener;
>>> import org.eclipse.swt.widgets.Button;
>>> import org.eclipse.swt.widgets.Composite;
>>> import org.eclipse.swt.widgets.Control;
>>> import org.eclipse.swt.widgets.Text;
>>>
>>>
>>> public abstract class TextAndDialogCellEditor extends
>>> SelectionDialogCellEditor {
>>>
>>> private Text textField;
>>> private Button button;
>>> private FocusListener textFocusListener;
>>>
>>> public TextAndDialogCellEditor(ColumnViewer parent, ILabelProvider
>>> labelProvider) {
>>> super(parent, labelProvider);
>>> }
>>>
>>>
>>> @Override
>>> protected Control createContents(Composite cell) {
>>> textField = new Text(cell, SWT.NONE);
>>> textField.setFont(cell.getFont());
>>> textField.setBackground(cell.getBackground());
>>>
>>> textField.addFocusListener(getTextFocusListener());
>>>
>>> textField.addKeyListener(new KeyAdapter() {
>>> @Override
>>> public void keyPressed(KeyEvent event) {
>>> keyReleaseOccured(event);
>>> }
>>> });
>>>
>>> // Prevent Enter and Esc key traversal from esacping the Text and being
>>> bubbled up to
>>> // parent Controls (for example, to prevent a containing dialog from
>>> getting the Enter or
>>> // Esc key event that occur in this Text)
>>> textField.addTraverseListener(new TraverseListener() {
>>> public void keyTraversed(TraverseEvent e) {
>>> if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail ==
>>> SWT.TRAVERSE_RETURN) {
>>> e.doit = false;
>>> }
>>> }
>>> });
>>>
>>> return textField;
>>> }
>>>
>>>
>>> @Override
>>> protected Button createButton(Composite parent) {
>>> this.button = super.createButton(parent);
>>>
>>> button.addFocusListener(new FocusAdapter() {
>>> @Override
>>> public void focusGained(FocusEvent e) {
>>> System.out.println("Button gained focus");
>>> }
>>> });
>>>
>>> button.addSelectionListener(new SelectionAdapter() {
>>> @Override
>>> public void widgetSelected(SelectionEvent e) {
>>> System.out.println("Button selected");
>>> }
>>> });
>>> return button;
>>> }
>>>
>>> protected FocusListener getTextFocusListener() {
>>> if (textFocusListener == null) {
>>> textFocusListener = new FocusAdapter() {
>>> @Override
>>> public void focusLost(FocusEvent event) {
>>> System.out.println("Text lost focus");
>>> setValue();
>>> TextAndDialogCellEditor.this.focusLost();
>>> }
>>> };
>>> }
>>>
>>> return textFocusListener;
>>> }
>>>
>>>
>>> @Override
>>> protected void keyReleaseOccured(KeyEvent keyEvent) {
>>> if (keyEvent.keyCode == SWT.CR) { // Return key
>>> setValue();
>>> }
>>> super.keyReleaseOccured(keyEvent);
>>> }
>>>
>>>
>>> protected void setValue() {
>>> String newValue = textField.getText();
>>> boolean newValidState = isCorrect(newValue);
>>> if (newValidState) {
>>> markDirty();
>>> doSetValue(newValue);
>>> } else {
>>> // try to insert the current value into the error message.
>>> setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] {
>>> newValue.toString() }));
>>> }
>>> }
>>>
>>> @Override
>>> protected void updateContents(Object object) {
>>> if (textField != null && labelProvider != null) {
>>> textField.setText(labelProvider.getText(object));
>>> }
>>> }
>>>
>>> @Override
>>> protected void doSetFocus() {
>>> // Overridden to set focus to the Text widget instead of the Button.
>>> textField.setFocus();
>>> textField.selectAll();
>>> }
>>>
>>> }
>>>
>>>
>>>
>>>> Eric Rizzo schrieb:
>>>>> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>>>>>> There is DialogCellEditor and TextCellEditor, but what I need is a
>>>>>> combination of the two, a CellEditor that allows the user to type in
>>>>>> text and also has the ... button for opening a Dialog to select a
>>>>>> value.
>>>>>> I've trying to write one by extending DialogCellEditor and adding a
>>>>>> Text
>>>>>> field (lots of code copied from TextCellEditor) but I'm having
>>>>>> annoying
>>>>>> difficulties getting focus handling to work properly (this is only
>>>>>> the
>>>>>> latest issue in a painful progression of them).
>>>>>> Has anyone seen such a CellEditor that I could use rather than
>>>>>> continue
>>>>>> to flounder writing my own?
>>>>> I guess I'll (try to) describe the issue I'm facing in case someone
>>>>> has
>>>>> an idea for getting past it.
>>>>> The problem with combining a Text and a Button in the same CellEditor
>>>>> seems to be related to how to handle focus-lost events. The Text needs
>>>>> to have a focus-lost handler that calls CellEditor.focusLost() so that
>>>>> the value from the Text is pushed to the model [focusLost() calls
>>>>> fireApplyEditorValue()] - when someone activates the editor, types
>>>>> into
>>>>> the Text and then clicks elsewhere, the value they typed is pushed to
>>>>> the model.
>>>>> However, this interferes when the CellEditor open-dialog button is
>>>>> pushed, because that triggers focus-lost to the Text which in turn
>>>>> triggers fireApplyEditorValue() - the problem is that this indirectly
>>>>> causes the ColumnViewerEditor to remove its listener from the cell
>>>>> editor [see code buried deep in
>>>>> ColumnViewerEditor.applyEditorValue()].
>>>>> So when the dialog is closed with a new value chose, the
>>>>> ColumnViewerEditor is no longer listening to that CellEditor and
>>>>> doesn't
>>>>> get the update.
>>>>>
>>>>> Any ideas how to get around this conundrum?
>>>>>
>>>>> Eric
>>>>
>>>>
>>>
>>
Re: [JFace] Text and Dialog button CellEditor? [message #334143 is a reply to message #333827] Thu, 22 January 2009 03:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/7/2009 12:41 PM, Tom Schindl wrote:
> Answering another question reminds me that I haven't answered your
> question for quite some time.
>
> Eric could you please create a fully running snippet. I can download the
> missing class from your repo (though it looks like it's released under
> GPL :-( but the binding domain-code would help me to get started maybe
> you could provide a snippet without the need for this super-class
> because the we could make up a snippet from it.

Wouldn't you know it, I reduced it down to a snippet and now it seems to
be working correctly! Frustrating, but at least the community can
benefit from the work.

A question before I submit the snippet in bugzilla: I've got two
classes, the snippet and the cell editor class. If they are combined
into one (make the cell editor a nested class) I think the code is too
crowded and difficult to follow - that defeats the purpose of a snippet,
doesn't it? So can snippets consist of more than one top-level class?
Would I attach both .java files to the bug report?

Eric


> Eric Rizzo schrieb:
>> Bump. Did anyone have a chance to look at this code or offer an
>> alternative implementation idea?
>>
>> Eric
>>
>>
>> On 11/17/2008 10:55 AM, Eric Rizzo wrote:
>>> On 11/15/2008 8:31 AM, Tom Schindl wrote:
>>>> Do you have code for me to play with?
>>>
>>> This extends another of our home-grown classes,
>>> SelectionDialogCellEditor. You can either change it to extend
>>> org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r or get
>>> SelectionDialogCellEditor from
>>> < https://www.skywayperspectives.org/fisheye/browse/CVS_OpenSo urce/skyway/common/plugins/org.skyway.ui/src/org/skyway/ui/t ables>
>>>
>>>
>>>
>>> Thanks for the help,
>>> Eric
>>>
>>>
>>> import java.text.MessageFormat;
>>>
>>> import org.eclipse.jface.viewers.ColumnViewer;
>>> import org.eclipse.jface.viewers.ILabelProvider;
>>> import org.eclipse.swt.SWT;
>>> import org.eclipse.swt.events.FocusAdapter;
>>> import org.eclipse.swt.events.FocusEvent;
>>> import org.eclipse.swt.events.FocusListener;
>>> import org.eclipse.swt.events.KeyAdapter;
>>> import org.eclipse.swt.events.KeyEvent;
>>> import org.eclipse.swt.events.SelectionAdapter;
>>> import org.eclipse.swt.events.SelectionEvent;
>>> import org.eclipse.swt.events.TraverseEvent;
>>> import org.eclipse.swt.events.TraverseListener;
>>> import org.eclipse.swt.widgets.Button;
>>> import org.eclipse.swt.widgets.Composite;
>>> import org.eclipse.swt.widgets.Control;
>>> import org.eclipse.swt.widgets.Text;
>>>
>>>
>>> public abstract class TextAndDialogCellEditor extends
>>> SelectionDialogCellEditor {
>>>
>>> private Text textField;
>>> private Button button;
>>> private FocusListener textFocusListener;
>>>
>>> public TextAndDialogCellEditor(ColumnViewer parent, ILabelProvider
>>> labelProvider) {
>>> super(parent, labelProvider);
>>> }
>>>
>>>
>>> @Override
>>> protected Control createContents(Composite cell) {
>>> textField = new Text(cell, SWT.NONE);
>>> textField.setFont(cell.getFont());
>>> textField.setBackground(cell.getBackground());
>>>
>>> textField.addFocusListener(getTextFocusListener());
>>>
>>> textField.addKeyListener(new KeyAdapter() {
>>> @Override
>>> public void keyPressed(KeyEvent event) {
>>> keyReleaseOccured(event);
>>> }
>>> });
>>>
>>> // Prevent Enter and Esc key traversal from esacping the Text and being
>>> bubbled up to
>>> // parent Controls (for example, to prevent a containing dialog from
>>> getting the Enter or
>>> // Esc key event that occur in this Text)
>>> textField.addTraverseListener(new TraverseListener() {
>>> public void keyTraversed(TraverseEvent e) {
>>> if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail ==
>>> SWT.TRAVERSE_RETURN) {
>>> e.doit = false;
>>> }
>>> }
>>> });
>>>
>>> return textField;
>>> }
>>>
>>>
>>> @Override
>>> protected Button createButton(Composite parent) {
>>> this.button = super.createButton(parent);
>>>
>>> button.addFocusListener(new FocusAdapter() {
>>> @Override
>>> public void focusGained(FocusEvent e) {
>>> System.out.println("Button gained focus");
>>> }
>>> });
>>>
>>> button.addSelectionListener(new SelectionAdapter() {
>>> @Override
>>> public void widgetSelected(SelectionEvent e) {
>>> System.out.println("Button selected");
>>> }
>>> });
>>> return button;
>>> }
>>>
>>> protected FocusListener getTextFocusListener() {
>>> if (textFocusListener == null) {
>>> textFocusListener = new FocusAdapter() {
>>> @Override
>>> public void focusLost(FocusEvent event) {
>>> System.out.println("Text lost focus");
>>> setValue();
>>> TextAndDialogCellEditor.this.focusLost();
>>> }
>>> };
>>> }
>>>
>>> return textFocusListener;
>>> }
>>>
>>>
>>> @Override
>>> protected void keyReleaseOccured(KeyEvent keyEvent) {
>>> if (keyEvent.keyCode == SWT.CR) { // Return key
>>> setValue();
>>> }
>>> super.keyReleaseOccured(keyEvent);
>>> }
>>>
>>>
>>> protected void setValue() {
>>> String newValue = textField.getText();
>>> boolean newValidState = isCorrect(newValue);
>>> if (newValidState) {
>>> markDirty();
>>> doSetValue(newValue);
>>> } else {
>>> // try to insert the current value into the error message.
>>> setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] {
>>> newValue.toString() }));
>>> }
>>> }
>>>
>>> @Override
>>> protected void updateContents(Object object) {
>>> if (textField != null && labelProvider != null) {
>>> textField.setText(labelProvider.getText(object));
>>> }
>>> }
>>>
>>> @Override
>>> protected void doSetFocus() {
>>> // Overridden to set focus to the Text widget instead of the Button.
>>> textField.setFocus();
>>> textField.selectAll();
>>> }
>>>
>>> }
>>>
>>>
>>>
>>>> Eric Rizzo schrieb:
>>>>> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>>>>>> There is DialogCellEditor and TextCellEditor, but what I need is a
>>>>>> combination of the two, a CellEditor that allows the user to type in
>>>>>> text and also has the ... button for opening a Dialog to select a
>>>>>> value.
>>>>>> I've trying to write one by extending DialogCellEditor and adding a
>>>>>> Text
>>>>>> field (lots of code copied from TextCellEditor) but I'm having
>>>>>> annoying
>>>>>> difficulties getting focus handling to work properly (this is only
>>>>>> the
>>>>>> latest issue in a painful progression of them).
>>>>>> Has anyone seen such a CellEditor that I could use rather than
>>>>>> continue
>>>>>> to flounder writing my own?
>>>>> I guess I'll (try to) describe the issue I'm facing in case someone
>>>>> has
>>>>> an idea for getting past it.
>>>>> The problem with combining a Text and a Button in the same CellEditor
>>>>> seems to be related to how to handle focus-lost events. The Text needs
>>>>> to have a focus-lost handler that calls CellEditor.focusLost() so that
>>>>> the value from the Text is pushed to the model [focusLost() calls
>>>>> fireApplyEditorValue()] - when someone activates the editor, types
>>>>> into
>>>>> the Text and then clicks elsewhere, the value they typed is pushed to
>>>>> the model.
>>>>> However, this interferes when the CellEditor open-dialog button is
>>>>> pushed, because that triggers focus-lost to the Text which in turn
>>>>> triggers fireApplyEditorValue() - the problem is that this indirectly
>>>>> causes the ColumnViewerEditor to remove its listener from the cell
>>>>> editor [see code buried deep in
>>>>> ColumnViewerEditor.applyEditorValue()].
>>>>> So when the dialog is closed with a new value chose, the
>>>>> ColumnViewerEditor is no longer listening to that CellEditor and
>>>>> doesn't
>>>>> get the update.
>>>>>
>>>>> Any ideas how to get around this conundrum?
>>>>>
>>>>> Eric
>>>>
>>>>
>>>
>>
Re: [JFace] Text and Dialog button CellEditor? [message #334150 is a reply to message #334143] Thu, 22 January 2009 07:43 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Eric,

Yes we have some snippets which consist of more than one class. Maybe
adding a comment in the class-javadoc to explain this could help.

Tom

Eric Rizzo schrieb:
> On 1/7/2009 12:41 PM, Tom Schindl wrote:
>> Answering another question reminds me that I haven't answered your
>> question for quite some time.
>>
>> Eric could you please create a fully running snippet. I can download the
>> missing class from your repo (though it looks like it's released under
>> GPL :-( but the binding domain-code would help me to get started maybe
>> you could provide a snippet without the need for this super-class
>> because the we could make up a snippet from it.
>
> Wouldn't you know it, I reduced it down to a snippet and now it seems to
> be working correctly! Frustrating, but at least the community can
> benefit from the work.
>
> A question before I submit the snippet in bugzilla: I've got two
> classes, the snippet and the cell editor class. If they are combined
> into one (make the cell editor a nested class) I think the code is too
> crowded and difficult to follow - that defeats the purpose of a snippet,
> doesn't it? So can snippets consist of more than one top-level class?
> Would I attach both .java files to the bug report?
>
> Eric
>
>
>> Eric Rizzo schrieb:
>>> Bump. Did anyone have a chance to look at this code or offer an
>>> alternative implementation idea?
>>>
>>> Eric
>>>
>>>
>>> On 11/17/2008 10:55 AM, Eric Rizzo wrote:
>>>> On 11/15/2008 8:31 AM, Tom Schindl wrote:
>>>>> Do you have code for me to play with?
>>>>
>>>> This extends another of our home-grown classes,
>>>> SelectionDialogCellEditor. You can either change it to extend
>>>> org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r or get
>>>> SelectionDialogCellEditor from
>>>> < https://www.skywayperspectives.org/fisheye/browse/CVS_OpenSo urce/skyway/common/plugins/org.skyway.ui/src/org/skyway/ui/t ables>
>>>>
>>>>
>>>>
>>>>
>>>> Thanks for the help,
>>>> Eric
>>>>
>>>>
>>>> import java.text.MessageFormat;
>>>>
>>>> import org.eclipse.jface.viewers.ColumnViewer;
>>>> import org.eclipse.jface.viewers.ILabelProvider;
>>>> import org.eclipse.swt.SWT;
>>>> import org.eclipse.swt.events.FocusAdapter;
>>>> import org.eclipse.swt.events.FocusEvent;
>>>> import org.eclipse.swt.events.FocusListener;
>>>> import org.eclipse.swt.events.KeyAdapter;
>>>> import org.eclipse.swt.events.KeyEvent;
>>>> import org.eclipse.swt.events.SelectionAdapter;
>>>> import org.eclipse.swt.events.SelectionEvent;
>>>> import org.eclipse.swt.events.TraverseEvent;
>>>> import org.eclipse.swt.events.TraverseListener;
>>>> import org.eclipse.swt.widgets.Button;
>>>> import org.eclipse.swt.widgets.Composite;
>>>> import org.eclipse.swt.widgets.Control;
>>>> import org.eclipse.swt.widgets.Text;
>>>>
>>>>
>>>> public abstract class TextAndDialogCellEditor extends
>>>> SelectionDialogCellEditor {
>>>>
>>>> private Text textField;
>>>> private Button button;
>>>> private FocusListener textFocusListener;
>>>>
>>>> public TextAndDialogCellEditor(ColumnViewer parent, ILabelProvider
>>>> labelProvider) {
>>>> super(parent, labelProvider);
>>>> }
>>>>
>>>>
>>>> @Override
>>>> protected Control createContents(Composite cell) {
>>>> textField = new Text(cell, SWT.NONE);
>>>> textField.setFont(cell.getFont());
>>>> textField.setBackground(cell.getBackground());
>>>>
>>>> textField.addFocusListener(getTextFocusListener());
>>>>
>>>> textField.addKeyListener(new KeyAdapter() {
>>>> @Override
>>>> public void keyPressed(KeyEvent event) {
>>>> keyReleaseOccured(event);
>>>> }
>>>> });
>>>>
>>>> // Prevent Enter and Esc key traversal from esacping the Text and being
>>>> bubbled up to
>>>> // parent Controls (for example, to prevent a containing dialog from
>>>> getting the Enter or
>>>> // Esc key event that occur in this Text)
>>>> textField.addTraverseListener(new TraverseListener() {
>>>> public void keyTraversed(TraverseEvent e) {
>>>> if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail ==
>>>> SWT.TRAVERSE_RETURN) {
>>>> e.doit = false;
>>>> }
>>>> }
>>>> });
>>>>
>>>> return textField;
>>>> }
>>>>
>>>>
>>>> @Override
>>>> protected Button createButton(Composite parent) {
>>>> this.button = super.createButton(parent);
>>>>
>>>> button.addFocusListener(new FocusAdapter() {
>>>> @Override
>>>> public void focusGained(FocusEvent e) {
>>>> System.out.println("Button gained focus");
>>>> }
>>>> });
>>>>
>>>> button.addSelectionListener(new SelectionAdapter() {
>>>> @Override
>>>> public void widgetSelected(SelectionEvent e) {
>>>> System.out.println("Button selected");
>>>> }
>>>> });
>>>> return button;
>>>> }
>>>>
>>>> protected FocusListener getTextFocusListener() {
>>>> if (textFocusListener == null) {
>>>> textFocusListener = new FocusAdapter() {
>>>> @Override
>>>> public void focusLost(FocusEvent event) {
>>>> System.out.println("Text lost focus");
>>>> setValue();
>>>> TextAndDialogCellEditor.this.focusLost();
>>>> }
>>>> };
>>>> }
>>>>
>>>> return textFocusListener;
>>>> }
>>>>
>>>>
>>>> @Override
>>>> protected void keyReleaseOccured(KeyEvent keyEvent) {
>>>> if (keyEvent.keyCode == SWT.CR) { // Return key
>>>> setValue();
>>>> }
>>>> super.keyReleaseOccured(keyEvent);
>>>> }
>>>>
>>>>
>>>> protected void setValue() {
>>>> String newValue = textField.getText();
>>>> boolean newValidState = isCorrect(newValue);
>>>> if (newValidState) {
>>>> markDirty();
>>>> doSetValue(newValue);
>>>> } else {
>>>> // try to insert the current value into the error message.
>>>> setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] {
>>>> newValue.toString() }));
>>>> }
>>>> }
>>>>
>>>> @Override
>>>> protected void updateContents(Object object) {
>>>> if (textField != null && labelProvider != null) {
>>>> textField.setText(labelProvider.getText(object));
>>>> }
>>>> }
>>>>
>>>> @Override
>>>> protected void doSetFocus() {
>>>> // Overridden to set focus to the Text widget instead of the Button.
>>>> textField.setFocus();
>>>> textField.selectAll();
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>>> Eric Rizzo schrieb:
>>>>>> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>>>>>>> There is DialogCellEditor and TextCellEditor, but what I need is a
>>>>>>> combination of the two, a CellEditor that allows the user to type in
>>>>>>> text and also has the ... button for opening a Dialog to select a
>>>>>>> value.
>>>>>>> I've trying to write one by extending DialogCellEditor and adding a
>>>>>>> Text
>>>>>>> field (lots of code copied from TextCellEditor) but I'm having
>>>>>>> annoying
>>>>>>> difficulties getting focus handling to work properly (this is only
>>>>>>> the
>>>>>>> latest issue in a painful progression of them).
>>>>>>> Has anyone seen such a CellEditor that I could use rather than
>>>>>>> continue
>>>>>>> to flounder writing my own?
>>>>>> I guess I'll (try to) describe the issue I'm facing in case someone
>>>>>> has
>>>>>> an idea for getting past it.
>>>>>> The problem with combining a Text and a Button in the same CellEditor
>>>>>> seems to be related to how to handle focus-lost events. The Text
>>>>>> needs
>>>>>> to have a focus-lost handler that calls CellEditor.focusLost() so
>>>>>> that
>>>>>> the value from the Text is pushed to the model [focusLost() calls
>>>>>> fireApplyEditorValue()] - when someone activates the editor, types
>>>>>> into
>>>>>> the Text and then clicks elsewhere, the value they typed is pushed to
>>>>>> the model.
>>>>>> However, this interferes when the CellEditor open-dialog button is
>>>>>> pushed, because that triggers focus-lost to the Text which in turn
>>>>>> triggers fireApplyEditorValue() - the problem is that this indirectly
>>>>>> causes the ColumnViewerEditor to remove its listener from the cell
>>>>>> editor [see code buried deep in
>>>>>> ColumnViewerEditor.applyEditorValue()].
>>>>>> So when the dialog is closed with a new value chose, the
>>>>>> ColumnViewerEditor is no longer listening to that CellEditor and
>>>>>> doesn't
>>>>>> get the update.
>>>>>>
>>>>>> Any ideas how to get around this conundrum?
>>>>>>
>>>>>> Eric
>>>>>
>>>>>
>>>>
>>>
>
Re: [JFace] Text and Dialog button CellEditor? [message #334156 is a reply to message #334150] Thu, 22 January 2009 14:50 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Snippet submitted: https://bugs.eclipse.org/bugs/show_bug.cgi?id=262016


On 1/22/2009 2:43 AM, Tom Schindl wrote:
> Hi Eric,
>
> Yes we have some snippets which consist of more than one class. Maybe
> adding a comment in the class-javadoc to explain this could help.
>
> Tom
>
> Eric Rizzo schrieb:
>> On 1/7/2009 12:41 PM, Tom Schindl wrote:
>>> Answering another question reminds me that I haven't answered your
>>> question for quite some time.
>>>
>>> Eric could you please create a fully running snippet. I can download the
>>> missing class from your repo (though it looks like it's released under
>>> GPL :-( but the binding domain-code would help me to get started maybe
>>> you could provide a snippet without the need for this super-class
>>> because the we could make up a snippet from it.
>> Wouldn't you know it, I reduced it down to a snippet and now it seems to
>> be working correctly! Frustrating, but at least the community can
>> benefit from the work.
>>
>> A question before I submit the snippet in bugzilla: I've got two
>> classes, the snippet and the cell editor class. If they are combined
>> into one (make the cell editor a nested class) I think the code is too
>> crowded and difficult to follow - that defeats the purpose of a snippet,
>> doesn't it? So can snippets consist of more than one top-level class?
>> Would I attach both .java files to the bug report?
>>
>> Eric
>>
>>
>>> Eric Rizzo schrieb:
>>>> Bump. Did anyone have a chance to look at this code or offer an
>>>> alternative implementation idea?
>>>>
>>>> Eric
>>>>
>>>>
>>>> On 11/17/2008 10:55 AM, Eric Rizzo wrote:
>>>>> On 11/15/2008 8:31 AM, Tom Schindl wrote:
>>>>>> Do you have code for me to play with?
>>>>> This extends another of our home-grown classes,
>>>>> SelectionDialogCellEditor. You can either change it to extend
>>>>> org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r or get
>>>>> SelectionDialogCellEditor from
>>>>> < https://www.skywayperspectives.org/fisheye/browse/CVS_OpenSo urce/skyway/common/plugins/org.skyway.ui/src/org/skyway/ui/t ables>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Thanks for the help,
>>>>> Eric
>>>>>
>>>>>
>>>>> import java.text.MessageFormat;
>>>>>
>>>>> import org.eclipse.jface.viewers.ColumnViewer;
>>>>> import org.eclipse.jface.viewers.ILabelProvider;
>>>>> import org.eclipse.swt.SWT;
>>>>> import org.eclipse.swt.events.FocusAdapter;
>>>>> import org.eclipse.swt.events.FocusEvent;
>>>>> import org.eclipse.swt.events.FocusListener;
>>>>> import org.eclipse.swt.events.KeyAdapter;
>>>>> import org.eclipse.swt.events.KeyEvent;
>>>>> import org.eclipse.swt.events.SelectionAdapter;
>>>>> import org.eclipse.swt.events.SelectionEvent;
>>>>> import org.eclipse.swt.events.TraverseEvent;
>>>>> import org.eclipse.swt.events.TraverseListener;
>>>>> import org.eclipse.swt.widgets.Button;
>>>>> import org.eclipse.swt.widgets.Composite;
>>>>> import org.eclipse.swt.widgets.Control;
>>>>> import org.eclipse.swt.widgets.Text;
>>>>>
>>>>>
>>>>> public abstract class TextAndDialogCellEditor extends
>>>>> SelectionDialogCellEditor {
>>>>>
>>>>> private Text textField;
>>>>> private Button button;
>>>>> private FocusListener textFocusListener;
>>>>>
>>>>> public TextAndDialogCellEditor(ColumnViewer parent, ILabelProvider
>>>>> labelProvider) {
>>>>> super(parent, labelProvider);
>>>>> }
>>>>>
>>>>>
>>>>> @Override
>>>>> protected Control createContents(Composite cell) {
>>>>> textField = new Text(cell, SWT.NONE);
>>>>> textField.setFont(cell.getFont());
>>>>> textField.setBackground(cell.getBackground());
>>>>>
>>>>> textField.addFocusListener(getTextFocusListener());
>>>>>
>>>>> textField.addKeyListener(new KeyAdapter() {
>>>>> @Override
>>>>> public void keyPressed(KeyEvent event) {
>>>>> keyReleaseOccured(event);
>>>>> }
>>>>> });
>>>>>
>>>>> // Prevent Enter and Esc key traversal from esacping the Text and being
>>>>> bubbled up to
>>>>> // parent Controls (for example, to prevent a containing dialog from
>>>>> getting the Enter or
>>>>> // Esc key event that occur in this Text)
>>>>> textField.addTraverseListener(new TraverseListener() {
>>>>> public void keyTraversed(TraverseEvent e) {
>>>>> if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail ==
>>>>> SWT.TRAVERSE_RETURN) {
>>>>> e.doit = false;
>>>>> }
>>>>> }
>>>>> });
>>>>>
>>>>> return textField;
>>>>> }
>>>>>
>>>>>
>>>>> @Override
>>>>> protected Button createButton(Composite parent) {
>>>>> this.button = super.createButton(parent);
>>>>>
>>>>> button.addFocusListener(new FocusAdapter() {
>>>>> @Override
>>>>> public void focusGained(FocusEvent e) {
>>>>> System.out.println("Button gained focus");
>>>>> }
>>>>> });
>>>>>
>>>>> button.addSelectionListener(new SelectionAdapter() {
>>>>> @Override
>>>>> public void widgetSelected(SelectionEvent e) {
>>>>> System.out.println("Button selected");
>>>>> }
>>>>> });
>>>>> return button;
>>>>> }
>>>>>
>>>>> protected FocusListener getTextFocusListener() {
>>>>> if (textFocusListener == null) {
>>>>> textFocusListener = new FocusAdapter() {
>>>>> @Override
>>>>> public void focusLost(FocusEvent event) {
>>>>> System.out.println("Text lost focus");
>>>>> setValue();
>>>>> TextAndDialogCellEditor.this.focusLost();
>>>>> }
>>>>> };
>>>>> }
>>>>>
>>>>> return textFocusListener;
>>>>> }
>>>>>
>>>>>
>>>>> @Override
>>>>> protected void keyReleaseOccured(KeyEvent keyEvent) {
>>>>> if (keyEvent.keyCode == SWT.CR) { // Return key
>>>>> setValue();
>>>>> }
>>>>> super.keyReleaseOccured(keyEvent);
>>>>> }
>>>>>
>>>>>
>>>>> protected void setValue() {
>>>>> String newValue = textField.getText();
>>>>> boolean newValidState = isCorrect(newValue);
>>>>> if (newValidState) {
>>>>> markDirty();
>>>>> doSetValue(newValue);
>>>>> } else {
>>>>> // try to insert the current value into the error message.
>>>>> setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] {
>>>>> newValue.toString() }));
>>>>> }
>>>>> }
>>>>>
>>>>> @Override
>>>>> protected void updateContents(Object object) {
>>>>> if (textField != null&& labelProvider != null) {
>>>>> textField.setText(labelProvider.getText(object));
>>>>> }
>>>>> }
>>>>>
>>>>> @Override
>>>>> protected void doSetFocus() {
>>>>> // Overridden to set focus to the Text widget instead of the Button.
>>>>> textField.setFocus();
>>>>> textField.selectAll();
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>> Eric Rizzo schrieb:
>>>>>>> On 11/14/2008 11:25 AM, Eric Rizzo wrote:
>>>>>>>> There is DialogCellEditor and TextCellEditor, but what I need is a
>>>>>>>> combination of the two, a CellEditor that allows the user to type in
>>>>>>>> text and also has the ... button for opening a Dialog to select a
>>>>>>>> value.
>>>>>>>> I've trying to write one by extending DialogCellEditor and adding a
>>>>>>>> Text
>>>>>>>> field (lots of code copied from TextCellEditor) but I'm having
>>>>>>>> annoying
>>>>>>>> difficulties getting focus handling to work properly (this is only
>>>>>>>> the
>>>>>>>> latest issue in a painful progression of them).
>>>>>>>> Has anyone seen such a CellEditor that I could use rather than
>>>>>>>> continue
>>>>>>>> to flounder writing my own?
>>>>>>> I guess I'll (try to) describe the issue I'm facing in case someone
>>>>>>> has
>>>>>>> an idea for getting past it.
>>>>>>> The problem with combining a Text and a Button in the same CellEditor
>>>>>>> seems to be related to how to handle focus-lost events. The Text
>>>>>>> needs
>>>>>>> to have a focus-lost handler that calls CellEditor.focusLost() so
>>>>>>> that
>>>>>>> the value from the Text is pushed to the model [focusLost() calls
>>>>>>> fireApplyEditorValue()] - when someone activates the editor, types
>>>>>>> into
>>>>>>> the Text and then clicks elsewhere, the value they typed is pushed to
>>>>>>> the model.
>>>>>>> However, this interferes when the CellEditor open-dialog button is
>>>>>>> pushed, because that triggers focus-lost to the Text which in turn
>>>>>>> triggers fireApplyEditorValue() - the problem is that this indirectly
>>>>>>> causes the ColumnViewerEditor to remove its listener from the cell
>>>>>>> editor [see code buried deep in
>>>>>>> ColumnViewerEditor.applyEditorValue()].
>>>>>>> So when the dialog is closed with a new value chose, the
>>>>>>> ColumnViewerEditor is no longer listening to that CellEditor and
>>>>>>> doesn't
>>>>>>> get the update.
>>>>>>>
>>>>>>> Any ideas how to get around this conundrum?
>>>>>>>
>>>>>>> Eric
>>>>>>
Previous Topic:Enable Popup based on Filetype
Next Topic:Re: EMF Databinding using WritableValue
Goto Forum:
  


Current Time: Sat Dec 21 16:23:59 GMT 2024

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

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

Back to the top