User Tools

Site Tools


Dave Orme muses about agile and functional programming.

My current work emphasizes SOA applications using Scala, Kubernetes, and AWS with a React-based SPA front-end. I'm also interested in progressive web applications and developer tools.


Scala, Clojure, and FP


The Cloud

Data-First Development

Older work

Coconut Palm Software home

Donate Bitcoin:



Kubernetes, Docker, Streaming Data, Spark, Scala, Clojure, OSGi, Karaf, GCP, AWS, SQL


Everything I say here is my own opinion and not necessarily that of my employer.


More XScalaWT

Here are some more Scala and XScalaWT examples, from recent experiments, for those who prefer simple code examples and don't want to read through the longer tutorial.

(As in the previous examples, I'll omit the package statement and imports.)

class LoginDialog(display : Display) extends Shell(display, SWT.NO_TRIM) {
  implicit def unboxText2String(t : Text) = t.getText() 
  var username : Text = null
  var password : Text = null
  var ok = false
  setMaximized(true)  // since we're running inside RAP...
    _.setLayout(new GridLayout(1, false)),
      _.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false))
    label("Username", _.setBackground(WHITE)),
    label("Password", _.setBackground(WHITE)),
    $[Text](SWT.BORDER | SWT.PASSWORD)(password=_),
      _.setLayout(new GridLayout(2, true)),
      _.setLayoutData(new GridData(SWT.CENTER, SWT.NONE, false, false)),
        _.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)),
        { e : SelectionEvent => ok=true; getShell().dispose() }
        _.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)),
        { e : SelectionEvent => getShell().dispose() }
  def getCredentials = if (ok) new UserSession(username, password) else null

The example above shows the generic syntax that lets you access all of SWT, plus any custom controls that you might write. For example:

$[Text](SWT.BORDER | SWT.PASSWORD)(password=_),


  _.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false))

…which leads to the following:

class Banner(parent : Composite, style : Int) extends Composite(parent, style) {
  this.contains (
    _.setLayout(new GridLayout(3, true)),
    label(LOGO.image, _.setBackground(WHITE)),
      _.setLayoutData(new GridData(SWT.FILL, SWT.END, true, false)),

And for those interested, UserSession looks like this:

class UserSession(var userName : String, var password : String) {
  def getPasswordMD5 = try {
    val algorithm = MessageDigest.getInstance("MD5")
    val messageDigest = algorithm.digest()
    val digestBuffer = messageDigest.foldLeft(new StringBuffer()) { 
      (stringBuffer, byte) =>
      stringBuffer.append(Integer.toHexString(0xFF & byte))
  } catch {
    case e : NoSuchAlgorithmException => throw new RuntimeException(e)

Because the “userName” and “password” parameters are declared as “var” parameters, Scala will automatically turn them into bean properties with proper getters and setters. No more typing all that getFoo(), setFoo() boilerplate!

The only thing I don't like about this code is that I'm constantly setting the background color to SWT.WHITE. Looks like I need to look into how to style RAP widgets. Or maybe look into the new E4 style sheet support for SWT…


blog/more_xscalawt.txt · Last modified: 2014/10/17 22:08 (external edit)