01: package net.ar.webonswing.petstore;
02:
03: import java.util.*;
04:
05: import javax.swing.*;
06:
07: import net.ar.webonswing.*;
08: import net.ar.webonswing.petstore.actions.*;
09: import net.ar.webonswing.petstore.contributors.*;
10: import net.ar.webonswing.petstore.helpers.*;
11: import net.ar.webonswing.petstore.model.*;
12:
13: public class ProductView extends ApplicationFrame {
14: protected Product product;
15:
16: public ProductView() {
17: WosFramework.assignContributor(this ,
18: new HibernateObjectPersistenceContributor("product"));
19: }
20:
21: public ProductView(Product aProduct) {
22: this ();
23:
24: setProduct(aProduct);
25: init();
26: }
27:
28: protected JComponent getBody() {
29: GenericTable table = new GenericTable(new String[] { "ItemId",
30: "ProductId", "Description", "ListPrice", "Add" });
31:
32: for (Iterator i = product.getItems().iterator(); i.hasNext();) {
33: final Item item = (Item) i.next();
34:
35: JLabel itemId = new JLabel(item.getItemId());
36: itemId.addMouseListener(new ShowItemAction(item));
37:
38: JButton addItemButton = new JButton("Add Item");
39: addItemButton.addActionListener(new AddItemToCartAction(
40: item, getCart()));
41:
42: table
43: .addRow(new JComponent[] { itemId,
44: new JLabel(product.getProductId()),
45: new JLabel(item.getDescription()),
46: new JLabel(item.getListPrice() + ""),
47: addItemButton });
48: }
49:
50: JPanel panel = new JPanel();
51: panel.add(table);
52: panel.add(new JLabel(product.getName())).setName("name");
53: panel.add(new JLabel(product.getDescription())).setName(
54: "description");
55:
56: panel.setLayout(ApplicationFrame.getCurrentSkin()
57: .getCurrentPropagateTemplateFor("ProductView.main"));
58:
59: return panel;
60: }
61:
62: public Product getProduct() {
63: return product;
64: }
65:
66: public void setProduct(Product aProduct) {
67: this.product = aProduct;
68: }
69: }
|