/* (non-Javadoc)
     * @see fi.jasoft.dragdroplayouts.drophandlers.DefaultCssLayoutDropHandler#handleComponentReordering(com.vaadin.event.dd.DragAndDropEvent)
     */
    @Override
    protected void handleComponentReordering(DragAndDropEvent event) {
      LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
      CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();

      // Get the components
      DDCssLayout layout = (DDCssLayout) details.getTarget();
      Component comp = transferable.getComponent();
      Component over = details.getOverComponent();

      if (over == comp) {
        // If the component and the target are the same, ignore the
        // drag, the component was released "on itself" so no
        // reordering is required.
        return;
      }

      // We are using a CSS layout with float:left; we only care about
      // horizontal positioning
      HorizontalDropLocation horizontalDropLocation = details.getHorizontalDropLocation();

      // Detach - remove current component first, then calculate index.
      layout.removeComponent(comp);
      int indexOfDropTarget = layout.getComponentIndex(over);

      // The layout has the component on top of which the drop occurred
      if (indexOfDropTarget > -1) {

        // If drop location is to the LEFT, add component before
        if (HorizontalDropLocation.LEFT.equals(horizontalDropLocation)
            || HorizontalDropLocation.CENTER.equals(horizontalDropLocation)) {
          layout.addComponent(comp, indexOfDropTarget);
        } else {

          // If drop target is RIGHT, add after
          indexOfDropTarget++;

          if (indexOfDropTarget < layout.getComponentCount()) {
            layout.addComponent(comp, indexOfDropTarget);
          } else {
            layout.addComponent(comp);
          }
        }

      } else {
        // The current layout doesn't have the component on top of which
        // it was dropped, most likely the drop was on the underlying
        // layout itself. In this case we could look at the vertical
        // drop position to determine if we should add the component at
        // the top or the bottom in the layout.
        layout.addComponent(comp);

        // The else could be left out if we want to force the user to
        // drop the component on another component, i.e. dropping on
        // layout is not supported.
      }
    }
  /* (non-Javadoc)
   * @see fi.jasoft.dragdroplayouts.DDCssLayout#paintContent(com.vaadin.server.PaintTarget)
   */
  @Override
  public void paintContent(PaintTarget target) throws PaintException {
    super.paintContent(target);

    // Override paintContent (vaadin serialization api) to set the
    // horizontal drop ratio to 50% so that we don't have a "CENTER"
    // position to drop things. See
    // VDDCssLayout#getHorizontalDropLocation() and
    // VDDCssLayout#handleCellDropRatioUpdate() for details
    target.addAttribute(Constants.ATTRIBUTE_HORIZONTAL_DROP_RATIO, 0.5f);
  }