Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Sunday, November 6, 2016

Securing JavaFX Content Based on Role

This is an example where a MainView contains two child views, AllAccessView and AdminOnlyView.  All of the views are in .fxml and AllAccessView and AdminOnlyView are fx:included in MainView.

A setRole() method is provided by MainViewController.  This method sets an internal field which is tied to a ChangeListener.  The ChangeListener will decide, based on role, whether or not to show both views (for Admin) or just one (for User).

The fx:include code is wrapped up in Boxes to make the adding and removing easier.

I'll expand upon this later.

The code will explain things better.

SecuredApp Source

Monday, October 24, 2016

Disambiguiating Nil Arguments in Swift

Overloading functions in Swift enables you to use the same function name with arguments of different types.  This can lead to an easier-to-use API, especially with code completion.  Instead of having a complement of functions like

  saveMyClass(myclass)
  saveAnotherClass(anotherclass), and
  saveYetAnotherClass(yetanotherclass),

you'd just use a single save() function that would accept the three different types.  The previous example becomes

  save(myclass),
  save(anotherclass), and
  save(yetanotherclass).


Disambiguating Null Arguments in Kotlin

To define a function argument that can accept a null value in Kotlin, you use the question mark (?) operator.  For example,

fun bar(name : String?) { // ... do something

Can accept both a String argument like "Hello, World!" and a null.  If you have another version of bar() that accepts a nullable argument, say

fun bar(name : Int?) { // ... do something w. an Int

You'll run into a problem if you call

bar(null)

To disambiguate this, you need to provide type into to Kotlin. That type info should be a nullable type. In the following code, a method "foo" is updated with a newer version. Both functions can coexist when non-null arguments are passed. The Kotlin as keyword is used to specify exactly which function is to be used for the null value (and the code compiled).


Wednesday, September 21, 2016

A TornadoFX Kotlin Context Menu with Alert Confirmation

This post demonstrates how to specify an action handler for the TornadoFX alert() function.  This code supports a ContextMenu delete operation.  The delete operation requires a confirmation.   "Cancel" will cancel the delete operation, closing the ContextMenu.  "OK" will adjust the TableView and call the back-end logic through a TornadoFX Controller class.

The purpose of the post is to show the syntax of Kotlin and TornadoFX rather than provide working code.  For that type of tutorial, check out courses.bekwam.net/public_tutorials.