2012-10-26 2 views
0

J'ai créé un simple éditeur DragNDrop pour modifier un arbre à persister dans ma base de données. (L'utilisation de GXT 2.2.5 ne peut pas être mise à niveau)L'activité DragStrop de TreeStore n'est pas reflétée dans TreeStore

J'ai un TreePanel construit avec un TreeStore. TreePanel est à la fois un TreePanelDragSource et TreePanelDropTarget.

Le glisser/déposer fonctionne correctement; En tant que test, j'ai utilisé le TreeStore à partir d'une fenêtre de dialogue ouverte existante. En faisant glisser/déposer dans l'éditeur, l'autre fenêtre affiche immédiatement les modifications de l'arborescence. Cependant, lorsque je récupère le TreeStore pour l'enregistrer, les nœuds ne sont pas réorganisés dans le Store. Comment obtenir la structure arborescente réorganisée?

TIA

Répondre

0

Ma solution

Apparently there is no way to directly get at the Tree structure altered by Drag and Drop. 
I reasoned that TreePanelView = TreePanel.getView() might have the Drag and Drop chaanges. 
By examining TreePanelView in the debugger after a drag and drop I devise this solution: 
/* 
* These 'My' classes are used to access the internal tree within TreePanelView. 
* The internal tree reflects Drag and Drop activity, 
* which is NOT reflected in the TreeStore. 
*/ 
private class MyTreePanel<M extends ModelData> extends TreePanel<M> { 
    public MyTreePanel(TreeStore<M> ts) { 
     super(ts); 
     view = new MyView<M>(); 
     view.bind(this, store); 
    } 
    public MyView<M> getMyView() { 
     return (MyView<M>) getView(); 
    } 
} 
private class MyView<M extends ModelData> extends TreePanelView<M> { 
    public MyTreeStore<M> getTreeStore() { 
     return (MyTreeStore<M>) this.treeStore; 
    } 
} 
private class MyTreeStore<M extends ModelData> extends TreeStore<M> { 
    public MyTreeStore() { 
     super(); 
    } 
    public Map<M, TreeModel> getModelMap() { 
     return modelMap; 
    } 
} 
To extract the tree altered by Drag and Drop: 
MyTreePanel<ModelData> myTree; //Initialize the TreeStore appropriately 

// After Drag and Drop activity, get the altered tree thusly: 
Map<ModelData, TreeModel> viewMap = myTree.getMyView().getTreeStore().getModelMap(); 

The TreeModel in viewMap is actually a BaseTreeModel. 
The ModelData are the objects I originally loaded into TreeStore. 
I had to: 
1 - Iterate over viewMap, extract "id" from BaseTreeModel and create a reverse map, 
    indexed by "id" and containing my ModelData objects. 
2 - Fetch root BaseTreeModel node from viewMap using root ModelData of original tree. 
3 - Walk the BaseTreeModel tree. 
    At each node, fetched ModelData objects by "id" from the reverse map. 

In this way I reconstructed the tree altered by Drag and Drop. 
Questions connexes