Subversion Repositories SmartDukaan

Rev

Rev 2105 | Rev 2427 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2105 Rev 2119
Line 22... Line 22...
22
 
22
 
23
  interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
23
  interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
24
  private static final Binder binder = GWT.create(Binder.class);
24
  private static final Binder binder = GWT.create(Binder.class);
25
 
25
 
26
  public interface VendorPriceUpdateListener{
26
  public interface VendorPriceUpdateListener{
27
      boolean onUpdate(String itemKey, double mop, double dp, double tp, long vendorId);
27
      boolean onUpdate(double mop, double dp, double tp, long vendorId);
28
  }
28
  }
29
  
29
  
30
  private VendorPriceUpdateListener vendorPriceUpdateListener;
30
  private VendorPriceUpdateListener vendorPriceUpdateListener;
31
  
31
  
32
  @UiField Button closeButton, updateButton;
32
  @UiField Button closeButton, updateButton;
33
  @UiField TextBox itemKey, mop, dealerPrice, transferPrice;
33
  @UiField TextBox mop, dealerPrice, transferPrice;
34
  @UiField ListBox vendor;
34
  @UiField ListBox vendor;
35
 
35
 
36
  public VendorPricesDialog() {
36
  public VendorPricesDialog() {
37
      setText("Vendor Prices");
37
      setText("Vendor Prices");
38
      setWidget(binder.createAndBindUi(this));
38
      setWidget(binder.createAndBindUi(this));
Line 42... Line 42...
42
      for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
42
      for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
43
          vendor.addItem(e.getValue());
43
          vendor.addItem(e.getValue());
44
      }
44
      }
45
  }
45
  }
46
  
46
  
47
  public VendorPricesDialog(String itemKey, String mop, String dp, String tp) {
47
  public VendorPricesDialog(String mop, String dp, String tp) {
48
    this();
48
    this();
49
    setPrices(itemKey, mop, dp, tp);
49
    setPrices(mop, dp, tp);
50
  }
50
  }
51
  
51
  
52
  public void setPrices(String itemKey, String mop, String dp, String tp) {
52
  public void setPrices(String mop, String dp, String tp) {
53
    this.itemKey.setText(itemKey);
-
 
54
    this.mop.setText(mop);
53
    this.mop.setText(mop);
55
    this.dealerPrice.setText(dp);
54
    this.dealerPrice.setText(dp);
56
    this.transferPrice.setText(tp);
55
    this.transferPrice.setText(tp);
57
    this.vendor.setEnabled(false);
56
    this.vendor.setEnabled(false);
58
    this.itemKey.setEnabled(false);
-
 
59
  }
57
  }
60
 
-
 
61
  /*@Override
-
 
62
  protected void onPreviewNativeEvent(NativePreviewEvent preview) {
-
 
63
    super.onPreviewNativeEvent(preview);
-
 
64
 
-
 
65
    NativeEvent evt = preview.getNativeEvent();
-
 
66
    if (evt.getType().equals("keydown")) {
-
 
67
      // Use the popup's key preview hooks to close the dialog when either
-
 
68
      // enter or escape is pressed.
-
 
69
      switch (evt.getKeyCode()) {
-
 
70
        case KeyCodes.KEY_ENTER:
-
 
71
        case KeyCodes.KEY_ESCAPE:
-
 
72
          hide();
-
 
73
          break;
-
 
74
      }
-
 
75
    }
-
 
76
  }*/
-
 
77
  
58
  
78
  public void setVendorDetailsUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
59
  public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
79
      this.vendorPriceUpdateListener = vPriceUpdateListener;
60
      this.vendorPriceUpdateListener = vPriceUpdateListener;
80
  }
61
  }
81
 
62
 
82
  @UiHandler("closeButton")
63
  @UiHandler("closeButton")
83
  void onCloseClicked(ClickEvent event) {
64
  void onCloseClicked(ClickEvent event) {
Line 88... Line 69...
88
  void onEditClicked(ClickEvent event) {
69
  void onEditClicked(ClickEvent event) {
89
      double mop;
70
      double mop;
90
      double dp;
71
      double dp;
91
      double tp;
72
      double tp;
92
      long vendorId;
73
      long vendorId;
93
      String key;
-
 
94
      try {
74
      try {
95
          mop = Double.parseDouble(this.mop.getText());
75
          mop = Double.parseDouble(this.mop.getText());
96
          dp = Double.parseDouble(this.dealerPrice.getText());
76
          dp = Double.parseDouble(this.dealerPrice.getText());
97
          tp = Double.parseDouble(this.transferPrice.getText());
77
          tp = Double.parseDouble(this.transferPrice.getText());
98
          vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
78
          vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
99
          key = itemKey.getText().trim();
-
 
100
          if(key.isEmpty()) {
-
 
101
              Window.alert("Item key cannot be empty");
-
 
102
              return;
-
 
103
          }
-
 
104
      } catch(NumberFormatException ex) {
79
      } catch(NumberFormatException ex) {
105
          Window.alert("Price format is not valid.");
80
          Window.alert("Price format is not valid.");
106
          return;
81
          return;
107
      }
82
      }
108
      if(vendorPriceUpdateListener.onUpdate(key, mop, dp, tp, vendorId)) {
83
      if(vendorPriceUpdateListener.onUpdate(mop, dp, tp, vendorId)) {
109
          hide();
84
          hide();
110
      }
85
      }
111
  }
86
  }
112
}
87
}