Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipse-dev] [DataBinding] DOM and Rhino JFace Databinding implementation.

Hi,

I'm TK-UI developer. TK-UI is Toolkit to describe your UI with any XML markup (XUL, XHTML...)
and render it with Swing or SWT. I'm using JFace databinding to bind DOM Document (Element, Attr, Text...)
with UI widget. So when you update UI it update DOM, whoen you update DOM, the UI is updated.

For instance you can write this XHTML content :

<html xmlns="http://www.w3.org/1999/xhtml">
     <input type="text" value="bla bla bla" />
</html>

And TK-UI load DOM Document and display SWT Text with "bla bla bla".
When you type some data into input (SWT Text), it update attribute value of the DOM.
So DOM Document are totally bounded with UI.

To manage DOM binding I have created DOMObservables (like BeansObservales, PojoObservables...)
and you use this factory like another JFace databinding implementation. This project is stored into
UFace project.

But I would like know if JFace team is interested with my DOM JFace Databinding implementation?
Indead I would like to improve this project to manage a lot of thing like masterdetail.

Here simple sample with masterdetail which manage three SWT List which display countries, cities and streets.
Each SWT List are bounded with this DOM Document :

<countries>
    <country name="Country 1" >
        <cities>
            <city name="City 1.1" >
                <street name="Street 1.1.1" />
            </city>
            <city name="City 1.2" >
                <street name="Street 1.2.1" />
                <street name="Street 1.2.2" />
                <street name="Street 1.2.3" />
            </city>
            <city name="City 1.3" >
                <street name="Street 1.3.1" />
                <street name="Street 1.3.2" />
            </city>
        </cities>
    </country>
    <country name="Country 2" >
        <cities>
            <city name="City 2.1" >
                <street name="Street 2.1.1" />
                <street name="Street 2.1.2" />
            </city>
            <city name="City 2.2" >
                <street name="Street 2.2.1" />
                <street name="Street 2.2.2" />
                <street name="Street 2.2.3" />
            </city>
        </cities>
    </country>
</countries>

The first SWT list display countries (Country 1 and Country 2 ).
When you select a country the second SWT List display cities (ex : you select
Country 1, SWT List cities display City 1.1, City 1.2, City 1.3).

Here the Java code for this sample :

Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
FillLayout layout = new FillLayout();
shell.setLayout(layout);

Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FillLayout());

DocumentBuilderFactory factory = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();
DocumentBuilder builder = factory.newDocumentBuilder();
Document countriesDOM = builder.parse(DOMComboViewerMasterDetail.class
        .getResourceAsStream("countries.xml"));

final Realm realm = SWTObservables.getRealm(display);

// Country
org.eclipse.swt.widgets.List countryList = new org.eclipse.swt.widgets.List(
        composite, SWT.BORDER | SWT.V_SCROLL);
ListViewer countryViewer = new ListViewer(countryList);
ObservableListContentProvider countryViewerContent = new ObservableListContentProvider();
countryViewer.setContentProvider(countryViewerContent);

countryViewer.setLabelProvider(new LabelProvider() {
    public String getText(Object element) {
        Element elt = (Element) element;
        return elt.getAttribute("name");
    }
});

IObservableList countries = DOMObservables.observeElementItems(realm,
        countriesDOM.getDocumentElement(), "country", null, null);
countryViewer.setInput(countries);

// City
IObservableValue selectedCountry = ViewersObservables
        .observeSingleSelection(countryViewer);

org.eclipse.swt.widgets.List cityList = new org.eclipse.swt.widgets.List(
        composite, SWT.BORDER | SWT.V_SCROLL);
ListViewer cityViewer = new ListViewer(cityList);
ObservableListContentProvider cityViewerContent = new ObservableListContentProvider();
cityViewer.setContentProvider(cityViewerContent);

cityViewer.setLabelProvider(new LabelProvider() {
    public String getText(Object element) {
        Element elt = (Element) element;
        return elt.getAttribute("name");
    }
});

IObservableList cities = DOMObservables.observeDetailList(realm,
        selectedCountry, "city");
cityViewer.setInput(cities);

// Street
IObservableValue selectedCity = ViewersObservables
        .observeSingleSelection(cityViewer);

org.eclipse.swt.widgets.List streetList = new org.eclipse.swt.widgets.List(
        composite, SWT.BORDER | SWT.V_SCROLL);
ListViewer streetViewer = new ListViewer(streetList);
ObservableListContentProvider streetViewerContent = new ObservableListContentProvider();
streetViewer.setContentProvider(streetViewerContent);

streetViewer.setLabelProvider(new LabelProvider() {
    public String getText(Object element) {
        Element elt = (Element) element;
        return elt.getAttribute("name");
    }
});

IObservableList streets = DOMObservables.observeDetailList(realm,
        selectedCity, "street");
streetViewer.setInput(streets);

shell.pack();
shell.open();

while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
        display.sleep();
}

shell.dispose();

If you are interested with my work, don't hesitate to contact me, I will happy
to contribute to JFace Databinding project.

At end I have too start Rhino JFace Databinding to bind Scriptable _javascript_ Object with another thing (DOM, SWT UI....)
I could tell you more if you are interested.

Regards Angelo

Back to the top