Blog
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. Video 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.