EMF-Edit-Support is coming to JavaFX via e(fx)clipse


One of the brand new runtime features we will provide with the next release of e(fx)clipse is EMF-Edit-Support for JavaFX so that people who use EMF as their domain technology don’t have to write code by hand when they want to set up List, Tables and Trees in a JavaFX application.

An important side note in is that it is not BestSolution.at who has developed this feature but it has been contributed and is maintained by one of our early adopters (TESIS DYNAware).

As a start let’s take a look how you can set up a ListView:

EditingDomain editingDomain = ....;
AdapterFactory adapterFactory = ....;
Group rootNode = ....;

ListView<Object> listView = new ListView<>();
listView.setItems(new AdapterFactoryObservableList<Object>(adapterFactory, rootNode));

AdapterFactoryListCellFactory listCellFactory;
listCellFactory = new AdapterFactoryListCellFactory(adapterFactory);
listView.setCellFactory(listCellFactory);

Nice isn’t it? Let’s take a look at a more complex control:

Group rootNode = ....;
EditingDomain editingDomain = ....;
AdapterFactory adapterFactory = ....;

TreeView<Object> treeView = new TreeView<>();
treeView.setRoot(new AdapterFactoryTreeItem(rootNode, adapterFactory));
AdapterFactoryTreeCellFactory cellFact;
cellFact = new AdapterFactoryTreeCellFactory(adapterFactory);

treeView.setCellFactory(cellFact);

Let’s add some DND support

cellFact.addCellCreationListener(new CellDragAdapter());
cellFact.addCellCreationListener(new EditingDomainCellDropAdapter(editingDomain));

And finally a nice little table:

Group rootNode = ....;
EditingDomain editingDomain = ....;
AdapterFactory adapterFactory = ....;

TableView<Object> tableView = new TableView<>();

TableColumn<Object, Object> firstNameColumn = new TableColumn<>("First Name");
firstNameColumn.setCellValueFactory(new ProxyCellValueFactory<Object, Object>());

AdapterFactoryTableCellFactory<Object, Object> firstNameCellFactory = 
   new AdapterFactoryTableCellFactory<>(adapterFactory, 0);
firstNameColumn.setCellFactory(firstNameCellFactory);

Now add some inline editing support:

tableView.setEditable(true);
firstNameCellFactory.addCellEditHandler(new EAttributeCellEditHandler(
  ContactsPackage.eINSTANCE.getContact_FirstName(),
  editingDomain));

That’s it for structured controls like List, Table and Tree but often you also need to bind an EMF-Feature e.g. to a TextField and this can be done like this:

Contact contact = ...;
EditingDomain editingDomain = ....;
EStructuralFeature feature = ContactsPackage.eINSTANCE.getContact_FirstName();

Property<String> property = EMFEditFXProperties.value(editingDomain, contact, feature);
textField.textProperty().bindBidirectional(property);

If you want to see this in action I’ve recorded a small video for you.

You noticed that we have full undo/redo support available but for those of you who have used EMF-Edit that is not a suprise. As always you can find the sample code in our github repo.

About these ads

6 Responses to “EMF-Edit-Support is coming to JavaFX via e(fx)clipse”

  1. Cool. Took me a while to understand why you’re doing all this stuff, unitl I tried JavaFX myself. EMFEdit finally gets the usability it deserves with your JavaFX approach (as opposed to SWT, RAP or GWT). Carry on the excellent work!

  2. I can’t wait for the next release of e(fx)clipse. I’m working with EMF, and get JavaFX compatibility can be fantastic. Good work Tom!

  3. Mauro Condarelli Reply May 4, 2013 at 2:50 pm

    Hi Tom,
    thanks a lot for the good work!
    I am struggling because I need (not my choice) to integrate an EMF model in a standalone JavaFX application (NO e4, RCP, …, just a plain “public class Main extends Application”).
    Possibly using databinding.
    Is this possible at all?
    What is the minimal set of .jar necessary?
    Is there any example/documentation/tutorial available?
    I’m currently very perplexed about how to write the AdapterFactory apparently needed.
    Any pointer welcome.
    TiA
    Mauro

Trackbacks/Pingbacks

  1. e(fx)clipse 0.8.0 released | Tomsondev Blog - January 6, 2013

    [...] Another employee from TESIS DYNAWare – Torsten Sommer – worked on an integration of JavaFX and EMF-Edit. You can now setup FX List, Tables and Trees from the generated EMF-Edit classes makeing is super easy to implement UIs using EMF-Frameworks like e.g. CDO or Teneo. I’ve already blogged about this some time ago here. [...]

  2. GUI Generation with JavaFX | Uwe's Blog - July 12, 2013

    […] http://tomsondev.bestsolution.at/2012/12/13/emf-edit-support-is-coming-to-javafx-via-efxclipse/ […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 600 other followers

%d bloggers like this: