Subversion Repositories SmartDukaan

Rev

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

Rev 1992 Rev 2105
Line -... Line 1...
-
 
1
 
1
package in.shop2020.catalog.dashboard.client;
2
package in.shop2020.catalog.dashboard.client;
2
 
3
 
-
 
4
import in.shop2020.catalog.dashboard.shared.Utils;
-
 
5
 
-
 
6
import java.util.Map.Entry;
-
 
7
 
3
import com.google.gwt.core.client.GWT;
8
import com.google.gwt.core.client.GWT;
4
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.event.dom.client.ClickEvent;
5
import com.google.gwt.uibinder.client.UiBinder;
10
import com.google.gwt.uibinder.client.UiBinder;
6
import com.google.gwt.uibinder.client.UiField;
11
import com.google.gwt.uibinder.client.UiField;
7
import com.google.gwt.uibinder.client.UiHandler;
12
import com.google.gwt.uibinder.client.UiHandler;
8
import com.google.gwt.user.client.Window;
13
import com.google.gwt.user.client.Window;
9
import com.google.gwt.user.client.ui.Button;
14
import com.google.gwt.user.client.ui.Button;
10
import com.google.gwt.user.client.ui.DialogBox;
15
import com.google.gwt.user.client.ui.DialogBox;
-
 
16
import com.google.gwt.user.client.ui.ListBox;
11
import com.google.gwt.user.client.ui.TextBox;
17
import com.google.gwt.user.client.ui.TextBox;
12
import com.google.gwt.user.client.ui.Widget;
18
import com.google.gwt.user.client.ui.Widget;
13
 
19
 
14
 
20
 
15
public class VendorPricesDialog extends DialogBox {
21
public class VendorPricesDialog extends DialogBox {
16
 
22
 
17
  interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
23
  interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
18
  private static final Binder binder = GWT.create(Binder.class);
24
  private static final Binder binder = GWT.create(Binder.class);
19
 
25
 
20
  public interface VendorPriceUpdateListener{
26
  public interface VendorPriceUpdateListener{
21
      void onPriceUpdate(double mop, double dp, double tp);
27
      boolean onUpdate(String itemKey, double mop, double dp, double tp, long vendorId);
22
  }
28
  }
23
  
29
  
24
  private VendorPriceUpdateListener vendorPriceUpdateListener;
30
  private VendorPriceUpdateListener vendorPriceUpdateListener;
25
  
31
  
26
  @UiField Button closeButton, updateButton;
32
  @UiField Button closeButton, updateButton;
27
  @UiField TextBox mop, dealerPrice, transferPrice;
33
  @UiField TextBox itemKey, mop, dealerPrice, transferPrice;
-
 
34
  @UiField ListBox vendor;
28
 
35
 
29
  public VendorPricesDialog(String mop, String dp, String tp) {
36
  public VendorPricesDialog() {
30
    setText("Vendor Prices");
37
      setText("Vendor Prices");
31
    setWidget(binder.createAndBindUi(this));
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
  
-
 
47
  public VendorPricesDialog(String itemKey, String mop, String dp, String tp) {
-
 
48
    this();
-
 
49
    setPrices(itemKey, mop, dp, tp);
-
 
50
  }
-
 
51
  
-
 
52
  public void setPrices(String itemKey, String mop, String dp, String tp) {
-
 
53
    this.itemKey.setText(itemKey);
32
    this.mop.setText(mop);
54
    this.mop.setText(mop);
33
    this.dealerPrice.setText(dp);
55
    this.dealerPrice.setText(dp);
34
    this.transferPrice.setText(tp);
56
    this.transferPrice.setText(tp);
35
    setAnimationEnabled(true);
57
    this.vendor.setEnabled(false);
36
    //setGlassEnabled(true);
58
    this.itemKey.setEnabled(false);
37
    center();
-
 
38
  }
59
  }
39
 
60
 
40
  /*@Override
61
  /*@Override
41
  protected void onPreviewNativeEvent(NativePreviewEvent preview) {
62
  protected void onPreviewNativeEvent(NativePreviewEvent preview) {
42
    super.onPreviewNativeEvent(preview);
63
    super.onPreviewNativeEvent(preview);
Line 52... Line 73...
52
          break;
73
          break;
53
      }
74
      }
54
    }
75
    }
55
  }*/
76
  }*/
56
  
77
  
57
  public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
78
  public void setVendorDetailsUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
58
      this.vendorPriceUpdateListener = vPriceUpdateListener;
79
      this.vendorPriceUpdateListener = vPriceUpdateListener;
59
  }
80
  }
60
 
81
 
61
  @UiHandler("closeButton")
82
  @UiHandler("closeButton")
62
  void onCloseClicked(ClickEvent event) {
83
  void onCloseClicked(ClickEvent event) {
Line 66... Line 87...
66
  @UiHandler("updateButton")
87
  @UiHandler("updateButton")
67
  void onEditClicked(ClickEvent event) {
88
  void onEditClicked(ClickEvent event) {
68
      double mop;
89
      double mop;
69
      double dp;
90
      double dp;
70
      double tp;
91
      double tp;
-
 
92
      long vendorId;
-
 
93
      String key;
71
      try {
94
      try {
72
          mop = Double.parseDouble(this.mop.getText());
95
          mop = Double.parseDouble(this.mop.getText());
73
          dp = Double.parseDouble(this.dealerPrice.getText());
96
          dp = Double.parseDouble(this.dealerPrice.getText());
74
          tp = Double.parseDouble(this.transferPrice.getText());
97
          tp = Double.parseDouble(this.transferPrice.getText());
-
 
98
          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
          }
75
      } catch(NumberFormatException ex) {
104
      } catch(NumberFormatException ex) {
76
          Window.alert("Price format is not valid.");
105
          Window.alert("Price format is not valid.");
77
          return;
106
          return;
78
      }
107
      }
79
      vendorPriceUpdateListener.onPriceUpdate(mop, dp, tp);
108
      if(vendorPriceUpdateListener.onUpdate(key, mop, dp, tp, vendorId)) {
80
      hide();
109
          hide();
-
 
110
      }
81
  }
111
  }
82
}
112
}