PDA

View Full Version : Store.Add fires for all sub nodes



dhruv.shukla
2 Mar 2011, 9:49 AM
Hello,
Store.Add fires for all sub nodes when a node is drag and drop to other node level for a TreePanel.

Is there any event to fire only once when Add occurs.

Thanks,

Colin Alworth
3 Mar 2011, 2:59 PM
Unless I am misreading, as of GXT 2.2.0, TreePanelDropTarget, the code that handles a drop into a TreePanel, calls either TreeStore.insert(List, int, boolean) or TreeStore.insert(ModelData, List, int, boolean), and in all cases, that last boolean (named addChildren) is false.

Both of those methods make their way into TreeStore.doInsert, a private method, where addChildren is used to determine if the children of the items being appended should be added themselves (as opposed to the List<TreeModel> named children, which would more aptly be named itemsToAppend or newChildren). If addChildren is false, as it is in these cases, the last block of code where the subelements are recursively appended does not happen, so I am unclear as to how your issue is occurring.

Can you provide a simple example of this, or at least a stack trace that demonstrates that doInsert is being called recursively and causing this issue? I suspect that either an event is occurring as a result of items being added, or that the add call is not coming from within TreePanelDropTarget.

dhruv.shukla
3 Mar 2011, 3:40 PM
Colin I see the Tree Panel Drop Target which I have is

final TreePanelDropTarget target = new TreePanelDropTarget(tree) {
@Override
protected void showFeedback(DNDEvent event) {
final TreePanel<ModelData>.TreeNode target = tree.findNode(event.getTarget());
if (target != null) {
// System.out.println("status:" + status + " active for :" + activeItem.toString());
targetData = ()target.getModel();
sourceData = ()selectionModel.getSelectedItem();
if(store.getParent(sourceData)== null && store.getParent(targetData) == null) {
super.showFeedback(event);
return;
} else {
if(store.getParent(sourceData).equals(store.getParent(targetData))) {
super.showFeedback(event);
return;
}
}
}
event.getStatus().setStatus(false);
event.setCancelled(true);
Insert.get().hide();
}
@Override
protected void handleInsert(DNDEvent event, final TreeNode item) {
int height = item.getElement().getOffsetHeight();
int mid = height / 2;
int top = item.getElement().getAbsoluteTop();
mid += top;
int y = event.getClientY();
boolean before = y < mid;

if (!item.isLeaf() || isAllowDropOnLeaf()) {
if ((before && y > top + 4) || (!before && y < top + height - 4)) {
event.getStatus().setStatus(false);
event.setCancelled(true);
return;
}
}
super.handleInsert(event, item);
}
@Override
protected void onDragDrop(DNDEvent event) {
super.onDragDrop(event);
TreeStoreModel record = (TreeStoreModel)((List)event.getData()).get(0);
model = ()record.getModel();
parent = model.getParent();
if(parent != null) {
if(parent.getType() != StepNodeType.Process) {
presenter.updateTreeOrder(store.getChildren(parent)); // Doing this since store doesnt have the parent for Process.
} else {
presenter.updateTreeOrder(store.getRootItems());
}
}
}
};
target.setAllowSelfAsSource(true);
target.setFeedback(Feedback.INSERT);
target.setScrollElementId(navContainer.getId());


store.addListener(Store.Add, new StoreListener<TreeModel>() {
public void storeAdd(StoreEvent<TreeModel> se)
{
TreeStoreEvent<TreeModel> tse = (TreeStoreEvent<TreeModel> ) se;
TreeModel parent = (TreeModel)tse.getParent();
if(parent != null) {
presenter.updateTreeOrder(parent.getAllChildrens());
} else {
presenter.updateTreeOrder(store.getRootItems());
}
}
});


Unless I am misreading, as of GXT 2.2.0, TreePanelDropTarget, the code that handles a drop into a TreePanel, calls either TreeStore.insert(List, int, boolean) or TreeStore.insert(ModelData, List, int, boolean), and in all cases, that last boolean (named addChildren) is false.

Both of those methods make their way into TreeStore.doInsert, a private method, where addChildren is used to determine if the children of the items being appended should be added themselves (as opposed to the List<TreeModel> named children, which would more aptly be named itemsToAppend or newChildren). If addChildren is false, as it is in these cases, the last block of code where the subelements are recursively appended does not happen, so I am unclear as to how your issue is occurring.

Can you provide a simple example of this, or at least a stack trace that demonstrates that doInsert is being called recursively and causing this issue? I suspect that either an event is occurring as a result of items being added, or that the add call is not coming from within TreePanelDropTarget.

dhruv.shukla
3 Mar 2011, 3:56 PM
Daemon Thread [Code server for CmSteps from Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13 on http://localhost/gwt/CmSteps/hosted.html?CmSteps @ 7?GP5dg/sCivwuvm] (Suspended (breakpoint at line 167 in TreePanelDropTarget))
StepsNavViewImpl$14(TreePanelDropTarget).appendModel(ModelData, List<ModelData>, int) line: 167
StepsNavViewImpl$14(TreePanelDropTarget).appendModel(ModelData, List<ModelData>, int) line: 172
StepsNavViewImpl$14(TreePanelDropTarget).handleInsertDrop(DNDEvent, TreePanel$TreeNode, int) line: 301
StepsNavViewImpl$14(TreePanelDropTarget).onDragDrop(DNDEvent) line: 320
StepsNavViewImpl$14.onDragDrop(DNDEvent) line: 417
StepsNavViewImpl$14(DropTarget).handleDrop(DNDEvent) line: 410
DNDManager.handleDragEnd(DragSource, DNDEvent) line: 122
TreePanelDragSource(DragSource).onDraggableDragEnd(DragEvent) line: 291
DragSource.access$1(DragSource, DragEvent) line: 284
DragSource$1.dragEnd(DragEvent) line: 99
DragSource$1(DragListener).handleEvent(DragEvent) line: 66
DragSource$1(DragListener).handleEvent(BaseEvent) line: 1
Draggable(BaseObservable).callListener(Listener<BaseEvent>, BaseEvent) line: 178
Draggable(BaseObservable).fireEvent(EventType, BaseEvent) line: 86
Draggable.stopDrag(Event) line: 695
Draggable$2.onPreview(PreviewEvent) line: 149
Draggable$2(BaseEventPreview).onPreviewNativeEvent(Event$NativePreviewEvent) line: 145
Event$NativePreviewEvent.dispatch(Event$NativePreviewHandler) line: 195
Event$NativePreviewEvent.dispatch(EventHandler) line: 1
HandlerManager$HandlerRegistry.fireEvent(GwtEvent<H>, boolean) line: 60
HandlerManager$HandlerRegistry.access$1(HandlerManager$HandlerRegistry, GwtEvent, boolean) line: 53
HandlerManager.fireEvent(GwtEvent<?>) line: 178
Event$NativePreviewEvent.fire(HandlerManager, NativeEvent) line: 87
Event$NativePreviewEvent.access$4(HandlerManager, NativeEvent) line: 73
Event$.fireNativePreviewEvent(NativeEvent) line: 444
DOM.previewEvent(Event) line: 1284
GeneratedMethodAccessor69.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 597
MethodAdaptor.invoke(Object, Object...) line: 103
MethodDispatch.invoke(JsValue, JsValue[], JsValue) line: 71
OophmSessionHandler.invoke(BrowserChannel, BrowserChannel$Value, int, BrowserChannel$Value[]) line: 157
BrowserChannelServer(BrowserChannel).reactToMessagesWhileWaitingForReturn(BrowserChannel$SessionHandler) line: 1714
BrowserChannelServer.invokeJavascript(CompilingClassLoader, JsValueOOPHM, String, JsValueOOPHM[], JsValueOOPHM) line: 165
ModuleSpaceOOPHM.doInvoke(String, Object, Class<?>[], Object[]) line: 120
ModuleSpaceOOPHM(ModuleSpace).invokeNative(String, Object, Class<?>[], Object[]) line: 507
ModuleSpaceOOPHM(ModuleSpace).invokeNativeObject(String, Object, Class<?>[], Object[]) line: 264
JavaScriptHost.invokeNativeObject(String, Object, Class<?>[], Object[]) line: 91
Impl.apply(Object, Object, Object) line: not available
Impl.entry0(Object, Object, Object) line: 188
GeneratedMethodAccessor60.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 597
MethodAdaptor.invoke(Object, Object...) line: 103
MethodDispatch.invoke(JsValue, JsValue[], JsValue) line: 71
OophmSessionHandler.invoke(BrowserChannel, BrowserChannel$Value, int, BrowserChannel$Value[]) line: 157
BrowserChannelServer(BrowserChannel).reactToMessagesWhileWaitingForReturn(BrowserChannel$SessionHandler) line: 1714
BrowserChannelServer.invokeJavascript(CompilingClassLoader, JsValueOOPHM, String, JsValueOOPHM[], JsValueOOPHM) line: 165
ModuleSpaceOOPHM.doInvoke(String, Object, Class<?>[], Object[]) line: 120
ModuleSpaceOOPHM(ModuleSpace).invokeNative(String, Object, Class<?>[], Object[]) line: 507
ModuleSpaceOOPHM(ModuleSpace).invokeNativeObject(String, Object, Class<?>[], Object[]) line: 264
JavaScriptHost.invokeNativeObject(String, Object, Class<?>[], Object[]) line: 91
Impl.apply(Object, Object, Object) line: not available
Impl.entry0(Object, Object, Object) line: 188
GeneratedMethodAccessor60.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
Method.invoke(Object, Object...) line: 597
MethodAdaptor.invoke(Object, Object...) line: 103
MethodDispatch.invoke(JsValue, JsValue[], JsValue) line: 71
OophmSessionHandler.invoke(BrowserChannel, BrowserChannel$Value, int, BrowserChannel$Value[]) line: 157
BrowserChannelServer(BrowserChannel).reactToMessages(BrowserChannel$SessionHandler) line: 1669
BrowserChannelServer.processConnection() line: 401
BrowserChannelServer.run() line: 222
Thread.run() line: 619