1 package de.orangecafe.amazonrcp.gui.commands;
2
3 import org.springframework.richclient.command.ActionCommand;
4 import org.springframework.richclient.application.Application;
5 import org.springframework.richclient.application.ApplicationException;
6 import org.springframework.richclient.application.event.LifecycleApplicationEvent;
7 import org.springframework.richclient.util.Assert;
8
9 import de.orangecafe.amazonrcp.service.IAmazonService;
10 import de.orangecafe.amazonrcp.service.ServiceException;
11 import de.orangecafe.amazonrcp.helper.CartHolder;
12 import de.orangecafe.amazonrcp.AmazonRCP;
13 import com.amazon.webservices.awsecommerceservice._2007_04_04.Cart;
14
15 import java.util.prefs.Preferences;
16
17
18
19
20 public class ClearCartCommand extends ActionCommand {
21 private IAmazonService _service;
22
23 private Preferences _preferences = Preferences.userNodeForPackage(AmazonRCP.class);
24
25 public ClearCartCommand() {
26 super("clearCartCommand");
27 }
28
29 public void setAmazonService(final IAmazonService service) {
30 _service = service;
31 }
32
33 protected void doExecuteCommand() {
34 String cartId = _preferences.get(CartHolder.KEY_CART_ID, null);
35 String cartHMAC = _preferences.get(CartHolder.KEY_CART_HMAC, null);
36
37 Assert.notNull(cartId);
38 Assert.notNull(cartHMAC);
39
40 try {
41 _service.clearCart(cartId, cartHMAC);
42 } catch (ServiceException e) {
43 throw new ApplicationException(e);
44 }
45
46 Application.instance().getApplicationContext().publishEvent(new LifecycleApplicationEvent(LifecycleApplicationEvent.CREATED, Cart.class));
47 }
48 }