Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Accessing Java methods through JavaScript
Accessing Java methods through JavaScript [message #501879] Fri, 04 December 2009 09:35 Go to next message
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
Hello

I have a Browser widget loading a html file and need to know when a link is opened.

The LocationListener does not fire the events:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=196787

So I thought of using JavaScript function calls on the link. Found an solution for RCP: BrowserFunction
But BrowserFunctions are not implemented in RAP jet:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=287371

So my question, is there any other way to access Java methods using JavaScript.
Is there an other way to catch link hits?

greets
Flavio


Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
Re: Accessing Java methods through JavaScript [message #501975 is a reply to message #501879] Fri, 04 December 2009 15:58 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Flavio,

If the HTML is under your control, you can use Javascript to issue
requests whenever a link is opened. On the server-side you can use a
service handler (see JavaDoc for IServiceHandler) to process the
request.

HTH
Rüdiger Herrmann
http://eclipsesource.com

Flavio Donzé wrote:
> Hello
>
> I have a Browser widget loading a html file and need to know when a link
> is opened.
>
> The LocationListener does not fire the events:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=196787
>
> So I thought of using JavaScript function calls on the link. Found an
> solution for RCP: BrowserFunction
> But BrowserFunctions are not implemented in RAP jet:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=287371
>
> So my question, is there any other way to access Java methods using
> JavaScript.
> Is there an other way to catch link hits?
>
> greets
> Flavio
Re: Accessing Java methods through JavaScript [message #502228 is a reply to message #501975] Mon, 07 December 2009 10:14 Go to previous messageGo to next message
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
Hello Rüdiger

Thanks a lot for that tip! I can catch the links here is my class:

public class LinkService implements IServiceHandler {
	/** objectId parameter name */
	private static final String OBJECT_ID = "objectId";
	/** objectType parameter name */
	private static final String OBJECT_TYPE = "objectType";

	@Override
	public void service() throws IOException, ServletException {
		try {
			HttpServletRequest request = ContextProvider.getRequest();

			String objectType = request.getParameter(OBJECT_TYPE);
			String objectId = request.getParameter(OBJECT_ID);

			if (objectType != null && objectId != null) {
				EClassifier classifier = ModelUtil.getModelClassifier(objectType);
				IBasicObjectRefService<BasicObject, ObjectRef> service = CommonPlugin.getDefault().getRefService(
						classifier);
				final BasicObject object = service.findById(objectId);

				UIUtil.openViewerEditor(object);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


The problem now is that I want to open an editor "UIUtil.openViewerEditor()".

here the first few lines in openViewerEditor():

		IWorkbench workbench = PlatformUI.getWorkbench();
		IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
		if (window == null && workbench.getWorkbenchWindowCount() > 0) {
			window = workbench.getWorkbenchWindows()[0];
		}
		if (window == null) {
			throw new RuntimeException("no workbench window found, can not open editor");
		}
		IWorkbenchPage page = window.getActivePage();


Well getActiveWorkbenchWindow() returns null and accessing workbench.getWorkbenchWindows()[0] throws an "Invalid thread access" exception.

Any hint on how to handle that?

greets and thanks
flavio


Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
Re: Accessing Java methods through JavaScript [message #502245 is a reply to message #502228] Mon, 07 December 2009 12:02 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
the service-handler code is executed on a non-UI-thread, hence the
exceptions.
If you just want to open an editor, why don't you use the Link Widget?

Flavio Donzé wrote:
> Hello Rüdiger
>
> Thanks a lot for that tip! I can catch the links here is my class:
>
>
> public class LinkService implements IServiceHandler {
> /** objectId parameter name */
> private static final String OBJECT_ID = "objectId";
> /** objectType parameter name */
> private static final String OBJECT_TYPE = "objectType";
>
> @Override
> public void service() throws IOException, ServletException {
> try {
> HttpServletRequest request = ContextProvider.getRequest();
>
> String objectType = request.getParameter(OBJECT_TYPE);
> String objectId = request.getParameter(OBJECT_ID);
>
> if (objectType != null && objectId != null) {
> EClassifier classifier =
> ModelUtil.getModelClassifier(objectType);
> IBasicObjectRefService<BasicObject, ObjectRef> service =
> CommonPlugin.getDefault().getRefService(
> classifier);
> final BasicObject object = service.findById(objectId);
>
> UIUtil.openViewerEditor(object);
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
>
> The problem now is that I want to open an editor
> "UIUtil.openViewerEditor()".
>
> here the first few lines in openViewerEditor():
>
>
> IWorkbench workbench = PlatformUI.getWorkbench();
> IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
> if (window == null && workbench.getWorkbenchWindowCount() > 0) {
> window = workbench.getWorkbenchWindows()[0];
> }
> if (window == null) {
> throw new RuntimeException("no workbench window found, can
> not open editor");
> }
> IWorkbenchPage page = window.getActivePage();
>
>
> Well getActiveWorkbenchWindow() returns null and accessing
> workbench.getWorkbenchWindows()[0] throws an "Invalid thread access"
> exception.
>
> Any hint on how to handle that?
>
> greets and thanks
> flavio
Re: Accessing Java methods through JavaScript [message #502248 is a reply to message #502245] Mon, 07 December 2009 13:01 Go to previous messageGo to next message
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
I can't use the link widget.
In our software we generate html, for example a gmf document contains links on other documents, this gmf document is exported as image and displayed in a html file where the links are handled in an "image map".
Clicking one of these links opens a new multi page editor where one page displays the generated html in a browser widget (again containing links on other documents).
Since we generate the html links we can define them. Right now one looks like this:

http://127.0.0.1:2232/scodi?startup=viewer&custom_servic e_handler=linkHandler&objectId=_TZFC4OApEd69Jd9lCYI-wg&a mp;objectType=Person


any idea how I should handle that? not possible?

thanks
flavio


Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
Re: Accessing Java methods through JavaScript [message #502257 is a reply to message #502248] Mon, 07 December 2009 13:28 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
(without having tried it myself) you could use Display#asyncExec()
to execute the UI code.
Be aware that you cannot use Display#getCurrent() from a
non-UI-thread. When running on 1.3M3 or later you could use
Display#getDefault(), otherwise you need to buffer a reference to
the display my other means.

Flavio Donzé wrote:
> I can't use the link widget.
> In our software we generate html, for example a gmf document contains
> links on other documents, this gmf document is exported as image and
> displayed in a html file where the links are handled in an "image map".
> Clicking one of these links opens a new multi page editor where one page
> displays the generated html in a browser widget (again containing links
> on other documents). Since we generate the html links we can define
> them. Right now one looks like this:
>
> http://127.0.0.1:2232/scodi?startup=viewer&custom_servic e_handler=linkHandler&objectId=_TZFC4OApEd69Jd9lCYI-wg&a mp;objectType=Person
>
>
>
> any idea how I should handle that? not possible?
>
> thanks
> flavio
Re: Accessing Java methods through JavaScript [message #504107 is a reply to message #502257] Thu, 17 December 2009 09:51 Go to previous message
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
Display#asyncExec() only opens the new editor when I close the active one => Click the link, nothing happens, close the active editor, the new editor is opened.

I hope BrowserFunction support is missing will be resolved soon. That would make life a lot easier Smile


Prozessmanagement und Qualitätsmanagement Software QMS/IMS
https://www.scodi.ch
Re: Accessing Java methods through JavaScript [message #504142 is a reply to message #504107] Thu, 17 December 2009 07:16 Go to previous message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
It seems like you need to activate the UICallback to execute the
runnable that is passed to asyncExec().


On 17.12.2009 10:51, Flavio Donzé wrote:
> Display#asyncExec() only opens the new editor when I close the active
> one => Click the link, nothing happens, close the active editor, the new
> editor is opened.
>
> I hope https://bugs.eclipse.org/bugs/show_bug.cgi?id=287371 will be
> resolved soon. That would make life a lot easier :)
Previous Topic:Use a software site location for RAP in a target platform
Next Topic:Building a RAP web-app with buckminster
Goto Forum:
  


Current Time: Tue Apr 23 07:51:38 GMT 2024

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

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

Back to the top