Home » Eclipse Projects » Remote Application Platform (RAP) » RAP Selectable Label with MarkUp(Allow mouse-selection of text in Label with MarkUp)
RAP Selectable Label with MarkUp [message #1773316] |
Tue, 26 September 2017 12:33 |
|
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
---
Just because you can doesn't mean you should
|
|
| |
Re: RAP Selectable Label with MarkUp [message #1773388 is a reply to message #1773364] |
Wed, 27 September 2017 08:15 |
|
Thanks Chris - seems like a hopeful idea.
I tried modifying the "user-select" style attribute in Chrome's F12 tools to "text" as an experiment, but this didn't help.
Would setSelectable(true) be changing something else?
I then tried some ClientScripting to call setSelectable(true) for the widget, but it is an unknown function... can you give me a clue how to call it please?
Error: Error in scripting event type MouseEnter: event.widget.setSelectable is not a function
at rap-client.js:253
...
Here is the JS ClientScript that I tried:
var handleEvent = function(event) {
switch(event.type) {
case SWT.MouseEnter:
event.widget.setSelectable(true);
break;
}
};
Thanks, John
---
Just because you can doesn't mean you should
|
|
|
Re: RAP Selectable Label with MarkUp [message #1773434 is a reply to message #1773388] |
Wed, 27 September 2017 19:41 |
Chris Fairhall Messages: 221 Registered: February 2011 |
Senior Member |
|
|
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 11:23 |
|
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
---
Just because you can doesn't mean you should
|
|
|
Re: RAP Selectable Label with MarkUp [message #1858955 is a reply to message #1773766] |
Wed, 03 May 2023 09:27 |
Benjamin Wolff Messages: 136 Registered: July 2009 |
Senior Member |
|
|
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&
|
|
|
Goto Forum:
Current Time: Thu Mar 28 17:50:17 GMT 2024
Powered by FUDForum. Page generated in 0.03570 seconds
|