RAP Selectable Label with MarkUp [message #1773316] |
Tue, 26 September 2017 08:33  |
Eclipse User |
|
|
|
Is there are way to allow the text in a Label widget (RAP/Browser) to be selectable with the mouse, so the user can use copy-to-clipboard feature in the browser? This would be similar to any other HTML element on a traditional web page.
I considered using a Text widget instead, and making it read-only, but the problem is that I really need RWT MarkUp styling, and Text does not support this (or does it?!).
Is this achievable?
Thanks, John
|
|
|
|
|
Re: RAP Selectable Label with MarkUp [message #1773434 is a reply to message #1773388] |
Wed, 27 September 2017 15:41   |
Eclipse User |
|
|
|
I don't know how you get to the rwt Widget from client scripting, it's internal API.
There are listeners attached to the document/body/window to handle the select events, calling setSelectable(true) stops the event being cancelled. It also updates the user-select styles that block it.
I did it by selecting the element in Chrome and referencing it with $0.rwtWidget
$0
<div style="background: rgb(255, 255, 255); bor....
$0.rwtWidget
{
[functions]: ,
$cells: [ ],
$el: { },
___rwtStyle__backgroundColor: "rgb(255,255,255)",
....
classname: "rwt.widgets.Label",
name: "rwt.widgets.Label"
}
$0.rwtWidget.getSelectable()
false
$0.rwtWidget.setSelectable(true)
true
You could patch Label.js to call this.setSelectable(true); in the constructor or change the init value in the selectable property. That might have wider reaching effects though.
Perhaps you could make a custom widget based off Label, with its own LCA so you can set the selectable property from the Java side. i don't think you'd need to touch the JS side
|
|
|
Re: RAP Selectable Label with MarkUp [message #1773766 is a reply to message #1773434] |
Wed, 04 October 2017 07:23   |
Eclipse User |
|
|
|
Hi Chris, thanks for the ideas.
However, I'm not understanding how to apply this.
It isn't just Labels in principle... in fact, users will expect that if they can see text on a web page, then they should be able to highlight it with the mouse and copy-to-clipboard, or whatever.
I'm struggling to see how this can be done, with JS, ClientScripting or anything in RAP.
The user-select attribute appears to have no effect, even when modified in Chrome's F12 as a test, so presumably it is the event listeners for the page in RAP that are preventing this. You eluded to this in your reply above, but I've no clue how to apply your suggestion to the page, particularly via code rather than messing about in Chrome's F12. It needs to work on all browsers of course.
Thanks, John
|
|
|
Re: RAP Selectable Label with MarkUp [message #1858955 is a reply to message #1773766] |
Wed, 03 May 2023 05:27  |
Eclipse User |
|
|
|
Hi,
I'd like to come back to this issue here again. I'm also faced with the requirement to allow users to select the text from a Label. I understand that RWT mimics SWT, where you can't select Labe text. However, users expect to be able to select and copy text in the browser and it would be nice if this would be possible at least for Labels in RWT as well.
The suggested workaround is instead to use a Text widget in read-only mode [1] [2]. However, this created an input element instead of a simple div for a Label. Furthermore, this workaround won't work in my case, because I'm using Labels with HTML-markup and rely on the wrapping behavior to create some more HTML-native layout behavior.
I checked the RWT sources and found that for Labels the "selectable" property is disabled in the base MultiCellWidget class here: https://github.com/eclipse-rap/org.eclipse.rap/blob/main/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/MultiCellWidget.js#L115
I did not find any JS API to change this property a runtime for a given Label object, so it doesn't seem to be possible. As I understand, this property causes the CSS property "user-select: none" to be applied on the HTML element. However, when removing or changing this property in the browser dev tools, it still doesn't work. This suggests that there is additionally an event handler attached elsewhere that catches and drops the select event.
I'd to open the discussion again and ask for some pointers on how I could make a Label text selectable or implement a custom "SelectableLabel" widget. An idea would be to copy all the resources from Label and duplicate them into a custom widget SelectableLabel. However, that seems pretty heavy and I never managed to implement a custom widget, since the available docs on how to do this a rather scarce (again, would be grateful for any pointers ;)). I could also create a feature request on GitHub and refer to [1], to get some more insights from the devs. Please let me know.
Best regards,
Ben
[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=406199
[2] https://www.eclipse.org/forums/index.php?t=msg&th=754247&goto=1356535&
|
|
|
Powered by
FUDForum. Page generated in 0.05725 seconds