Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Focus lost event with hyperlink in Browser
Focus lost event with hyperlink in Browser [message #1373941] Thu, 22 May 2014 11:50 Go to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi,
I have a problem with a hyperlink in the Browser widget. A simplified example is below:

I have an editable table and a Browser widget which contains a hyperlink. When I click inside a table's cell, the celleditor opens and has the focus.

SWT:
When I click on the hyperlink the celleditor closes because the hyperlink gains focus (on mousepressed)

RAP:
The celleditor does not close because the link does not gain the focus (there is no focusOut event on the table/celleditor)


Subsequently this leads to a "Widget is disposed" exception in
org.eclipse.jface.viewers.ColumnViewerEditor.cancelEditing()


Control control = cellEditor.getControl();
if (control != null && !viewer.getControl().isDisposed()) {
if (mouseListener != null) {
control.removeMouseListener(mouseListener); //control is disposed here!


Because control is disposed here

Maybe it is related to http://www.eclipse.org/forums/index.php/m/917900/?srch=focus#msg_917900 ?

[Updated on: Thu, 22 May 2014 13:56]

Report message to a moderator

Re: Focus lost event with hyperlink in Browser [message #1375877 is a reply to message #1373941] Fri, 23 May 2014 06:50 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2334
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
exactly...
This
http://www.eclipse.org/forums/index.php/m/917900/?srch=focus#msg_917900
is the reason.
Best,
Ivan

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Focus lost event with hyperlink in Browser [message #1376078 is a reply to message #1375877] Fri, 23 May 2014 08:47 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
HI Ivan,
thanks for your reply.

Can you give me a hint how to solve the problem?

frank b wrote
found a way to solve the problem using Tim's advice : browser function facility in onclick body event 
however I don't understand what he means
Re: Focus lost event with hyperlink in Browser [message #1384144 is a reply to message #1376078] Wed, 28 May 2014 08:32 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi,
I just tried the following snippet:

<html>

<body>

<select id="selectfield">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw">VW</option>
  <option value="audi" selected>Audi</option>
</select>

<input type="text" id="textfield"></input>

<iframe src="iframe.htm" width="90%" height="400" name="name"></iframe> <!-- here a hyperlink is contained -->

<script type="text/javascript">
document.getElementById("selectfield").onblur = function () { alert("focus lost!"); }
document.getElementById("textfield").onblur = function () { alert("focus lost!"); }
</script>

</body>
</html>


When I click on the hyperlink in the IFrame the focusLost event is sent as expected. Is there no way that RAP can achieve the same behaviour?

[Updated on: Mon, 02 June 2014 08:40]

Report message to a moderator

Re: Focus lost event with hyperlink in Browser [message #1384811 is a reply to message #1384144] Mon, 02 June 2014 09:10 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hi.

The snippet works (I assume) because it relies only on the
browser-native focus handling, while RAP does most of the focus handling
itself. It's actually rather complicated and I can't really say how this
could be fixed without some detailed research. In any case, couldn't you
embed the link using a Label widget with markup?

Greetings,
Tim

> Hi,
> I just tried the following snippet:
>
>
> <html>
>
> <body>
>
> <select id="selectfield">
> <option value="volvo">Volvo</option>
> <option value="saab">Saab</option>
> <option value="vw">VW</option>
> <option value="audi" selected>Audi</option>
> </select>
>
> <input type="text" id="textfield"></input>
>
> <iframe src="iframe.htm" width="90%" height="400" name="name"></iframe>
> <!-- here a hyperlink is contained -->
>
> <script type="text/javascript">
> document.getElementById("selectfield").onblur = function () {
> alert("focus lost!"); }
> document.getElementById("textfield").onblur = function () { alert("focus
> lost!"); }
> </script>
>
> </body>
> </html>
>
>
> When I click on the hyperlink in the IFrame the focusLost event is sent
> as expected. Is there now way that RAP can achieve the same behaviour?

--
Tim Buschtöns

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Focus lost event with hyperlink in Browser [message #1384826 is a reply to message #1376078] Mon, 02 June 2014 11:22 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
> frank b wrote found a way to solve the problem using Tim's advice :
> browser function facility in onclick body event however I don't
> understand what he means

It's a hack using a BrowserFunction (the Java class) to manually
focusing the browser widget. After the BrowserFunction is created it has
to be bound to the browser widgets document body, e.g. by using
browser.evaluate or code like...

document.body.onclick = function(){ myBrowserFunction(); }

.... embedded in the browsers HTML.

I have not tested that, and I can't say for sure it will fix your
problem also.

Greetings,
Tim

--
Tim Buschtöns

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Focus lost event with hyperlink in Browser [message #1385287 is a reply to message #1384826] Thu, 05 June 2014 11:58 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
created bug 436693
Re: Focus lost event with hyperlink in Browser [message #1386260 is a reply to message #1385287] Mon, 16 June 2014 08:43 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi,
I tried to manually send a focusLost event. I created a new BrowserFunction which sends a FocusOut event. However it does not work... Did I do anything wrong here?

    return new BrowserFunction(m_browser, getHyperlinkFunctionName()) {
      @Override
      public Object function(Object[] arguments) {

        Control focusControl = Display.getDefault().getFocusControl();
        if (focusControl != null) {
          System.err.println("sending focus lost event to " + focusControl);
          Event event = new Event();
          event.type = SWT.FocusOut;
          event.widget = focusControl;
          event.display = Display.getDefault();
          focusControl.notifyListeners(SWT.FocusOut, event);

          Event event2 = new Event();
          event2.type = SWT.FocusIn;
          event2.widget = m_browser;
          event2.display = Display.getDefault();
          m_browser.notifyListeners(SWT.FocusIn, event2);
        }

[Updated on: Mon, 16 June 2014 08:48]

Report message to a moderator

Re: Focus lost event with hyperlink in Browser [message #1386265 is a reply to message #1386260] Mon, 16 June 2014 08:58 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2334
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
instead of creating the events manually just try
browser.setFocus/forceFocus(); - this will automatically fire focusOut
of the old focus control and focusIn of the browser. Check the return
value of these methods. Is you browser function executed - sysout printed?
Best,
Ivan

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Focus lost event with hyperlink in Browser [message #1386293 is a reply to message #1386265] Mon, 16 June 2014 12:03 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi Ivan,

thanks for your reply. Yes the BrowserFunction is working.

Is "Control.forceFocus()" somehow different than really clicking into a field by mouse?


Note:
I have a control (A) which has the focus and attached a focusLostListener.

a) Now I click into another field (B) by mouse, the focusLostListener is called. When I look at the currently focused field: getDisplay().getFocusControl() B is focused, as expected.

b) When I do a "B.forceFocus()" in the BrowserFunction, the focusLost listener is called but getDisplay().getFocusControl() returns A

[Updated on: Mon, 16 June 2014 12:04]

Report message to a moderator

Re: Focus lost event with hyperlink in Browser [message #1386300 is a reply to message #1386293] Mon, 16 June 2014 12:18 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2334
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
are you trying to access the focusControl (display().getFocusControl())
inside the focusOut listener? I think in this case the focusControl
should be the one which is about to lose the focus. It seems that this
is not the case when you change the focus on the client (by mouse for
example) - focusControl is changed and then focusOut event is fired.
Best,
Ivan

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Focus lost event with hyperlink in Browser [message #1386304 is a reply to message #1386300] Mon, 16 June 2014 12:47 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Yes, I am calling display().getFocusControl() inside the focusOut listener. Do you know if there is any way to achieve the same behavior as clicking by mouse?
Re: Focus lost event with hyperlink in Browser [message #1386309 is a reply to message #1386304] Mon, 16 June 2014 12:59 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2334
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
just checked in SWT and it behaves like I thought. We should change
(somehow) the implementation when the focus is changed on the client to
behave like focus.setFocus() on the server. Please file a bugzilla about
this difference.
About your question - focucOut is fired before the actual switch of the
focus control. In focusOut listener display.getFocusControl should
return the same control like event.widget. Our current implementation is
not correct and you should not rely on it.
Best,
Ivan

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Focus lost event with hyperlink in Browser [message #1386314 is a reply to message #1386304] Mon, 16 June 2014 13:17 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2334
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
.... bug opened:
437530: Display#getFocusControl returns wrong control in FocusOut
listener when focus is changed on the client
https://bugs.eclipse.org/bugs/show_bug.cgi?id=437530

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Focus lost event with hyperlink in Browser [message #1386524 is a reply to message #1386314] Wed, 18 June 2014 06:15 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi Ivan,
sorry for asking again. Is there a way to achieve the same behavior programatically as like clicking into a field via mouse - e.g. I need to first switch the focus control and afterwards get the focus out.
Re: Focus lost event with hyperlink in Browser [message #1386536 is a reply to message #1386524] Wed, 18 June 2014 07:51 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2334
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
no... FocusOut *must* be fired before the focus control is switched (bug
will be fixed soon). This is the correct logic and this is how SWT works.
Best,
Ivan

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:Nice way to get a lazy loaded, session scoped model (MVC)
Next Topic:[ANN] RAP 2.3RC1 available for download
Goto Forum:
  


Current Time: Wed Feb 19 09:48:09 GMT 2020

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

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

Back to the top