e(fx)clipse 1.0 – New Features – Generate JavaFX Properties accessors


e(fx)clipse 1.0.0 is just around the corner and scheduled to be released on August 15th, while we are polishing the final bits, the Eclipse IP-Team checks our IP-Log, … .

I’d like to introduce you the new and exiting features that we worked on in the last months since we released 0.9.0 in February.

Blog series

Other posts in this series are:

The first feature we’d like to introduce is small helper who allows you to generate get*/set*/*Property methods for your JavaFX properties.

For those not familiar with JavaFX development: A JavaFX Bean works a bit different than a plain Java Bean. I guess all of you are familiar with the JavaBean-Pattern which looks like this:

public class MyBean {
  private int myInt;
  private int myReadonlyInt;

  private PropertyChangeSupport support = 
    new PropertyChangeSupport(this);

  public void addPropertyChangeListener(
    PropertyChangeListener l) {
      support.addPropertyChangeListener(l);
  }

  public void removePropertyChangeListener(
    PropertyChangeListener l) {
      support.removePropertyChangeListener(l);
  }

  public int getMyInt() {
    return myInt;
  }

  public void setMyInt(int myInt) {
    support.firePropertyChange(
      "myInt",this.myInt,this.myInt=myInt);
    setMyReadonlyInt(myInt*2);
  }

  public int getMyReadonlyInt() {
    return myReadonlyInt;
  }

  private void setMyReadonlyInt(int myReadonlyInt) {
    support.firePropertyChange(
      "myReadonlyInt",this.myReadonlyInt,this.myReadonlyInt=myReadonlyInt);
  }
}

which is written in JavaFX like this:

public class MyFXBean {
  private IntegerProperty myInt = new SimpleIntegerPropery(this,"myInt");
  private ReadOnlyIntegerWrapper myReadonlyInt = new ReadOnlyIntegerWrapper(this,"myReadonlyInt");
  
  public int getMyInt() {
    return myIntProperty().get();
  }

  public void setMyInt(int myInt) {
    myIntProperty().set(myInt);
  }

  public IntegerProperty myIntProperty() {
    return myInt;
  }

  public final ReadOnlyIntegerProperty myReadonlyIntProperty() {
    return this.myReadonlyInt.getReadOnlyProperty();
  }

  public final int getMyReadonlyInt() {
    return this.myReadonlyIntProperty().get();
  }
}

While Eclipse allows you to generate Getters/Setters for the JavaBean pattern would invalid Getters/Setters for a JavaFX Bean and no accessor at all for property itself.

So this makes a good first new feature to be introduced by e(fx)clipse tooling:

A wizard who generates the methods

  • Bring up the context menu on the Editor
    context-menu
  • Select Generate JavaFX Getters and Setters
  • A dialog opens and shows you all JavaFX-Propertiesdialog
  • Select the properties you want to generate the accessors for the “make methods final” is good JavaFX design because subclasses should not be able to overwrite your methods. See for example also JavaFX Tip 4: Have the Final Word hence making them final is the default
  • Simply hit OK and you get the resultfinal-result

For those who prefer to use keyboard short-cuts you can use:

  • CTRL/CMD+3 – To open the Quick Assist
  • Type “Generate JavaFX” and you should already see the command you want to execute and on subsequent Quick-Assist is very likely in the previos choice section
    quick

Give it a try and get Eclipse Luna + e(fx)clipse 1.0.0 nightly build from our update-site or simply download the all-in-one package from http://efxclipse.bestsolution.at/install.html.

This entry was posted in e(fx)clipse and tagged . Bookmark the permalink.