PDA

View Full Version : [1.2.3] and [2.0 M1] Binding bug in Draggable Tree



monzonj
21 Apr 2009, 6:40 AM
Hi!
- Take a draggable tree that is binded to a form.
- Click in any node and try to edit it.
- After editing, click in another tree node.
- You will see how your changes are lost and not transferred to the tree model.

This happens in any browser different to IE (this means with IE works fine, but FF, SAFARI, etc don't)

If the tree is not draggable, it works fine. I think it has to do with the DragListener that somehow "swallow" the click event and doesn't let the binder to update the model. But it's funny that it works in IE.

Please, notice that if, instead of clicking in another node, I click somewhere else then the tree is updated successfully.

Here is a complete example. Copy-paste and test it yourself:


public class TreeBindingExample extends LayoutContainer {

private FormBinding formBindings;

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setStyleAttribute("margin", "10px");

ContentPanel cp = new ContentPanel();

cp.setHeading("Tree Bindings");
cp.setFrame(true);
cp.setSize(800, 400);
cp.setLayout(new RowLayout(Orientation.HORIZONTAL));

Tree tree = createTree();
tree.addListener(Events.SelectionChange, new Listener<TreeEvent>() {
public void handleEvent(final TreeEvent be) {
if (be.selected.size() > 0) {
formBindings.bind(be.selected.get(0).getModel());
} else {
formBindings.unbind();
}
}
});

LayoutContainer container = new LayoutContainer();
container.setBorders(true);
container.setScrollMode(Scroll.AUTO);
container.add(tree);
cp.add(container, new RowData(.6, 1));

FormPanel panel = createForm();
formBindings = new FormBinding(panel, true);

cp.add(panel, new RowData(.4, 1));

add(cp);
}

private FormPanel createForm() {
FormPanel panel = new FormPanel();
panel.setHeaderVisible(false);

TextField<String> name = new TextField<String>();
name.setName("name");
name.setFieldLabel("Name");
panel.add(name);

return panel;
}

private Tree createTree() {
TreeStore<Stock> store = new TreeStore<Stock>();
store.setMonitorChanges(true);
store.add(TestData.getStocks(), true);

final Tree tree = new Tree();
tree.getStyle().setLeafIconStyle("icon-music");

TreeBinder<TreeModel> binder = new TreeBinder<TreeModel>(tree, store);
binder.setMask(false);
binder.setDisplayProperty("name");
binder.setAutoLoad(true);
binder.init();


/*** THIS IS THE D&D PART. REMOVE IT, AND THE BINDING WORKS FINE. ****/
TreeDragSource source = new TreeDragSource(binder);
TreeDropTarget target = new TreeDropTarget(binder);
target.setAllowSelfAsSource(true);
target.setFeedback(Feedback.BOTH);
target.setAutoExpand(true);
/*** ITHIS IS THE D&D PART. REMOVE IT, AND THE BINDING WORKS FINE. ****/


return tree;
}

}Some utility classes needed by the example:


public class Stock extends BaseTreeModel {
public Stock() {
}

public Stock(String name) {
set("name", name);
}

public String getName() {
return (String) get("name");
}

public String toString() {
return getName();
}
}
public class TestData {
public static List<Stock> getStocks() {
List<Stock> stocks = new ArrayList<Stock>();
stocks.add(new Stock("Apple Inc."));
stocks.add(new Stock("Cisco Systems, Inc."));
stocks.add(new Stock("Google Inc."));
stocks.add(new Stock("Intel Corporation"));
stocks.add(new Stock("Level 3 Communications, Inc."));
stocks.add(new Stock("Microsoft Corporation"));
stocks.add(new Stock("Nokia Corporation (ADR)"));
return stocks;
}
}