Showing posts with label swt. Show all posts
Showing posts with label swt. Show all posts

Tuesday, August 20, 2013

How to cancel an SWT key event?

KeyEvent in SWT has a doit member variable.
Setting it to false cancels any further handling of the event.

public void keyPressed(KeyEvent e) {
              handleKeyPress(e);
              e.doit = false;// cancels the event
}

Monday, April 22, 2013

stitch eclipse + swt + swtbot + junit + maven + tycho + surefire

In jist a high level view of running swtbot ui tests with maven/tycho
  1. Specify proper packaging i.e eclipse-test-plugin
  2. Specify src directory to maven build, usually it’s different in eclipse than what maven thinks
  3. Specify various parameters(memory, language, arch, ws, os, ..) correctly to vm and program
  4. Add necessary elements (UIHarness, UIThread…, application…) to tycho-surefire configuration
  5. Add all implicit dependencies of application/product as explicit to manifest file of the test plugin. Because tycho cannot resolve implicit dependencies.
  6. Add p2 repositories to pom so that target platform can be resolved into pom dependencies.
  7. Add Declarative Services library/ dependency to test plugin if it uses any declarative service to initialize application/product
All above steps assume at least mid level knowledge on maven/tycho/swtbot/eclipse/rcp and those who have tried the integration already.

32/64 bit issue with SWT, JVM. Solution maven way, eclipse way

SWT ships different libraries for each Operating System (os), Windowing System (ws) and Architecture (arch).
It doesn't allow loading 32 bit library into 64 bit JVM and vice versa.

So one should specify the osgi.arch value explicitly matching the jvm architecture.

In eclipse you can specify from launch configuration -> Arguments -> VM arguments
-Dosgi.arch=x86  for 32 bit jvm
-Dosgi.arch=x86_64 for 64 bit jvm

In maven there is more portable solution via profile
just activate correct profile on system sun.arch.data.model value

<project>
...
<profiles>
...
          <profile>
            <id>osgi-arch-64</id>
            <activation>
                <property>
                    <name>sun.arch.data.model</name>
                    <value>64</value>
                </property>
            </activation>
            <properties>
                <osgi.arch>x86_64</osgi.arch>
            </properties>
        </profile>
      
        <profile>
            <id>osgi-arch-32</id>
            <activation>
                <property>
                    <name>sun.arch.data.model</name>
                    <value>32</value>
                </property>
            </activation>
            <properties>
                <osgi.arch>x86</osgi.arch>
            </properties>
        </profile>
...
</profiles>
...
</project>

In case you are thinking why not setting -Dosgi.arch value in MAVEN_OPTS or JAVA_OPTS?

These are environment variables and they have to be set everywhere you build your project, all your teammates, build servers...