Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
JFace Data Binding/Snippets
|JFace Data Binding|
|How to Contribute|
Snippets show how common use cases can be implemented using the JFace Data Binding framework. They are typically a single self-contained Java class with a main method. See the bottom of this page for additional instructions on how to get and run the snippets.
Running the Snippets
- Create an Eclipse plug-in project and in the Manifest editor go to the Dependencies tab
- Add dependencies to the following bundles: org.eclipse.core.databinding, org.eclipse.core.databinding.beans, org.eclipse.core.databinding.property, org.eclipse.jface.databinding, org.eclipse.swt, and org.eclipse.core.runtime
- Click on any snippet in this list
- Copy (CTRL+C) the source to your clipboard
- Go to the src folder of your project and paste (CTRL+V). This will automatically create the correct package and source file.
- Right click on the new source file and select "Run as / Java Application"
- Hello World - the most basic of bindings
- Wizard Dialog - Shows how to use data binding in a wizard dialog so that validation results are displayed in the dialog's title area
- Spreadsheet - fills a Table updating cells upon change
- Name Formatter - observable value that updates when the first or last name changes
- Master detail - display the detail of the selection of a ListViewer in a Text widget
- Nested Selection With ComboViewer
- Model to TableViewer binding - basic binding to a TableViewer
- TableViewer binding with colors - label provider that provides Colors and auto updates the viewer
- TableViewer inline editing - TableViewer editing with the Eclipse 3.3 JFace viewer APIs. (requires Eclipse 3.3)
- ComputedList and Combo - Filter the elements in one viewer based on the selection in another
- ComboViewer and Java enum - Demonstrates binding the list of a ComboViewer to the values of an enum and the selected value to a simple model property.
Additional Run Options
A great way to learn is to look at concrete examples that you can run and experiment with.
You can clone the eclipse.platform.ui git repository which contains the "org.eclipse.jface.examples.databinding" project with the JFace Databinding examples. For cloning a git repository you can use the EGit tooling of Eclipse.
Use the following URL to clone the repository via File -> Import -> Git repository
After you cloned the project the clone wizard will allow you to import the included projects. For the databinding examples you only have to import the "org.eclipse.jface.examples.databinding" project. For an introduction into EGit please see EGit
Most of the examples provide a main method, you can run it as a Java Application to see what happens.
You can also copy any of the snippets (see below) into a scratch project within Eclipse. If you are copying single snippets into a scratch project, make sure that it is set up with the correct dependencies. You will need org.eclipse.core.databinding, org.eclipse.core.databinding.beans, and org.eclipse.jface.databinding.