| /trunk/ShoppingCart/src/com/gwtsite/dnd/client/CartDropController.java r6 | /trunk/ShoppingCart/src/com/gwtsite/dnd/client/CartDropController.java r10 | ||
| 1 | /* | ||
|---|---|---|---|
| 2 | * Copyright 2008 Chris Fong | ||
| 3 | * | ||
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| 5 | * use this file except in compliance with the License. You may obtain a copy of | ||
| 6 | * the License at | ||
| 7 | * | ||
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | * | ||
| 10 | * Unless required by applicable law or agreed to in writing, software | ||
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| 13 | * License for the specific language governing permissions and limitations under | ||
| 14 | * the License. | ||
| 15 | */ | ||
| 1 | package com.gwtsite.dnd.client; | 16 | package com.gwtsite.dnd.client; |
| 2 | 17 | ||
| 3 | import com.allen_sauer.gwt.dnd.client.DragContext; | 18 | import com.allen_sauer.gwt.dnd.client.DragContext; |
| 4 | import com.allen_sauer.gwt.dnd.client.VetoDragException; | 19 | import com.allen_sauer.gwt.dnd.client.VetoDragException; |
| 5 | import com.allen_sauer.gwt.dnd.client.drop.SimpleDropController; | 20 | import com.allen_sauer.gwt.dnd.client.drop.SimpleDropController; |
| 6 | import com.google.gwt.user.client.ui.Widget; | 21 | import com.google.gwt.user.client.ui.Widget; |
| 7 | 22 | ||
| 8 | public class CartDropController extends SimpleDropController { | 23 | public class CartDropController extends SimpleDropController { |
| 9 | 24 | ||
| 10 | private ShoppingCart cart; | 25 | private ShoppingCart cart; |
| 11 | 26 | ||
| 12 | public CartDropController(Widget dropTarget) { | 27 | public CartDropController(Widget dropTarget) { |
| 13 | super(dropTarget); | 28 | super(dropTarget); |
| 14 | cart = (ShoppingCart)dropTarget; | 29 | cart = (ShoppingCart)dropTarget; |
| 15 | } | 30 | } |
| 16 | 31 | ||
| 17 | public void onDrop(DragContext context) { | 32 | public void onDrop(DragContext context) { |
| 18 | super.onDrop(context); | 33 | super.onDrop(context); |
| 19 | Book book = (Book)context.draggable; | 34 | Book book = (Book)context.draggable; |
| 20 | cart.add(book); | 35 | cart.add(book); |
| 21 | } | 36 | } |
| 22 | 37 | ||
| 23 | public void onEnter(DragContext context) { | 38 | public void onEnter(DragContext context) { |
| 24 | super.onEnter(context); | 39 | super.onEnter(context); |
| 25 | cart.addStyleName("enterCart"); | 40 | cart.addStyleName("enterCart"); |
| 26 | } | 41 | } |
| 27 | 42 | ||
| 28 | public void onLeave(DragContext context) { | 43 | public void onLeave(DragContext context) { |
| 29 | super.onLeave(context); | 44 | super.onLeave(context); |
| 30 | cart.removeStyleName("enterCart"); | 45 | cart.removeStyleName("enterCart"); |
| 31 | } | 46 | } |
| 32 | 47 | ||
| 33 | public void onPreviewDrop(DragContext context) throws VetoDragException { | 48 | public void onPreviewDrop(DragContext context) throws VetoDragException { |
| 34 | 49 | ||
| 35 | super.onPreviewDrop(context); | 50 | super.onPreviewDrop(context); |
| 36 | } | 51 | } |
| 37 | 52 | ||
| 38 | 53 | ||
| 39 | 54 | ||
| 40 | } | 55 | } |