Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control?(in order to achieve a specific function by replacing SWT.ICON_CANCEL in a Text control)
How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control? [message #1772844] Sun, 17 September 2017 06:56 Go to next message
David Lee is currently offline David LeeFriend
Messages: 78
Registered: May 2013
Member
Hi,

By using style SWT.SEARCH + SWT.ICON_SEARCH, we can see an "eraser" icon on the right of a Text control, and clear all content of the Text by clicking the icon.

If I want to change its behavior, my questions are:
1.How to change "eraser" icon to be another one(eg. SWT.ICON_INFORMATION or a self design icon)?
2.How to show a message box instead of clearing content of the Text control after click? (without clearing the content of the Text)

Thank you!

Best,
David

[Updated on: Sun, 17 September 2017 08:13]

Report message to a moderator

Re: How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control? [message #1772866 is a reply to message #1772844] Mon, 18 September 2017 06:47 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
the icon can be changed via themeing. See [1] and [2].
To react on icon click you have to register a Selection listener and check the "detail" field of the Event object.

HTH,
Ivan

[1] http://download.eclipse.org/rt/rap/doc/3.2/guide/reference/theming/Text.html#Text-Search-Icon
[2] http://download.eclipse.org/rt/rap/doc/3.2/guide/reference/theming/Text.html#Text-Cancel-Icon
Re: How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control? [message #1772901 is a reply to message #1772866] Mon, 18 September 2017 13:54 Go to previous messageGo to next message
David Lee is currently offline David LeeFriend
Messages: 78
Registered: May 2013
Member
Hi,Ivan,

Thank you for your quick reply!

For a certain reason, I am trying to keep the text on a Text as it is after clicking eraser icon, and use the erase click event to do something else.

---------
protected SelectionListener selectionListener = new SelectionAdapter() {
@Override
public void widgetDefaultSelected( SelectionEvent event ) {
if( event.detail == SWT.ICON_CANCEL )
System.out.println( "ICON_CANCEL clicked" )
}
};

Text myText = new Text(...);
myText.setText("Hello!");
myText .addSelectionListener(selectionListener); // register selectionListener
----------

Code above ALWAYS erases text "Hello!" on myText BEFORE showing "ICON_CANCEL clicked" on cancel icon click.

Is there any way to keep the text on Text (ie. get rid of being defaultly erased) on cancel icon click?
Thank you for your guidance!

Best
David

[Updated on: Mon, 18 September 2017 15:42]

Report message to a moderator

Re: How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control? [message #1772944 is a reply to message #1772901] Tue, 19 September 2017 09:08 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
the value of the text field is cleared on the client [1], before DefaultSelection event is send to the server. If you reset the value back from the server, you will have only little flickering.

[1] https://github.com/eclipse/rap/blob/master/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Text.js#L120

HTH,
Ivan
Re: How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control? [message #1772951 is a reply to message #1772944] Tue, 19 September 2017 11:47 Go to previous messageGo to next message
David Lee is currently offline David LeeFriend
Messages: 78
Registered: May 2013
Member
Hi! Ivan,

Thank you for reply!

Dose that mean the only way is to store the value somewhere, and then restore it back to the Text control after eraser icon click?

BEST,
David

Re: How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control? [message #1772953 is a reply to message #1772951] Tue, 19 September 2017 12:14 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
there is always a hacky way - patch RAP client (JS) from the server to replace the Text.js#_onMouseDownUp function with a copy without 'setValue("")'. But that's the last last thing you could try, as patching RAP internals are risky and there is no guarantee that it will work with the next RAP version.

[1] https://github.com/eclipse/rap/blob/master/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Text.js#L112

Regards,
Ivan
Re: How to change icon and overwrite builtin event code of SWT.ICON_CANCEL in a Text control? [message #1773074 is a reply to message #1772953] Thu, 21 September 2017 06:59 Go to previous message
David Lee is currently offline David LeeFriend
Messages: 78
Registered: May 2013
Member
Hi,Ivan,

Thank you so much for your guidance!
In my opinion, due to the value of a Text can be programmatically cleared, on cancel click, instead of defaultly clearing the value, allow programmers to decide what to do can be more flexible!

BEST,
David

[Updated on: Fri, 22 September 2017 16:09]

Report message to a moderator

Previous Topic:Missing signed information on package org.eclipse.rap.rwt.testfixture_3.2.0.20160811-0840.jar
Next Topic:[ANN] RAP 3.3 released
Goto Forum:
  


Current Time: Wed Apr 24 17:40:00 GMT 2024

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

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

Back to the top