Subversion Repositories SmartDukaan

Rev

Rev 2105 | Rev 2427 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2105 ankur.sing 1
 
1992 ankur.sing 2
package in.shop2020.catalog.dashboard.client;
3
 
2105 ankur.sing 4
import in.shop2020.catalog.dashboard.shared.Utils;
5
 
6
import java.util.Map.Entry;
7
 
1992 ankur.sing 8
import com.google.gwt.core.client.GWT;
9
import com.google.gwt.event.dom.client.ClickEvent;
10
import com.google.gwt.uibinder.client.UiBinder;
11
import com.google.gwt.uibinder.client.UiField;
12
import com.google.gwt.uibinder.client.UiHandler;
13
import com.google.gwt.user.client.Window;
14
import com.google.gwt.user.client.ui.Button;
15
import com.google.gwt.user.client.ui.DialogBox;
2105 ankur.sing 16
import com.google.gwt.user.client.ui.ListBox;
1992 ankur.sing 17
import com.google.gwt.user.client.ui.TextBox;
18
import com.google.gwt.user.client.ui.Widget;
19
 
20
 
21
public class VendorPricesDialog extends DialogBox {
22
 
23
  interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
24
  private static final Binder binder = GWT.create(Binder.class);
25
 
26
  public interface VendorPriceUpdateListener{
2119 ankur.sing 27
      boolean onUpdate(double mop, double dp, double tp, long vendorId);
1992 ankur.sing 28
  }
29
 
30
  private VendorPriceUpdateListener vendorPriceUpdateListener;
31
 
32
  @UiField Button closeButton, updateButton;
2119 ankur.sing 33
  @UiField TextBox mop, dealerPrice, transferPrice;
2105 ankur.sing 34
  @UiField ListBox vendor;
1992 ankur.sing 35
 
2105 ankur.sing 36
  public VendorPricesDialog() {
37
      setText("Vendor Prices");
38
      setWidget(binder.createAndBindUi(this));
39
      setAnimationEnabled(true);
40
      //setGlassEnabled(true);
41
      center();
42
      for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
43
          vendor.addItem(e.getValue());
44
      }
45
  }
46
 
2119 ankur.sing 47
  public VendorPricesDialog(String mop, String dp, String tp) {
2105 ankur.sing 48
    this();
2119 ankur.sing 49
    setPrices(mop, dp, tp);
2105 ankur.sing 50
  }
51
 
2119 ankur.sing 52
  public void setPrices(String mop, String dp, String tp) {
1992 ankur.sing 53
    this.mop.setText(mop);
54
    this.dealerPrice.setText(dp);
55
    this.transferPrice.setText(tp);
2105 ankur.sing 56
    this.vendor.setEnabled(false);
1992 ankur.sing 57
  }
58
 
2119 ankur.sing 59
  public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
1992 ankur.sing 60
      this.vendorPriceUpdateListener = vPriceUpdateListener;
61
  }
62
 
63
  @UiHandler("closeButton")
64
  void onCloseClicked(ClickEvent event) {
65
    hide();
66
  }
67
 
68
  @UiHandler("updateButton")
69
  void onEditClicked(ClickEvent event) {
70
      double mop;
71
      double dp;
72
      double tp;
2105 ankur.sing 73
      long vendorId;
1992 ankur.sing 74
      try {
75
          mop = Double.parseDouble(this.mop.getText());
76
          dp = Double.parseDouble(this.dealerPrice.getText());
77
          tp = Double.parseDouble(this.transferPrice.getText());
2105 ankur.sing 78
          vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
1992 ankur.sing 79
      } catch(NumberFormatException ex) {
80
          Window.alert("Price format is not valid.");
81
          return;
82
      }
2119 ankur.sing 83
      if(vendorPriceUpdateListener.onUpdate(mop, dp, tp, vendorId)) {
2105 ankur.sing 84
          hide();
85
      }
1992 ankur.sing 86
  }
87
}