Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Manage focus of CellEditor in TableViewer
Manage focus of CellEditor in TableViewer [message #491940] Fri, 16 October 2009 15:16 Go to next message
Khoa Nguyen is currently offline Khoa NguyenFriend
Messages: 4
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.
--------------020507010604020502030408
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi friends,

I manage to build a custom Cell Editor for a TableViewer. This cell
editor has 3 common controls which are laid out as in the enclosed image
(http://img62.imageshack.us/img62/3/celleditor.gif). As you might guess,
the [x] button aims to clear that cell value while the [...] button is
for bringing up a chooser dialog.

@Override
protected Control createControl(Composite parent) {
Composite editor = new Composite(parent, getStyle());
Label label = new Label(editor, SWT.NONE);
Button x = new Button(editor, SWT.NONE);
Button ellipsis = new Button(editor, SWT.NONE);
.....
return editor;
}

To deactivate the editor properly, I have to handle the focusLost event
to any of these controls and invoke super.focusLost().

First off, I cannot listen to focusLost event on any of 2 buttons
because if one of them is clicked, the other loses focus and a focusLost
event occurs, thus data is committed before the #widgetSelected() happens.

I tried to solve this problem by not allowing any buttons to grab the
focus (SWT.NO_FOCUS) except the editor control and hope (^_^) as long as
I'm manipulating its sub components (the buttons), the editor control
still doesn't lose its focus. However, the focus of the editor control
is lost as soon as I click on the buttons, even before the
#widgetSelected is invoked... My hope crumbles =((

Now I get stuck. Actually, I may try using #mouseEnter, #mouseExit event
handler to set focus on each button before handling click event.
However, I need a better solution from you guys.

Thanks for spending time on reading my long post ;-)
-instcode

--------------020507010604020502030408
Content-Type: image/gif;
name="celleditor.gif"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="celleditor.gif"

R0lGODlhGwFOAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgMDAwP8AAAD/ AP//AAAA//8A
/wD//////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAA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v+/XW/+733W09L71Lny+kvOrjs978+aLfuVL03/NUO6Wlw4/9/Nnb zlTKJbHfPk3w
f54ktw1xXUIE+LsBus55oAtg/FKxq5pwT0D7A8r7EPi/OMUPgBU0Fgapx8FU cM5uAPJWR/oW
QYqETyHOE1/4Lvi5A7ruJgkUXwJbxhv8ue2BOCyhTCaYwd3xUIP/o1T//6qH Ag/aUCT60+FL
hgjABCKQiUKk4AEvSEXX+aGB+cuhr5TovioGcYBBxKAA5VfBMdrPg5sTHlG4 yD/yoc98bowj
61BAQxqlTY0MYSP/6sdH+mGviB9Eoh6vIj/mpQ55xksk74qIRZIEcpASzJwk JYnGlCxujZCk
CXxqxsmbebKTLmNgDe8YO81lMmPUYKAqU8nKVbqylbB85SqPKMgQ7uuUO4mR LnfJS9rYUW5a
DBsugWLDYj6ElpYMptmGaRKIOdM80BTIM6UZzV9aE5i2xBszu5bEbaarmwla pjdPQsI0ZrN7
48QaONMZpXWyk0GXzOM7VRZPRc0zYI+8Jzf1iQO1gAAAOw==
--------------020507010604020502030408--
Re: Manage focus of CellEditor in TableViewer [message #492151 is a reply to message #491940] Mon, 19 October 2009 07:30 Go to previous messageGo to next message
Khoa Nguyen is currently offline Khoa NguyenFriend
Messages: 4
Registered: July 2009
Junior Member
Khoa Nguyen wrote:
> Hi friends,
>
> I manage to build a custom Cell Editor for a TableViewer. This cell
> editor has 3 common controls which are laid out as in the enclosed image
> (http://img62.imageshack.us/img62/3/celleditor.gif). As you might guess,
> the [x] button aims to clear that cell value while the [...] button is
> for bringing up a chooser dialog.
>
> @Override
> protected Control createControl(Composite parent) {
> Composite editor = new Composite(parent, getStyle());
> Label label = new Label(editor, SWT.NONE);
> Button x = new Button(editor, SWT.NONE);
> Button ellipsis = new Button(editor, SWT.NONE);
> .....
> return editor;
> }
>
> To deactivate the editor properly, I have to handle the focusLost event
> to any of these controls and invoke super.focusLost().
>
> First off, I cannot listen to focusLost event on any of 2 buttons
> because if one of them is clicked, the other loses focus and a focusLost
> event occurs, thus data is committed before the #widgetSelected() happens.
>
> I tried to solve this problem by not allowing any buttons to grab the
> focus (SWT.NO_FOCUS) except the editor control and hope (^_^) as long as
> I'm manipulating its sub components (the buttons), the editor control
> still doesn't lose its focus. However, the focus of the editor control
> is lost as soon as I click on the buttons, even before the
> #widgetSelected is invoked... My hope crumbles =((
>
> Now I get stuck. Actually, I may try using #mouseEnter, #mouseExit event
> handler to set focus on each button before handling click event.
> However, I need a better solution from you guys.
>
> Thanks for spending time on reading my long post ;-)
> -instcode
>
> ------------------------------------------------------------ ------------
>

No one gives me a comment and now I come up with a urly & dirty
workaround (don't refactor yet):

@Override
protected void doSetFocus() {
getControl().forceFocus();
getControl().removeFocusListener(listener);
getControl().addFocusListener(listener);
}

@Override
protected Control createControl(Composite parent) {
Composite editor = new Composite(parent, getStyle());
final Button bt1 = new Button(editor, SWT.DOWN/*|SWT.NO_FOCUS*/);
button.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
bt1.removeFocusListener(listener);
bt2.removeFocusListener(listener);
getControl().removeFocusListener(listener);
bt1.setFocus();
}
@Override
public void mouseExit(MouseEvent e) {
bt1.removeFocusListener(listener);
bt1.addFocusListener(listener);
}
});
final Button bt2 = new Button(editor, SWT.DOWN);
button.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
bt1.removeFocusListener(listener);
bt2.removeFocusListener(listener);
getControl().removeFocusListener(listener);
bt2.setFocus();
}
@Override
public void mouseExit(MouseEvent e) {
bt2.removeFocusListener(listener);
bt2.addFocusListener(listener);
}
});
return editor;
}

Let me get it straight: Suppose we have a composite which is being
focus. All of its children *are not focusable*. My question is: Should
mouse events, keyboard events or any kind of events occur within its
children really need to trigger a focusLost event on the parent
composite? Stupid focusLost event in that case anyway!
Re: Manage focus of CellEditor in TableViewer [message #492170 is a reply to message #492151] Mon, 19 October 2009 09:34 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

http://wiki.eclipse.org/JFaceSnippets#Snippet060TextCellEdit orWithContentProposal
must have solved this also maybe you can take a look there.

Tom

Khoa Nguyen schrieb:
> Khoa Nguyen wrote:
>> Hi friends,
>>
>> I manage to build a custom Cell Editor for a TableViewer. This cell
>> editor has 3 common controls which are laid out as in the enclosed
>> image (http://img62.imageshack.us/img62/3/celleditor.gif). As you
>> might guess, the [x] button aims to clear that cell value while the
>> [...] button is for bringing up a chooser dialog.
>>
>> @Override
>> protected Control createControl(Composite parent) {
>> Composite editor = new Composite(parent, getStyle());
>> Label label = new Label(editor, SWT.NONE);
>> Button x = new Button(editor, SWT.NONE);
>> Button ellipsis = new Button(editor, SWT.NONE);
>> .....
>> return editor;
>> }
>>
>> To deactivate the editor properly, I have to handle the focusLost
>> event to any of these controls and invoke super.focusLost().
>>
>> First off, I cannot listen to focusLost event on any of 2 buttons
>> because if one of them is clicked, the other loses focus and a
>> focusLost event occurs, thus data is committed before the
>> #widgetSelected() happens.
>>
>> I tried to solve this problem by not allowing any buttons to grab the
>> focus (SWT.NO_FOCUS) except the editor control and hope (^_^) as long
>> as I'm manipulating its sub components (the buttons), the editor
>> control still doesn't lose its focus. However, the focus of the editor
>> control is lost as soon as I click on the buttons, even before the
>> #widgetSelected is invoked... My hope crumbles =((
>>
>> Now I get stuck. Actually, I may try using #mouseEnter, #mouseExit
>> event handler to set focus on each button before handling click event.
>> However, I need a better solution from you guys.
>>
>> Thanks for spending time on reading my long post ;-)
>> -instcode
>>
>> ------------------------------------------------------------ ------------
>>
>
> No one gives me a comment and now I come up with a urly & dirty
> workaround (don't refactor yet):
>
> @Override
> protected void doSetFocus() {
> getControl().forceFocus();
> getControl().removeFocusListener(listener);
> getControl().addFocusListener(listener);
> }
>
> @Override
> protected Control createControl(Composite parent) {
> Composite editor = new Composite(parent, getStyle());
> final Button bt1 = new Button(editor, SWT.DOWN/*|SWT.NO_FOCUS*/);
> button.addMouseTrackListener(new MouseTrackAdapter() {
> @Override
> public void mouseEnter(MouseEvent e) {
> bt1.removeFocusListener(listener);
> bt2.removeFocusListener(listener);
> getControl().removeFocusListener(listener);
> bt1.setFocus();
> }
> @Override
> public void mouseExit(MouseEvent e) {
> bt1.removeFocusListener(listener);
> bt1.addFocusListener(listener);
> }
> });
> final Button bt2 = new Button(editor, SWT.DOWN);
> button.addMouseTrackListener(new MouseTrackAdapter() {
> @Override
> public void mouseEnter(MouseEvent e) {
> bt1.removeFocusListener(listener);
> bt2.removeFocusListener(listener);
> getControl().removeFocusListener(listener);
> bt2.setFocus();
> }
> @Override
> public void mouseExit(MouseEvent e) {
> bt2.removeFocusListener(listener);
> bt2.addFocusListener(listener);
> }
> });
> return editor;
> }
>
> Let me get it straight: Suppose we have a composite which is being
> focus. All of its children *are not focusable*. My question is: Should
> mouse events, keyboard events or any kind of events occur within its
> children really need to trigger a focusLost event on the parent
> composite? Stupid focusLost event in that case anyway!
Previous Topic:how to get current font used for treeviewer?
Next Topic:[TableViewer] how to get the selected column?
Goto Forum:
  


Current Time: Thu Mar 28 18:28:38 GMT 2024

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

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

Back to the top