Permalink
Browse files

getProduct en Ambassador

  • Loading branch information...
1 parent 5e6227c commit ea1f900b536485ba0b60747660447d421b5fbd5c Santiago Lezica committed Nov 26, 2010
View
BIN bin/main/java/shopsardine/main/SSApplication.class
Binary file not shown.
View
BIN bin/main/java/shopsardine/model/Product.class
Binary file not shown.
View
BIN bin/main/java/shopsardine/view/MainFrame.class
Binary file not shown.
View
24 src/main/java/shopsardine/controller/Ambassador.java
@@ -3,6 +3,8 @@
import java.util.LinkedList;
import java.util.List;
+import javax.swing.ImageIcon;
+import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import main.java.shopsardine.embassy.CatalogRequest;
@@ -126,4 +128,26 @@ public void handle(Document response) {
});
}
+
+ public void showProductDetail(int product_id) {
+ new CatalogRequest("GetProduct", "product_id=" + product_id).make(
+ new RequestCallback() {
+
+ public void handle(Document response) {
+ Element element = (Element) response.getElementsByTagName("product").item(0);
+ Product p = new Product(element, true);
+
+ String message = "<html>";
+ for(String key : p.info.keySet()) {
+ message += "<b>" + key + "</b>: " + p.info.get(key) + "<br />";
+ }
+
+ JOptionPane.showMessageDialog(mainFrame, message, p.name,
+ JOptionPane.INFORMATION_MESSAGE, new ImageIcon(p.image));
+
+ }
+
+ });
+
+ }
}
View
1 src/main/java/shopsardine/main/SSApplication.java
@@ -149,6 +149,7 @@ public void mouseClicked(MouseEvent e) {
ambassador.fetchCategories();
ambassador.fetchSubcategories(catid);
ambassador.fetchProducts(catid, subcatid);
+ ambassador.showProductDetail(28);
mainFrame.setVisible(true);
View
26 src/main/java/shopsardine/model/Product.java
@@ -9,14 +9,20 @@
import java.awt.image.RGBImageFilter;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
public class Product {
+ int id;
public Image image;
public String name, desc;
public double price, rank;
+ public Map<String, String> info;
public Product() {}
@@ -31,15 +37,33 @@ public Product(String name, double price, double rank, String picurl) {
}
public Product(Element e) {
+ this(e, false);
+ }
+
+ public Product(Element e, boolean extended) {
String picurl;
+ id = Integer.parseInt(e.getAttribute("id"));
name = e.getElementsByTagName("name").item(0).getTextContent();
price = Double.parseDouble(e.getElementsByTagName("price").item(0).getTextContent());
rank = Double.parseDouble(e.getElementsByTagName("sales_rank").item(0).getTextContent());
if ((picurl = e.getElementsByTagName("image_url").item(0).getTextContent()) != null)
fetchImage(picurl);
+ /* That's the basic info. Do we have extended info? */
+ if (extended) {
+
+ info = new HashMap<String, String>();
+ NodeList nodelist = e.getChildNodes();
+
+ for(int i = 0; i < nodelist.getLength(); i++) {
+ Node n = nodelist.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE)
+ info.put(n.getNodeName(), n.getTextContent());
+ }
+ }
+
}
public static Product fromElement(Element element) {
@@ -61,7 +85,7 @@ public void fetchImage(String url) {
}
public String toString() {
- return "[Product " + name + "]";
+ return name;
}
static ImageFilter filter;

0 comments on commit ea1f900

Please sign in to comment.