PDA

View Full Version : EditorTreeGrid and store update



ushref
11 Jan 2011, 7:28 AM
Hello every body,
I was looking for a solution to my problem in this forum. But all what i have found was not suitable for my case.
First of all, i would like to share with you my case:
I have an EditorTreeGrid that will have as a BaseTreeModel as its ModelData.
Modifications for all nodes are updated and works very well when a retreive the TreeStore to commit modifications to the server.
This tree should initially be loaded via a rpc service, in the client side I would be able to manage the addition of new nodes, remove of others and the repositioning by D&D.
When submiting data to the server, using RPC service, changes submited to the server are those which affect the initial TreeStore nodes. Added or removed Nodes are not subbitted to the server.
I used a ToolBar that have two buttons( Add, remove) and a button (Save to database).
Modifications of nodes attributes are done by the use of a FormPanel (with a FormBindings instance).

Here is the Code used to instanciate the EditorTreeGrid:
( I have the gxt 2.2.1 for Gwt 2).
the variable "model" is the BaseTreeModel returned by the RPC service





final TreeStore<ModelData> store = new TreeStore<ModelData>();
store.add(model.getChildren(), true);

ColumnConfig name = new ColumnConfig("name", "Name", 400);

name.setRenderer(new TreeGridCellRenderer<ModelData>());

TextField<String> text = new TextField<String>();
text.setAllowBlank(false);

name.setEditor(new CellEditor(text));
name.setSortable(false);

ColumnConfig value = new ColumnConfig("value", "Value", 400);
value.setEditor(new CellEditor(new TextField<String>()));
value.setSortable(false);

ColumnModel cm = new ColumnModel(Arrays.asList(name, value));

final EditorTreeGrid<ModelData> tree = new EditorTreeGrid<ModelData>(
store, cm);

tree.setClicksToEdit(ClicksToEdit.TWO);
tree.setBorders(true);
tree.getStyle().setLeafIcon(Resources.ICONS.leaf_Item());
tree.setAutoExpandColumn("name");
tree.setTrackMouseOver(true);
tree.setAutoHeight(true);
tree.setAutoWidth(true);
tree.setExpanded(tree.getTreeStore().getChild(0), true);
tree.getStore().setMonitorChanges(true);

For adding node, i used :



folder = tree.getSelectionModel().getSelectedItem();
if (folder != null) {
BaseTreeModel child = new BaseTreeModel("New Node");
store.add(folder, child, false);
store.update(folder);
store.commitChanges();
tree.setExpanded(folder, true);
}

Then i have used the tree.getTreeStore(), tree.getStore(). With these two methods, I can't have all modifications :s (added or removed tree nodes ). What i have to send to my RPC service, is only the Root element of the store with all updates.

Can you tell me please, what have I to do in order to get all modifications of the store?? :-/
There is any solution for this problem? or have i to use a binding between the store and the EditorTreeGrid??

ushref
11 Jan 2011, 7:48 AM
PS: The new node (child) is a ModelData extending the BaseTreeModel.

Ersmarker
19 Jan 2011, 1:49 PM
Hi.

store.commitChanges() only handles changed records, not Add or Remove to the store.
You need to monitor that through a StoreListener.