Skip to end of metadata
Go to start of metadata

GroovySWT is a wrapper around SWT, the eclipse Standard Widget Toolkit. It allows you to easily write Eclipse SWT applications by using Groovy's builder mechanism.
Here is some SWT code using native Groovy:

When you run this (see below for setup details), the result looks like:

Here is the same example using SwtBuilder - note that this example does more because it actually prints some text 'Hello' to standard output when you press the button:

Examples 

For a short example of using the JFace builder for creating a standard application see the TextEditor sample.
You can find about 70 examples in the example directory in subversion or you can download them here.

For a comparison of the groovy and java code see here or see the latest code in subversion.

Platform dependency.

Groovy-swt is not platform dependent, but SWT is. So you need to make sure that you are running a SWT matching the platform you are running the application on. You can download the appropriate SWT version at eclipse (select the eclipse version, find the heading "SWT Binary and Source", and download the SWT for your platform)

Releases:

See the changelog for changes.

0.5:

Updated to eclipse 3.5 (see the changelog for all the other changes)

Please note the 0.5 was completely re-written to use FactoryBuilderSupport (to be able to be included in griffon), so there may be a few inconsistencies with version 0.3, but if you find any then please let me know. You can see the changelog for a list of all the changes.

Another major new feature in version 0.5 is the binding framework (build on top of the jface databinding and following the same style as the swing builder). You can find a little documentation with examples here.

0.3:

The sources (and README.txt telling you how to set up the libraries and dll's) can be found in subversion:

The jar file compiled against Eclipse SDK 3.3 jars can be found attached:

To run groov-swt application you also need some of the eclipse libraries (including SWT), so download groovy-swt-0.3-including-Eclipse-libs.ZIP and unzip all the jar files into the lib directory of your groovy installation. This zip file includes the windows version of SWT, so if you are on another platform you need to download the appropriate version of SWT at eclipse and include that instead.

9 Comments

  1. I am making another implementaion of GroovySwt. It has some features mentioned below.

    • Instead of creating Factory classes source codes manually , I maked factory
      creating program and the program makes all factory's source code .
                    
    • Construction arguments are passed as last parameter. For example ,
          
           button(text:"hello world" , background:[100 , 100, 100] , SWT.PUSH)
           
      this code is same as below.
          
           Button btn = new Button(parent , SWT.PUSH) ;
           btn.setText("hello world") ;
           btn.setBackground(new Color(btn.getDisplay() , 100 , 100 , 100)) ; 
           
      ( note: The Color resource is managed automatically . )
      If Construction arguments' length is longer than 1 , just wrap those in list.
          
           tabItem(text:"hello world" , [SWT.NONE , 1])
                  
    •  You can define interfaces(includes event handlers) inline , or use your 
       custom implementation classes.
         
          button( SWT.PUSH ) {
               selectionListener(
                   widgetSelected:{ println "hello world"   /* define inline */ }
               )
          }
         
          // custom implementation of SelectionListener
          CustomSelectionListener listener = new CustomSelectionListener() ;
         
          button( SWT.PUSH ) {
              selectionListener(listener)    // use custom class
          }
               
    •  You can assign your custom tag name to existing class.  For example , 
       you can use 'BUTTON' to use org.eclipse.swt.widgets.Button . This mapping
       is configured by configuration file at runtime .
       (note : The default mapping (class name) is always usable.)
          

    My Implementation is not perfect currently , but it works fine.
    I want to contribute my works , is It possible ?

  2. Yes, if you have some useful code to contribute, that would be great.

  3. Hello,
    I get SWT.zip, but i don't know how to install . I've read some webs, but i haven't found nothing about this.

    Could someone help me about this? Im working on Windows XP. I've installed Groovy and Eclipse.

    Thanks!


  4. Download the attachment called groovy-swt-0.3-including-Eclipse-libs.ZIP and unzip everything into you groovy/lib directory and remove the old groovyswt.jar from that directory.

     Frank

  5. The link for groovy-swt-0.3-including-Eclipse-libs.ZIP is broken. Can someone fix it?

  6. The link for groovy-swt-0.3-including-Eclipse-libs.ZIP should now be working again.

    Frank 

  7. I found that this jar could not work on 64-bit JVM. When I run the demos, it throws exception like this:Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM.

     

    Any solution?

     

     

  8. oh boy had a little fun getting this all to work

    not sure how recently the project has been updated - but i appear at last to have a working build that generates for eclipse juno .

    steps: sourced the code tree from the svn directory - took a while to figure out how to do that - you have to register an id with xircles for codehaus and then you can get into the svn pages of the groovy link above.

    I stored igt all in a zip - then did an import from zip into my exclipse juno v4 workspace.   Prject loads but lights up like a christmas tree with complie errors - fear not this is what you have to do (entire afternoon explore here )

    1.  you have to get the juno SWT jar first.. This site helps you do that swt download link pages for swt
    2. same trick - save the zip, import into your workspace.  the project so loaded has a working swt.jar file you can use elsewhere in your projects.
    3. if you want jface - more work this is really nasty from eclipse - you have a download a copy of eclipse 4.2 for RCP- which has all the extra jar files in its plugin directory.   heres the eclipse download link i used today juno rcp enabled build (dec 2012).  save this and unzip in a temp directory.  you need a bunch of jars from here.
    4. go back to your first groovy swt project you loaded into the workspace - what i did was add a 'lib' directory to the file tree and then stuffed a bunch of jars in there and include them in your build path.  two apache logging files - had to go to apache to get those and copy them into the lib directory  - the rest are from the RCP build  plugin directory above

    in addition i had to use jindjar .com to locate copies of miglayout, and the icu4j jar, and junit-4.5

    5 once you have that lot include them all in the build path by adding all the jars in your lib directory.

    you still get some errors and wanrings i had to edit some of the groovy files - as some of the classes in src/samples had private classes declared - my complier im using grails 2.1.1 inside GGTS with java 6 didnt like that - so i commented out any private classififers and ran a project /clean.  I think that got it all to compile - howeever when i ran another project i got errors about class versions. 

    last thing to do is use latest java vm 7 and set sdk runtime in your project and the workbench to be the same - then it all seemed to start working.

    once its all compiled up with no errors - you can build another project in groovy or grails and reference your working build project (havnt figured out how to export working groovy_swt into standalone jar yet.  but thats good enough for now.

    hopefully thats enough to get any one else started  - but i think a refresh on the groovy modules svn build is probably required - those private classes really didnt work for me.

    Hope that helps anyone who comes after me - and save you a days toil and heartache.  Might have a moan to eclipse about getting the RCP jars in a more readily installable package - theres no update site i can see just to get these into a standard juno build - my GGTS didnt include them for sure

     

     

     

     

  9. i've downloaded and made a couple of improvements i think that permit you to incrementally build parts and join them together at the end - see above

    in doing so i've created a draft tutorial for swt and jface builder that shows how they can be used

    i've posted a copy here in case any one would else would benefit from it whilst i build it out a little more its currently as draft 0.1

     

    Wills Groovy SWT tutorial.docx