This utility makes any given element draggable and provides an interface for interacting with the drag-and-drop process.
Example usage:
Draggable< MyElement> draggable = Draggable.of(myElementInstance); draggable.detach(); // To stop the element from being draggable
E
the type of the draggable element which should implement IsElement
This class maintains a map of draggable elements and offers methods to dynamically manage which elements are draggable at a given time. Example usage:
DragSource source = new DragSource(); Draggable< MyElement> draggable = Draggable.of(myElementInstance); source.addDraggable(draggable); source.removeDraggable(draggable.getId());
The DropZone class allows the easy addition and removal of drop targets. It provides functionality to manage the dropping of dragged elements on registered targets. Example usage:
DropZone zone = new DropZone();
zone.addDropTarget(myHtmlElement, draggableId -> DomGlobal.console.info("Dropped: " + draggableId));
public static Draggable<E> of(E element)
element
the element to be made draggable
E
the type of the element
a new Draggable instance
public static Draggable<E> of(E element, Consumer<E> dragStartListener)
element
the element to be made draggable
dragStartListener
listener for the drag start event
E
the type of the element
a new Draggable instance
public static Draggable<E> of(String id, E element)
id
unique identifier for the draggable element
element
the element to be made draggable
E
the type of the element
a new Draggable instance
public static Draggable<E> of(String id, E element, Consumer<E> dragStartListener)
id
unique identifier for the draggable element
element
the element to be made draggable
dragStartListener
listener for the drag start event
E
the type of the element
a new Draggable instance
public DraggableConfig getConfig()
Draggble item DraggableConfig
public void setConfig(DraggableConfig config)
config
DraggableConfig
public void detach()
public String getId()
the unique identifier
public void addDraggable(Draggable<?> draggable)
draggable
the draggable element to be added
public void removeDraggable(String id)
If an element with the provided ID is found, it is first detached (made non-draggable) and then removed from the manager.
id
the unique identifier of the draggable element to be removed
public void addDropTarget(HTMLElement element, DropListener dropListener)
element
the HTML element to register as a drop target
dropListener
the listener that will be invoked upon a drop event
public void addDropTarget(IsElement<? extends HTMLElement> element, DropListener dropListener)
element
the IsElement to register as a drop target
dropListener
the listener that will be invoked upon a drop event
public void removeDropTarget(HTMLElement element)
element
the HTML element to unregister as a drop target
public void removeDropTarget(IsElement<? extends HTMLElement> element)
element
the IsElement to unregister as a drop target