Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Event Handling in RAP 2.0 RC1 for existing Widgets
Event Handling in RAP 2.0 RC1 for existing Widgets [message #1006222] Wed, 30 January 2013 13:46 Go to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Hi,

I've read through the new and noteworthy of RAP 2.0 RC1 [1] about the new Java and JavaScript API to create custom widgets.
I'd like to know if this API is also considered to be used to extend existing widgets.
E.g. What I'd like to do is to add a custom hyperlink listener to the Grid widget. Upon a mouse click event, the content of a GridItem is parsed and if there's a hyperlink inside, the server object will get notified about this.

What I've done so far (which does work in RAP 1.5) is to extend the Table.java class with add- and removeHyperlinkListener methods, altered TableLCA to preserve and render the new listener and in TableItem the processing of the event is done by notifying the hyperlink listeners.

I added a function in Grid.js to notify the server about this event. The code looks something like this:

_sendHyperlinkActivated : function( event, item ) {
 var targetNode = event.getDomTarget();
 ...
 var server = rwt.remote.Server.getInstance();
 var properties = { "url" : targetNode.getAttribute("href") };
 server.getRemoteObject( item ).notify( "HyperlinkClicked", properties );
}


The problem that arises is that the notify function of RemoteObject.js won't get inside the if-block
if( this.isListening( event ) )


since there's no listener registered with this event. Therefore, the event is not sent to the server.
I saw that there's a GridHandler.js where listeners are added. So I tried to add the Hyperlink listener to the listener-block but the result was the same.

Questions:


  1. Could you tell me what I need to do further to register the custom listener on the client widget?
  2. Is this the best practice to extend an existing widget by modifying the widget's .js file and its *Handler.js file (on the client side) or is there another way?


Cheers,

Ken

[1] http://www.eclipse.org/rap/noteworthy/2.0/?build=RC1
Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1006647 is a reply to message #1006222] Fri, 01 February 2013 10:16 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Ken,

no, the Remote API can not be used to modify existing widgets. Creating
a RemoteObject leads to a new object being created on the client. I
think for the moment, you'll have to patch the widget for this feature.

A possible workaround could be to point the link to a service handler
that issues the event.

BTW, I think the request for a hyperlink listener on the Grid is already
covered by bug 347436.

Regards, Ralf


[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=347436

--
Ralf Sternberg

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1006694 is a reply to message #1006647] Fri, 01 February 2013 13:06 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Hi Ralf,

Thanks for your reply.

Actually, I'm porting the patch in bug 347436 to RAP 2.0 Razz
But I'm stuck at the part of the _senderHyperlinkActivated function in Grid.js where the request containing the URL is sent to the server.
The previous patch for RAP 1.5 did the following:

var req = org.eclipse.swt.Request.getInstance();
req.addEvent( "org.eclipse.swt.events.hyperlinkActivated", itemId );
req.addParameter( "org.eclipse.swt.events.hyperlinkActivated.url", targetNode.getAttribute("href") );
req.send();


This works perfectly because the request was sent immediately to the server without checking any further conditions.
However, the notification and event handling changed in RAP 2.0. The event is sent to the server by invoking

server.getRemoteObject( item ).notify( "HyperlinkActivated", properties );


According the the documentation of the notify function in RemoteObject.js

Quote:

Notifies the remote object that an event of the given type occurred.
Notifications can only be sent for types that the server is currently listening for (see {@link rap.registerTypeHandler}, <b>handler.events</b>). If this is not the
case, no "notify" operation is written into the message and no request will be sent.
Otherwise the message will be sent to the server within a few milliseconds. One message may contain several "notify" operations, if they are added consecutively.


the notification will only be sent if the server is listening. When debugging the server part, I can see that the listeners are attached correctly. So I think that the client is somehow not informed about the listener. I guess that's why this.isListening(event) returns false.

I haven't figured out so far how I could register the listener on the client side. I assume that I need to extend GridHandler.js too. Any inputs would be appreciated.


Could you point out the idea by implementing a custom service handler a bit? I've only found the old documentation [1]. Do I get it right that I would need to prefix the hyperlink URL with something like "http://localhost:9090/rap?custom_service_handler=myHyperlinkActivatedHandler" and pass the actual hyperlink URL as a parameter ("http://localhost:9090/rap?custom_service_handler=myHyperlinkActivatedHandler&myURL=localhost.....)?

[1] http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.rap.help%2Fhelp%2Fhtml%2Freference%2Fapi%2Forg%2Feclipse%2Frwt%2Fservice%2FIServiceHandler.html

[Updated on: Fri, 01 February 2013 17:38]

Report message to a moderator

Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1007319 is a reply to message #1006647] Tue, 05 February 2013 14:03 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Ralf Sternberg wrote on Fri, 01 February 2013 05:16

A possible workaround could be to point the link to a service handler
that issues the event.


I tried to implement this approach by calling a custom service handler. What I've done so far is to prefix my hyperlinks so that an AJAX call is executed

[1]
"javascript:req=new top.rwt.remote.Request( '" + myURL + "', 'POST', 'text/html' );req.send();";


where myURL is something like

[2]
String myURL = RWT.getServiceManager().getServiceHandlerUrl(myServiceHandler) + "&amp;p=" + originURL;


Upon clicking on a hyperlink, my custom service handler is eventually called. In my use case I need to do some UI processing inside the service handler by calling

[3]
myWidget.getDisplay().asyncExec(new Runnable(){...});


However, this requires that a ServerPushSession is started

[4]
ServerPushSession serverPushSession = new ServerPushSession();
serverPushSession.start();


which opens an additional connection between the client and the server. In the mobile environment (e.g. iPhone) that would mean that you could always see the "loading symbol" whenever a table (grid) widget is opened.

Could you tell me if code snippets in [1], [2], [3] and [4] are supposed to be "best practices" or are there any other possibilities to avoid starting the ServerPushSession?










Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1007375 is a reply to message #1007319] Tue, 05 February 2013 16:33 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 Ken,
your idea about links in the table cells has been discussed in this bug:
347436: Add support for links in table cells
https://bugs.eclipse.org/bugs/show_bug.cgi?id=347436
Stephan Leicht provided a patch against 1.5, but you could get the idea
from there and try to port it to 2.0. Please note that modifying an
existing widget, both on client and server, is not recommended.
HTH,
Ivan

On 2/5/2013 4:03 PM, Ken Lee wrote:
> Ralf Sternberg wrote on Fri, 01 February 2013 05:16
>> A possible workaround could be to point the link to a service handler
>> that issues the event.
>
>
> I tried to implement this approach by calling a custom service
> handler. What I've done so far is to prefix my hyperlinks so that an
> AJAX call is executed
> [1]
>
> "javascript:req=new top.rwt.remote.Request( '" + myURL + "', 'POST',
> 'text/html' );req.send();";
>
>
> where myURL is something like
> [2]
>
> String myURL =
> RWT.getServiceManager().getServiceHandlerUrl(myServiceHandler) + "&p="
> + originURL;
>
>
> Upon clicking on a hyperlink, my custom service handler is eventually
> called. In my use case I need to do some UI processing inside the
> service handler by calling
> [3]
>
> myWidget.getDisplay().asyncExec(new Runnable(){...});
>
>
> However, this requires that a ServerPushSession is started
> [4]
>
> ServerPushSession serverPushSession = new ServerPushSession();
> serverPushSession.start();
>
>
> which opens an additional connection between the client and the
> server. In the mobile environment (e.g. iPhone) that would mean that
> you could always see the "loading symbol" whenever a table (grid)
> widget is opened.
> Could you tell me if code snippets in [1], [2], [3] and [4] are
> supposed to be "best practices" or are there any other possibilities
> to avoid starting the ServerPushSession?
>
>
>
>
>
>
>
>
>
>
>

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1007498 is a reply to message #1006694] Wed, 06 February 2013 08:34 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 Ken,
somehow I missed the point that you are actually trying to port the
patch from the same bug. As this topic has been raised again and again
we will try to come with a solution for RAP 2.1. As I mentioned before,
altering of the RAP widgets is not a good idea and it is not recommended.
Best,
Ivan

On 2/1/2013 3:07 PM, Ken Lee wrote:
> Hi Ralf,
>
> Thanks for your reply.
>
> Actually, I'm porting the patch in bug 347436 to RAP 2.0 :p
> But I'm stuck at the part of the _senderHyperlinkActivated function in
> Grid.js where the request containing the URL is sent to the server.
> The previous patch for RAP 1.5 did the following:
>
>
> var req = org.eclipse.swt.Request.getInstance();
> req.addEvent( "org.eclipse.swt.events.hyperlinkActivated", itemId );
> req.addParameter( "org.eclipse.swt.events.hyperlinkActivated.url",
> targetNode.getAttribute("href") );
> req.send();
>
>
> This works perfectly because the request was sent immediately to the
> server without checking any further conditions.
> However, the notification and event handling changed in RAP 2.0. The
> event is sent to the server by invoking
>
>
> server.getRemoteObject( item ).notify( "HyperlinkActivated",
> properties );
>
>
> According the the documentation of the notify function in RemoteObject.js
>
> Quote:
>> Notifies the remote object that an event of the given type occurred.
>> Notifications can only be sent for types that the server is currently
>> listening for (see {@link rap.registerTypeHandler},
>> <b>handler.events</b>). If this is not the
>> case, no "notify" operation is written into the message and no
>> request will be sent.
>> Otherwise the message will be sent to the server within a few
>> milliseconds. One message may contain several "notify" operations, if
>> they are added consecutively.
>
>
> the notification will only be sent if the server is listening. When
> debugging the server part, I can see that the listeners are attached
> correctly. So I think that the client is somehow not informed about
> the listener. I guess that's why this.isListening(event) returns false.
>
> I haven't figured out so far how I could register the listener on the
> client side. I assume that I need to extend GridHandler.js too. Any
> inputs would be appreciated.
>
>
> Could you point out the idea by implementing a custom service handler
> a bit? I've only found the old documentation [1]. Do I get it right
> that I would need to prefix the hyperlink URL with something like
> "http://localhost:9090/rap?custom_service_handler=myHyperlinkActivatedHandler"
> and pass the actual hyperlink URL as a parameter
> ("http://localhost:9090/rap?custom_service_handler=myHyperlinkActivatedHandler?myURL=localhost.....)?
>
> [1]
> http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.rap.help%2Fhelp%2Fhtml%2Freference%2Fapi%2Forg%2Feclipse%2Frwt%2Fservice%2FIServiceHandler.html

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1007736 is a reply to message #1007498] Thu, 07 February 2013 11:07 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Ivan Furnadjiev wrote on Wed, 06 February 2013 03:34

somehow I missed the point that you are actually trying to port the
patch from the same bug.


Hi Ivan,

Thanks for your reply. Since I'm working with Stephan Leicht, it's important for us that we can port this patch to RAP 2.0 for the Eclipse Scout project.

Quote:

As this topic has been raised again and again we will try to come with a solution for RAP 2.1.


I guess you are referencing the topic about hyperlinks in tables?

Quote:

As I mentioned before, altering of the RAP widgets is not a good idea and it is not recommended.


We know that this is not recommended. Unfortunately, I can't think of any other alternatives than modifying the existing widgets as described in my first and second posts or to use a custom service handler approach as stated in the third post.

It would be great if anyone could give me some hints for both approaches. Probably we need to patch some further widgets in the future and if we have a better understanding about the new event handling in RAP 2.x, I guess it will become a lot easier to implement such a patch.
Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1007773 is a reply to message #1007736] Thu, 07 February 2013 13:20 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 Ken,
yes.. I'm talking about hyperlinks in markup that trigger selection
event on the server. This topic is already in our list for RAP 2.1. We
will try to come with a solution in the next couple of weeks.
Best,
Ivan

On 2/7/2013 1:07 PM, Ken Lee wrote:
> Ivan Furnadjiev wrote on Wed, 06 February 2013 03:34
>> somehow I missed the point that you are actually trying to port the
>> patch from the same bug.
>
>
> Hi Ivan,
>
> Thanks for your reply. Since I'm working with Stephan Leicht, it's
> important for us that we can port this patch to RAP 2.0 for the
> Eclipse Scout project.
>
> Quote:
>> As this topic has been raised again and again we will try to come
>> with a solution for RAP 2.1.
>
>
> I guess you are referencing the topic about hyperlinks in tables?
>
> Quote:
>> As I mentioned before, altering of the RAP widgets is not a good idea
>> and it is not recommended.
>
>
> We know that this is not recommended. Unfortunately, I can't think of
> any other alternatives than modifying the existing widgets as
> described in my first and second posts or to use a custom service
> handler approach as stated in the third post.
>
> It would be great if anyone could give me some hints for both
> approaches. Probably we need to patch some further widgets in the
> future and if we have a better understanding about the new event
> handling in RAP 2.x, I guess it will become a lot easier to implement
> such a patch.
>

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Event Handling in RAP 2.0 RC1 for existing Widgets [message #1008609 is a reply to message #1006222] Wed, 13 February 2013 09:30 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Ken,
the bug:
347436: Add support for links in table cells
https://bugs.eclipse.org/bugs/show_bug.cgi?id=347436
is fixed in master. See comment#13 for more details.
Best,
Ivan

On 1/30/2013 3:46 PM, Ken Lee wrote:
> Hi,
>
> I've read through the new and noteworthy of RAP 2.0 RC1 [1] about the
> new Java and JavaScript API to create custom widgets.
> I'd like to know if this API is also considered to be used to extend
> existing widgets. E.g. What I'd like to do is to add a custom
> hyperlink listener to the Grid widget. Upon a mouse click event, the
> content of a GridItem is parsed and if there's a hyperlink inside, the
> server object will get notified about this.
>
> What I've done so far (which does work in RAP 1.5) is to extend the
> Table.java class with add- and removeHyperlinkListener methods,
> altered TableLCA to preserve and render the new listener and in
> TableItem the processing of the event is done by notifying the
> hyperlink listeners.
>
> I added a function in Grid.js to notify the server about this event.
> The code looks something like this:
>
>
> _sendHyperlinkActivated : function( event, item ) {
> var targetNode = event.getDomTarget();
> ...
> var server = rwt.remote.Server.getInstance();
> var properties = { "url" : targetNode.getAttribute("href") };
> server.getRemoteObject( item ).notify( "HyperlinkClicked", properties );
> }
>
>
> The problem that arises is that the notify function of RemoteObject.js
> won't get inside the if-block
>
> if( this.isListening( event ) )
>
>
> since there's no listener registered with this event. Therefore, the
> event is not sent to the server.
> I saw that there's a GridHandler.js where listeners are added. So I
> tried to add the Hyperlink listener to the listener-block but the
> result was the same.
>
> Questions:
>
> Could you tell me what I need to do further to register the custom
> listener on the client widget? Is this the best practice to extend an
> existing widget by modifying the widget's .js file and its *Handler.js
> file (on the client side) or is there another way?
>
>
> Cheers,
>
> Ken
>
> [1] http://www.eclipse.org/rap/noteworthy/2.0/?build=RC1

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:Multiple sessions in RAP
Next Topic:[ANN] RAP 2.0 RC2 published
Goto Forum:
  


Current Time: Fri Mar 29 13:16:02 GMT 2024

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

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

Back to the top