javaeclipseeclipse-rap

How to position the cursor pointer in RAP


I am trying to create a RAP application that needs to move the cursor pointer to a certain position during a game.

Is there a way, using SWT, to move the cursor position? Obviously the java.awt.Robot().mouseMove is not valid in this case because it uses AWT.


Solution

  • RAP does not support changing the cursor location.

    Display::getCursorLocation allows to query the (last known) cursor location, but there setCursorLocation, which is available in SWT is not implemented by RAP.

    Even if there was an API server-side, I doubt that the client security policy would allow to mess the mouse pointer position.


    Addressing your comment, for end-to-end testing RAP UIs you may want to look at this post: https://eclipsesource.com/blogs/2014/04/29/how-to-write-ui-tests-for-rap-with-selenium-2-0/ that describes how to set up Selenium UI tests for RAP applications.

    In my experience it is best to separate the UI from the rest of your application code so that the UI layer becomes so thin that it is safe enough to go without automated tests.

    Another way to test SWT or RAP UIs is to expose the relevant widgets to the test code and use Widget::notifyListeners to simulate user interaction. Again this works best if your application logic is cleanly separated and can be replaced with tests doubles while testing.