| 1961 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
|
|
4 |
|
|
|
5 |
import java.util.Date;
|
|
|
6 |
|
|
|
7 |
import com.google.gwt.core.client.GWT;
|
|
|
8 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
9 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
10 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
11 |
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
12 |
import com.google.gwt.user.client.Window;
|
|
|
13 |
import com.google.gwt.user.client.ui.Button;
|
|
|
14 |
import com.google.gwt.user.client.ui.Label;
|
|
|
15 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
16 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
17 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
18 |
|
|
|
19 |
public class ItemDetails extends ResizeComposite {
|
|
|
20 |
|
|
|
21 |
interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
|
|
|
22 |
private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
|
|
|
23 |
|
|
|
24 |
public interface PriceUpdateListener {
|
|
|
25 |
void onPriceUpdate(long itemId, double sellingPrice);
|
|
|
26 |
}
|
|
|
27 |
private PriceUpdateListener priceUpdateListener;
|
|
|
28 |
|
|
|
29 |
private final Item item;
|
|
|
30 |
|
|
|
31 |
@UiField Label itemId, productGroup, brand, modelNumber, modelName, color;
|
|
|
32 |
@UiField Label category, comments;
|
|
|
33 |
@UiField Label catalogItemId;
|
|
|
34 |
@UiField TextBox sellingPrice;
|
|
|
35 |
@UiField Label mrp, mop, dealerPrice, weight;
|
|
|
36 |
@UiField Label addedOn, startDate, retireDate, updatedOn;
|
|
|
37 |
@UiField Label bestDealsText, bestDealsValue;
|
|
|
38 |
@UiField Button submit;
|
|
|
39 |
|
|
|
40 |
public ItemDetails(Item item){
|
|
|
41 |
this.item = item;
|
|
|
42 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
43 |
setItemDetails(this.item);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public ItemDetails() {
|
|
|
47 |
this.item = null;
|
|
|
48 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public void setItemDetails(Item item){
|
|
|
52 |
itemId.setText(item.getId()+"");
|
|
|
53 |
productGroup.setText(item.getProductGroup());
|
|
|
54 |
brand.setText(item.getBrand());
|
|
|
55 |
modelNumber.setText(item.getModelNumber());
|
|
|
56 |
modelName.setText(item.getModelName());
|
|
|
57 |
color.setText(item.getColor());
|
|
|
58 |
|
|
|
59 |
category.setText(item.getCategory()+"");
|
|
|
60 |
comments.setText(item.getComments());
|
|
|
61 |
catalogItemId.setText(item.getCatalogItemId() + "");
|
|
|
62 |
|
|
|
63 |
mrp.setText(item.getMrp()+"");
|
|
|
64 |
mop.setText(item.getMop()+"");
|
|
|
65 |
sellingPrice.setText(item.getSellingPrice()+"");
|
|
|
66 |
dealerPrice.setText(item.getDealerPrice()+"");
|
|
|
67 |
weight.setText(item.getWeight()+"");
|
|
|
68 |
|
|
|
69 |
addedOn.setText(getDisplayableDate(item.getAddedOn()));
|
|
|
70 |
startDate.setText(getDisplayableDate(item.getStartDate()));
|
|
|
71 |
retireDate.setText(getDisplayableDate(item.getRetireDate()));
|
|
|
72 |
updatedOn.setText(getDisplayableDate(item.getUpdatedOn()));
|
|
|
73 |
|
|
|
74 |
bestDealsText.setText(item.getBestDealsText());
|
|
|
75 |
bestDealsValue.setText(item.getBestDealsValue()+"");
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
//TODO: This code is duplicated between here and OrderList. Move it to a Utility class.
|
|
|
79 |
private String getDisplayableDate(Long millis){
|
|
|
80 |
Date date = new Date();
|
|
|
81 |
date.setTime(millis);
|
|
|
82 |
String dateString = date.toString();
|
|
|
83 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
84 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
85 |
return dateString;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public void setPriceUpdateListener(PriceUpdateListener priceUpdatelistener) {
|
|
|
89 |
this.priceUpdateListener = priceUpdatelistener;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@UiHandler("submit")
|
|
|
93 |
void onSubmitPressed(ClickEvent clickEvent) {
|
|
|
94 |
long id = Long.parseLong(this.itemId.getText());
|
|
|
95 |
try {
|
|
|
96 |
double sp = Double.parseDouble(this.sellingPrice.getText());
|
|
|
97 |
priceUpdateListener.onPriceUpdate(id, sp);
|
|
|
98 |
} catch(NumberFormatException ex) {
|
|
|
99 |
Window.alert("Price format is not correct.");
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
}
|