Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Label text is initially truncated
Label text is initially truncated [message #1143270] Fri, 18 October 2013 00:55 Go to next message
M Küng
Messages: 3
Registered: October 2012
Junior Member
Hi Everyone,

I've currently doing some work on a RAP application and have encountered a strange issue with Label sizes. What I'm trying to do is determine the largest width Label on a form and set all the labels to the same widthHint in a GridLayout. The means that in a two column layout of "buddied" controls (e.g. a Label and a Text control in each column) the layout is symmetrical.

This works great in a matching RCP application but what's happening in RAP is that that the first time the app is loaded in a browser the longer labels are being truncated because the width calculation is not returning the correct value.

If I refresh the page in the browser the text size calculations are corrected and the labels display untruncated.

The issue seems to happen in the text size estimation code but I'm not sure why refreshing the page in the browser is resetting the calculation.

I've attached screenshots from a simple hello app to demonstrate the before and after refresh display. The code used to create the control is as follows:

Composite container = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(container);
Label label = new Label(container, SWT.BORDER);
label.setText("TRUNCATED LONG PIECE OF TEXT:");
label.pack();
GridDataFactory.swtDefaults().hint(label.getSize().x, SWT.DEFAULT).applyTo(label);


Any ideas on how to work around this?
index.php/fa/16494/0/
index.php/fa/16495/0/
  • Attachment: Correct.png
    (Size: 3.19KB, Downloaded 138 times)
  • Attachment: Truncated.png
    (Size: 3.09KB, Downloaded 136 times)
Re: Label text is initially truncated [message #1143949 is a reply to message #1143270] Fri, 18 October 2013 10:38 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1794
Registered: July 2009
Senior Member
Hi,
this is an expected behavior and it's how Text Size Determination (TSD)
works in RAP.
- When the application is started for the first time (after server
start) the size of the text "TRUNCATED LONG PIECE OF TEXT:" is estimated
(real text size in browser is not known yet)
- Text is sent to the client for measurement.
- With the next request real text size is send to the server and
re-layout is performed to adjust the widget bounds.
- The real text size is kept into a "text size database"
- With the next application start (reload), the text size is already
know (available in the "text size database") and it's used directly.
I hope that this explains it.
Best,
Ivan

On 10/18/2013 3:54 PM, M Küng wrote:
> Hi Everyone,
>
> I've currently doing some work on a RAP application and have encountered a strange issue with Label sizes. What I'm trying to do is determine the largest width Label on a form and set all the labels to the same widthHint in a GridLayout. The means that in a two column layout of "buddied" controls (e.g. a Label and a Text control in each column) the layout is symmetrical.
>
> This works great in a matching RCP application but what's happening in RAP is that that the first time the app is loaded in a browser the longer labels are being truncated because the width calculation is not returning the correct value.
>
> If I refresh the page in the browser the text size calculations are corrected and the labels display untruncated.
>
> The issue seems to happen in the text size estimation code but I'm not sure why refreshing the page in the browser is resetting the calculation.
>
> I've attached screenshots from a simple hello app to demonstrate the before and after refresh display. The code used to create the control is as follows:
>
> Composite container = new Composite(parent, SWT.NONE);
> GridLayoutFactory.fillDefaults().applyTo(container);
> Label label = new Label(container, SWT.BORDER);
> label.setText("TRUNCATED LONG PIECE OF TEXT:");
> label.pack();
> GridDataFactory.swtDefaults().hint(label.getSize().x, SWT.DEFAULT).applyTo(label);
>
> Any ideas on how to work around this?
>
>

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Label text is initially truncated [message #1144553 is a reply to message #1143949] Fri, 18 October 2013 20:00 Go to previous messageGo to next message
M Küng
Messages: 3
Registered: October 2012
Junior Member
Hi Ivan,

Thanks for the quick response. That does indeed explain why it's happening but it doesn't explain how to work around the issue.

It there an elegant way to force the re-layout to happen without requiring the user to refresh the page in the browser?

I tried calling layout(true, true) on the parent Composite but that doesn't work and I can see that the TSD code is simply returning the last value it cached rather then updating the cached value.

Thanks,

Marcel
Re: Label text is initially truncated [message #1145058 is a reply to message #1144553] Sat, 19 October 2013 04:14 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1794
Registered: July 2009
Senior Member
Hi Marcel,
the common workaround is to add a resize listener to the widget and do
your logic there. When widget is created, its bounds are estimated,
based on text size estimation. With the next request from the client (it
happens automatically if there are text for measuring) the layout will
be triggered and the widget bounds will be automatically adjusted to the
real text size. No need to reload the application.
Best,
Ivan

On 10/19/2013 3:00 AM, M Küng wrote:
> Hi Ivan,
>
> Thanks for the quick response. That does indeed explain why it's
> happening but it doesn't explain how to work around the issue.
>
> It there an elegant way to force the re-layout to happen without
> requiring the user to refresh the page in the browser?
>
> I tried calling layout(true, true) on the parent Composite but that
> doesn't work and I can see that the TSD code is simply returning the
> last value it cached rather then updating the cached value.
>
> Thanks,
>
> Marcel

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Label text is initially truncated [message #1145979 is a reply to message #1145058] Sat, 19 October 2013 18:51 Go to previous message
M Küng
Messages: 3
Registered: October 2012
Junior Member
Hi Ivan,

Awesome. Adding the resize listener does the trick and the same code works nicely in both RAP and RCP.

Thanks very much,

Marcel

Ivan Furnadjiev wrote on Sat, 19 October 2013 21:14
Hi Marcel,
the common workaround is to add a resize listener to the widget and do
your logic there. When widget is created, its bounds are estimated,
based on text size estimation. With the next request from the client (it
happens automatically if there are text for measuring) the layout will
be triggered and the widget bounds will be automatically adjusted to the
real text size. No need to reload the application.
Best,
Ivan

On 10/19/2013 3:00 AM, M Küng wrote:
> Hi Ivan,
>
> Thanks for the quick response. That does indeed explain why it's
> happening but it doesn't explain how to work around the issue.
>
> It there an elegant way to force the re-layout to happen without
> requiring the user to refresh the page in the browser?
>
> I tried calling layout(true, true) on the parent Composite but that
> doesn't work and I can see that the TSD code is simply returning the
> last value it cached rather then updating the cached value.
>
> Thanks,
>
> Marcel

Previous Topic:CTabItem background-color not themable?
Next Topic:Setup for Standalone RAP with Spring
Goto Forum:
  


Current Time: Mon Sep 01 03:40:32 EDT 2014

Powered by FUDForum. Page generated in 0.01820 seconds