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