PDA

View Full Version : ListView disappears when Dnd



Nico33
10 Feb 2010, 7:30 AM
Hi all,

I'm trying to use drag and drop on a ListView to allow reordering.
Here's my code snippet, but when I'm dragging an element, the listview disappears.

Am I missing something ?

Thanks in advance for any help


public class ListViewDnd extends LayoutContainer
{
@Override
protected void onRender(Element parent, int index)
{
super.onRender(parent, index);

Window w = new Window();
w.setPlain(true);
w.setSize(580, 550);
w.setLayout(new FitLayout());

ListStore<Stock> store = new ListStore<Stock>();
store.add(TestData.getCompanies());

ListView<Stock> lv = new ListView<Stock>();
lv.setStore(store);
lv.setSimpleTemplate("{name}");
lv.setBounds(10, 10, 160,60);
lv.setSize(400, 300);
lv.setBorders(true);

addDragDropSupport(lv);

w.add(lv);
w.show();
}

public static void addDragDropSupport(ListView<? extends ModelData> listView)
{
new ListViewDragSource(listView);
ListViewDropTarget target = new ListViewDropTarget(listView);
target.setAllowSelfAsSource(true);
target.setFeedback(Feedback.INSERT);
}
}

Nico33
4 Mar 2010, 11:01 AM
Hi all,

this is the complete test app that reproduces the problem :


public class TestApp implements EntryPoint
{
private ListView<Stock> lv;
private ListViewDropTarget target;

public void onModuleLoad()
{
Viewport viewport = new Viewport();
viewport.setLayout(new AnchorLayout());

LayoutContainer container = new LayoutContainer();

Button button = new Button("Open");
button.setSize(50, 50);
button.addSelectionListener(new SelectionListener<ButtonEvent>()
{
@Override
public void componentSelected(ButtonEvent ce)
{
Window w = new Window();
w.setPlain(true);
w.setSize(580, 550);
w.setLayout(new FitLayout());

ListStore<Stock> store = new ListStore<Stock>();
store.add(TestData.getCompanies());

lv = new ListView<Stock>();
lv.setStore(store);
lv.setSimpleTemplate("{name}");
lv.setBounds(10, 10, 160,60);
lv.setSize(400, 300);
lv.setBorders(true);

new ListViewDragSource(lv);
target = new ListViewDropTarget(lv);
target.setAllowSelfAsSource(true);
target.setFeedback(Feedback.INSERT);

w.add(lv);
w.show();
}
});

container.add(button);
viewport.add(container , new AnchorData("100% 100%", new Margins(10)));
RootPanel.get().add(viewport);
}
}Click on the button, that opens the windows.
Try to do anything on the listview (for example moving the scrollbar or beginning a DnD), the listview disappears.

How can I correct that ?

Thanks in advance for your help.

(note with gxt 2.1.1 it appears only on DnD, not while moving the scrollbar)

Nico33
8 Mar 2010, 3:49 AM
Maybe the listview doesn't work on a window ... :((

Nico33
9 Mar 2010, 9:30 AM
no idea ?

Nico33
11 Mar 2010, 4:41 AM
I'll give up this idea, and will try something without a window ...

sven
11 Mar 2010, 5:31 AM
Remove the call to setBounds. This is unneeded in the place you have it and is making the problem

Nico33
11 Mar 2010, 1:04 PM
Thanks, this is working as usual.

To avoid in the future to annoy you, how did you achieve to know what was wrong in my code ?
I tryed to debug, but can't see what's wrong.
Why did setbounds run this issue and how to prevent it ?

sven
11 Mar 2010, 1:08 PM
setBounds was setting a top and left value. The dragging set position to relative and so it was jumping away.

I simple started the testcode and looked at it with firebug before and after dragging. That was how i found it.