PDA

View Full Version : Drag And Drop in TreePanel



sunnyuser
18 Aug 2010, 4:45 AM
Hi All,

I'm facing one issue at the time of Drag & Drop in TreePanel. I am trying to apply Drag & Drop in the same tree means Drag one TreeNode into another one.When I am dragging any Noe then It's showing 1 Item Selected ToolTip and drag Start print comes into the console but when I drop it then dragDrop ........1111.......... or drap Move prints neither come nor my dragging node moves into another node.

My code is like as :

final TreePanelDragSource source = new TreePanelDragSource(treePanel);
source.addDNDListener(new DNDListener() {
@Override
public void dragStart(DNDEvent e) {
System.out.println("drag start..............");
TreePanel<ModelData> tree = ((TreePanel<ModelData>) e.getComponent());
ModelData modelData = tree.getSelectionModel().getSelectedItem();
if (modelData != null && tree.getStore().getParent(unitToMove) == null) {
e.setCancelled(true);
e.getStatus().setStatus(false);
return;
}
super.dragStart(e);
}

});

new TreePanelDropTarget(treePanel)

{
@Override
protected void onDragMove(DNDEvent event) {
System.out.println("dragMove.................");
super.onDragMove(event);
}

@Override
protected void onDragDrop(DNDEvent event) {
System.out.println("dragDrop ........1111..........[");
super.onDragDrop(event);
}
};


So, please help me ...I am not able to find where is the problem.


Thanks and regards,

SunnyUser

sven
18 Aug 2010, 4:51 AM
I just tested this in an own example with your TreePanelDropTarget overrides and it works without any problems.

Can you please post some fully working testcase that implements EntryPoint and demonstrates exactly what you are doing?

sunnyuser
25 Aug 2010, 1:00 AM
This functionality is working fine at my side also with this code :

TreePanelDragSource source = new TreePanelDragSource(treePanel);
source.addDNDListener(new DNDListener() {
@Override
public void dragStart(DNDEvent e) {
System.out.println("dragStart.................");
super.dragStart(e);
}

@Override
public void dragDrop(final DNDEvent e) {
System.out.println("dragDrop.................");
super.dragDrop(e);
}
});

TreePanelDropTarget target = new TreePanelDropTarget(treePanel) {

@Override
public void onDragMove(final DNDEvent e) {
e.getStatus().setStatus(true);
super.onDragMove(e);
}
};
target.setAllowSelfAsSource(true);
target.setAutoExpand(true);

I think, I forgot to write this line : target.setAllowSelfAsSource(true);


Thanks and regards,

SunnyUser

sven
25 Aug 2010, 1:02 AM
I think, I forgot to write this line

Can you please post a fully working testcase of your problem that implements EntryPOint and has everything needed? It is hard to reproduce a problem id nobody but you know what you are doing exactly.

sunnyuser
25 Aug 2010, 1:11 AM
I have one another problem in TreePanel according to my requirement and I don't know How to resolve this issue.

My Case :

After rendering of TreePanel, I want to insert one TreeNode in the TreePanel and with this selection should come also on New Added TreeNode and I also not able to find any way to track the newly added Node.


My code of addition of TreeNode is like as :

addedUnit = event.getData();
int childCount = store.getChildCount(oldSelectedTreeNode.getModel());
List<ModelData> childList = new ArrayList<ModelData>();
childList.add(addedUnit);
store.insert(oldSelectedTreeNode.getModel(), childList, childCount, false);


I tried to do some code in update method of TreePanel but it is not working :

treePanel = new TreePanel<ModelData>(store) {

@Override
protected void update() {
super.update();
if (addedUnit != null) {
treePanel.getView().onSelectChange(addedUnit, true);
// treePanel.setExpanded(store.getParent(addedUnit), true);
addedUnit = null;
}
}

};

Please help me to resolve this issue.