我在Vaadin7中遇到了问题。
我想在任务和列表之间创建拖放(任务可拖动,列表可丢弃)。
我的代码正在运行,但任务总是放在列表的最底部。
这是我的代码(drop handler):
@Override
public AcceptCriterion getAcceptCriterion() {
return AcceptAll.get();
}
@Override
public void drop(DragAndDropEvent event) {
DragAndDropWrapper dd = (DragAndDropWrapper)event.getTransferable().getSourceComponent();
Task t= (Task) dd.getData();
DragAndDropWrapper dd2 = (DragAndDropWrapper)event.getTargetDetails().getTarget();
List targetList = (List)dd2.getData();
String currentDraggedTaskId = t.getTask_id();
final int targetListId = Integer.parseInt( targetList.getId_list() );
try {
taskService.moveTask(currentDraggedTaskId, targetListId);
List targetListObj = (List)CollectionUtils.find(allLists, new Predicate() {
@Override
public boolean evaluate(Object object) {
List l = (List)(object);
return l.getId_list().equals(targetListId+"");
}
});
List oldList = (List)t.getParent().getParent();
oldList.removeComponent(t.getParent());
targetListObj.addComponent(t.getParent());
} catch (UnsupportedOperationException | SQLException e) {
Notification.show("err");
}
}
我知道我已将任务添加到布局的末尾,但我怎么知道列表中的任务已被删除?
如果有人能帮助我,我将非常感激:)
祝你好运, 太
答案 0 :(得分:0)
有关丢弃位置的更多/不同信息,具体取决于接收丢弃的组件类型。这是来自Vaadin书(见here):
TargetDetails对象提供有关确切位置的信息 可转移对象被丢弃的地方。确切的类 详细信息对象取决于放置目标,您需要将其转换为 正确的子类,以获取更详细的信息。 如果目标是 选择组件,基本上是树或表, AbstractSelectTargetDetails对象告诉drop是哪个项目 正在制作。对于树,TreeTargetDetails提供了更多细节。 对于包装组件,信息以a形式提供 WrapperDropDetails对象。除了目标项目或 组件,详细信息对象提供放置位置。供选择 组件,可以使用getDropLocation()获取位置 对于使用verticalDropLocation()和的包装组件 horizontalDropLocation()。位置指定为 VerticalDropLocation或HorizontalDropLocation对象。下降 location对象指定是否删除transferable 在组件或项目的上方,下方或直接(位于中间)。
因此,使用Table而不是List可能是一种解决方案。