fredsa / gwt-dnd

Library providing easy to use mouse or touch based drag-and-drop capabilities to GWT
44 stars 40 forks source link

MouseDragHandler.makeNotDraggable() is too strict #158

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Example code:

AbsolutePanel boundaryPanel = new AbsolutePanel();
PickupDragController dragController = new PickupDragController(boundaryPanel, 
true);
Label dragHandle = new Label();
dragController.makeNotDraggable(dragHandle);

In the above example, makeNotDraggable() throws a RuntimeException since the 
dragHandle was not draggable. I think it should just ignore it silently, 
because otherwise the developer needs to keep track of draggable state.

My use case:

I have a vertical list of widgets that the user can modify (add/remove) and 
reorder via drag handles. If there is only one widget present, I don't want the 
user to be able to "reorder" it, so I make it not draggable. Something like 
this:

public MyWidget extends Widget implements HasDragHandle{

  ...

  public void setDraggable(boolean draggable){
    if(draggable){
      dragController.makeDraggable(this);
    }else{
      dragController.makeNotDraggable(this);
    }
  }
}

boolean draggable = widgets.size() > 1;
for(MyWidget w : widgets){
  w.setDraggable(draggable);
}

The above throws the exception, so what I have to do is add a 'draggable' 
boolean to MyWidget to keep track of its draggable state, and not call 
makeNotDraggable() if it's already not draggable.

I think the gwt-dnd API should either (a) silently ignore non-draggable 
handles, or (b) provide a DragController.isDraggable(Widget w) method so that 
developers don't have to do their own state tracking.

(Obligatory Disclaimer: If there is a better way to do what I'm trying to do 
I'm all ears, of course :))

Original issue reported on code.google.com by zakness@gmail.com on 6 Mar 2012 at 6:23

GoogleCodeExporter commented 9 years ago
Thought of another workaround, and that's to wrap makeNotDraggable() in 
try/catch. But that's kinda ugly...

Original comment by zakness@gmail.com on 6 Mar 2012 at 6:25

GoogleCodeExporter commented 9 years ago
Having makeNotDraggable be strict helps ensure that application code is correct.

If you prefer to call makeNotDraggable with objects which were not first made 
draggable, please either wrap the calls to makeDraggable/makeNotDraggable and 
do your own bookkeeping, or use try/catch as you suggested

Original comment by fredsa@google.com on 28 Mar 2013 at 10:01