Package org.opencms.gwt.client.dnd
Class CmsDNDHandler
- java.lang.Object
-
- org.opencms.gwt.client.dnd.CmsDNDHandler
-
- All Implemented Interfaces:
com.google.gwt.event.dom.client.MouseDownHandler
,com.google.gwt.event.shared.EventHandler
public class CmsDNDHandler extends java.lang.Object implements com.google.gwt.event.dom.client.MouseDownHandler
Drag and drop handler.- Since:
- 8.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsDNDHandler.AnimationType
The animation types.protected class
CmsDNDHandler.CmsScrollTimer
Timer to schedule automated scrolling.protected static class
CmsDNDHandler.Direction
Scroll direction enumeration.protected class
CmsDNDHandler.DNDEventPreviewHandler
Drag and drop event preview handler.static class
CmsDNDHandler.Orientation
The allowed drag and drop orientation.
-
Constructor Summary
Constructors Constructor Description CmsDNDHandler(I_CmsDNDController controller)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTarget(I_CmsDropTarget target)
Adds a drop target.protected void
animateCancel(I_CmsDraggable draggable, I_CmsDNDController controller)
Clears the drag process with a move animation of the drag element to it's original position.protected void
animateDrop(I_CmsDraggable draggable, I_CmsDropTarget target, I_CmsDNDController controller)
Clears the drag process with a move animation of the drag element to the place-holder position.void
cancel()
Cancels the dragging process.protected void
clear()
Clears all references used within the current drag process.protected void
clearScrollTimer()
Cancels the scroll timer and removes the timer reference.void
clearTargets()
Clears the drop target register.void
drop()
Drops the draggable.I_CmsDNDController
getController()
Returns the drag and drop controller.I_CmsDropTarget
getCurrentTarget()
Returns the current drop target.int
getCursorOffsetX()
Returns the cursor offset x.int
getCursorOffsetY()
Returns the cursor offset y.I_CmsDraggable
getDraggable()
Returns the current draggable.com.google.gwt.dom.client.Element
getDragHelper()
Returns the drag helper element.CmsDNDHandler.Orientation
getOrientation()
Returns the allowed drag and drop orientation.com.google.gwt.dom.client.Element
getPlaceholder()
Returns the place holder element.boolean
hasModifierCTRL()
Returns whether the CTRL key was pressed when drag started.boolean
isAnimationEnabled()
Returns if the animation is enabled.boolean
isDragging()
Returns if a dragging process is taking place.boolean
isScrollEnabled()
Returns if automated scrolling is enabled.void
onMouseDown(com.google.gwt.event.dom.client.MouseDownEvent event)
protected void
onMouseWheelScroll(com.google.gwt.user.client.Event event)
Execute on mouse wheel event.protected void
onMove(com.google.gwt.user.client.Event event)
Executed on mouse move while dragging.protected void
onUp(com.google.gwt.user.client.Event event)
Executed on mouse up while dragging.protected void
positionHelper()
Positions an element depending on the current events client position and the cursor offset.void
removeTarget(I_CmsDropTarget target)
Removes a drop target from the register.void
setAnimationType(CmsDNDHandler.AnimationType animationType)
Sets the animation type.void
setController(I_CmsDNDController controller)
Sets the drag and drop controller.void
setCursorOffsetX(int cursorOffsetX)
Sets the cursor offset x.void
setCursorOffsetY(int cursorOffsetY)
Sets the cursor offset y.void
setDraggable(I_CmsDraggable draggable)
Sets the draggable.void
setDragHelper(com.google.gwt.dom.client.Element dragHelper)
Sets the drag helper element.void
setOrientation(CmsDNDHandler.Orientation orientation)
Sets the allowed drag and drop orientation.void
setPlaceholder(com.google.gwt.dom.client.Element placeholder)
Sets the placeholder element.void
setScrollElement(com.google.gwt.dom.client.Element scrollElement)
Sets the scroll element in case not the window but another element needs scrolling.void
setScrollEnabled(boolean scrollEnabled)
Sets the scrolling enabled.void
setStartPosition(int left, int top)
Sets the start position.protected void
stopDragging()
Sets dragging to false and removes the event preview handler.void
updatePosition()
Updates the position of the helper within the the appropriate target.
-
-
-
Constructor Detail
-
CmsDNDHandler
public CmsDNDHandler(I_CmsDNDController controller)
Constructor.- Parameters:
controller
- the drag and drop controller
-
-
Method Detail
-
addTarget
public void addTarget(I_CmsDropTarget target)
Adds a drop target.- Parameters:
target
- the target to add
-
cancel
public void cancel()
Cancels the dragging process.
-
clearTargets
public void clearTargets()
Clears the drop target register.
-
drop
public void drop()
Drops the draggable.
-
getController
public I_CmsDNDController getController()
Returns the drag and drop controller.- Returns:
- the drag and drop controller
-
getCurrentTarget
public I_CmsDropTarget getCurrentTarget()
Returns the current drop target.- Returns:
- the current drop target
-
getCursorOffsetX
public int getCursorOffsetX()
Returns the cursor offset x.- Returns:
- the cursor offset x
-
getCursorOffsetY
public int getCursorOffsetY()
Returns the cursor offset y.- Returns:
- the cursor offset y
-
getDraggable
public I_CmsDraggable getDraggable()
Returns the current draggable.- Returns:
- the draggable
-
getDragHelper
public com.google.gwt.dom.client.Element getDragHelper()
Returns the drag helper element.- Returns:
- the drag helper
-
getOrientation
public CmsDNDHandler.Orientation getOrientation()
Returns the allowed drag and drop orientation.- Returns:
- the drag and drop orientation
-
getPlaceholder
public com.google.gwt.dom.client.Element getPlaceholder()
Returns the place holder element.- Returns:
- the place holder element
-
hasModifierCTRL
public boolean hasModifierCTRL()
Returns whether the CTRL key was pressed when drag started.- Returns:
true
if CTRL key was pressed when drag started
-
isAnimationEnabled
public boolean isAnimationEnabled()
Returns if the animation is enabled.- Returns:
true
if the animation is enabled
-
isDragging
public boolean isDragging()
Returns if a dragging process is taking place.- Returns:
true
if the handler is currently dragging
-
isScrollEnabled
public boolean isScrollEnabled()
Returns if automated scrolling is enabled.- Returns:
- if automated scrolling is enabled
-
onMouseDown
public void onMouseDown(com.google.gwt.event.dom.client.MouseDownEvent event)
- Specified by:
onMouseDown
in interfacecom.google.gwt.event.dom.client.MouseDownHandler
- See Also:
MouseDownHandler.onMouseDown(com.google.gwt.event.dom.client.MouseDownEvent)
-
removeTarget
public void removeTarget(I_CmsDropTarget target)
Removes a drop target from the register.- Parameters:
target
- the target to remove
-
setAnimationType
public void setAnimationType(CmsDNDHandler.AnimationType animationType)
Sets the animation type.- Parameters:
animationType
- the animation type
-
setController
public void setController(I_CmsDNDController controller)
Sets the drag and drop controller.- Parameters:
controller
- the drag and drop controller to set
-
setCursorOffsetX
public void setCursorOffsetX(int cursorOffsetX)
Sets the cursor offset x.- Parameters:
cursorOffsetX
- the cursor offset x to set
-
setCursorOffsetY
public void setCursorOffsetY(int cursorOffsetY)
Sets the cursor offset y.- Parameters:
cursorOffsetY
- the cursor offset y to set
-
setDraggable
public void setDraggable(I_CmsDraggable draggable)
Sets the draggable.- Parameters:
draggable
- the draggable
-
setDragHelper
public void setDragHelper(com.google.gwt.dom.client.Element dragHelper)
Sets the drag helper element.- Parameters:
dragHelper
- the drag helper element
-
setOrientation
public void setOrientation(CmsDNDHandler.Orientation orientation)
Sets the allowed drag and drop orientation.- Parameters:
orientation
- the drag and drop orientation to set
-
setPlaceholder
public void setPlaceholder(com.google.gwt.dom.client.Element placeholder)
Sets the placeholder element.- Parameters:
placeholder
- the placeholder element
-
setScrollElement
public void setScrollElement(com.google.gwt.dom.client.Element scrollElement)
Sets the scroll element in case not the window but another element needs scrolling.- Parameters:
scrollElement
- the scroll element
-
setScrollEnabled
public void setScrollEnabled(boolean scrollEnabled)
Sets the scrolling enabled.- Parameters:
scrollEnabled
-true
to enable scrolling
-
setStartPosition
public void setStartPosition(int left, int top)
Sets the start position.In case of a canceled drag and drop and enabled animation, the draggable helper element will be reverted to the start position.
Values
<0
will be ignored.- Parameters:
left
- the left positiontop
- the top position
-
updatePosition
public void updatePosition()
Updates the position of the helper within the the appropriate target.Needs to be executed on mouse move or when the list of allowed targets changes.
Uses the currently stored cursor position.
-
animateCancel
protected void animateCancel(I_CmsDraggable draggable, I_CmsDNDController controller)
Clears the drag process with a move animation of the drag element to it's original position.- Parameters:
draggable
- the draggablecontroller
- the drag and drop controller
-
animateDrop
protected void animateDrop(I_CmsDraggable draggable, I_CmsDropTarget target, I_CmsDNDController controller)
Clears the drag process with a move animation of the drag element to the place-holder position.- Parameters:
draggable
- the draggabletarget
- the drop targetcontroller
- the drag and drop controller
-
clear
protected void clear()
Clears all references used within the current drag process.
-
clearScrollTimer
protected void clearScrollTimer()
Cancels the scroll timer and removes the timer reference.
-
onMouseWheelScroll
protected void onMouseWheelScroll(com.google.gwt.user.client.Event event)
Execute on mouse wheel event.- Parameters:
event
- the native event
-
onMove
protected void onMove(com.google.gwt.user.client.Event event)
Executed on mouse move while dragging.- Parameters:
event
- the event
-
onUp
protected void onUp(com.google.gwt.user.client.Event event)
Executed on mouse up while dragging.- Parameters:
event
- the event
-
positionHelper
protected void positionHelper()
Positions an element depending on the current events client position and the cursor offset. This method assumes that the element parent is positioned relative.
-
stopDragging
protected void stopDragging()
Sets dragging to false and removes the event preview handler.
-
-