Subversion Repositories SmartDukaan

Rev

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

Rev 2119 Rev 2427
Line 15... Line 15...
15
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;
16
import com.google.gwt.user.client.ui.ListBox;
17
import com.google.gwt.user.client.ui.TextBox;
17
import com.google.gwt.user.client.ui.TextBox;
18
import com.google.gwt.user.client.ui.Widget;
18
import com.google.gwt.user.client.ui.Widget;
19
 
19
 
-
 
20
/**
-
 
21
 * This dialog is used to add/edit item related prices (DealerPrice, MOP, TransferPrice) for a vendor.
20
 
22
 *
-
 
23
 */
21
public class VendorPricesDialog extends DialogBox {
24
public class VendorPricesDialog extends DialogBox {
22
 
25
 
23
  interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
26
    interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
24
  private static final Binder binder = GWT.create(Binder.class);
27
    private static final Binder binder = GWT.create(Binder.class);
25
 
28
 
-
 
29
    /**
-
 
30
     * Listener for update button click.
-
 
31
     */
26
  public interface VendorPriceUpdateListener{
32
    public interface VendorPriceUpdateListener{
27
      boolean onUpdate(double mop, double dp, double tp, long vendorId);
33
        boolean onUpdate(double mop, double dp, double tp, long vendorId);
28
  }
34
    }
29
  
35
 
30
  private VendorPriceUpdateListener vendorPriceUpdateListener;
36
    private VendorPriceUpdateListener vendorPriceUpdateListener;
31
  
37
 
32
  @UiField Button closeButton, updateButton;
38
    @UiField Button closeButton, updateButton;
33
  @UiField TextBox mop, dealerPrice, transferPrice;
39
    @UiField TextBox mop, dealerPrice, transferPrice;
34
  @UiField ListBox vendor;
40
    @UiField ListBox vendor;
35
 
41
 
36
  public VendorPricesDialog() {
42
    public VendorPricesDialog() {
37
      setText("Vendor Prices");
43
        setText("Vendor Prices");
38
      setWidget(binder.createAndBindUi(this));
44
        setWidget(binder.createAndBindUi(this));
39
      setAnimationEnabled(true);
45
        setAnimationEnabled(true);
40
      //setGlassEnabled(true);
-
 
41
      center();
46
        center();
42
      for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
47
        for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
43
          vendor.addItem(e.getValue());
48
            vendor.addItem(e.getValue());
44
      }
49
        }
45
  }
50
    }
46
  
51
 
47
  public VendorPricesDialog(String mop, String dp, String tp) {
52
    public VendorPricesDialog(String mop, String dp, String tp) {
48
    this();
53
        this();
49
    setPrices(mop, dp, tp);
54
        setPrices(mop, dp, tp);
50
  }
55
    }
51
  
56
 
52
  public void setPrices(String mop, String dp, String tp) {
57
    public void setPrices(String mop, String dp, String tp) {
53
    this.mop.setText(mop);
58
        this.mop.setText(mop);
54
    this.dealerPrice.setText(dp);
59
        this.dealerPrice.setText(dp);
55
    this.transferPrice.setText(tp);
60
        this.transferPrice.setText(tp);
56
    this.vendor.setEnabled(false);
61
        this.vendor.setEnabled(false);
57
  }
62
    }
58
  
63
 
-
 
64
    /**
-
 
65
     * listener for click on update button is set in ItemDetails and ItemForm
-
 
66
     * @param vPriceUpdateListener
-
 
67
     */
59
  public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
68
    public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
60
      this.vendorPriceUpdateListener = vPriceUpdateListener;
69
        this.vendorPriceUpdateListener = vPriceUpdateListener;
61
  }
70
    }
62
 
71
 
63
  @UiHandler("closeButton")
72
    @UiHandler("closeButton")
64
  void onCloseClicked(ClickEvent event) {
73
    void onCloseClicked(ClickEvent event) {
65
    hide();
74
        hide();
66
  }
75
    }
67
  
76
 
68
  @UiHandler("updateButton")
77
    @UiHandler("updateButton")
69
  void onEditClicked(ClickEvent event) {
78
    void onEditClicked(ClickEvent event) {
70
      double mop;
79
        double mop, dp, tp;
71
      double dp;
-
 
72
      double tp;
-
 
73
      long vendorId;
-
 
74
      try {
80
        try {
75
          mop = Double.parseDouble(this.mop.getText());
81
            mop = Double.parseDouble(this.mop.getText());
76
          dp = Double.parseDouble(this.dealerPrice.getText());
82
            dp = Double.parseDouble(this.dealerPrice.getText());
77
          tp = Double.parseDouble(this.transferPrice.getText());
83
            tp = Double.parseDouble(this.transferPrice.getText());
78
          vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
-
 
79
      } catch(NumberFormatException ex) {
84
        } catch(NumberFormatException ex) {
80
          Window.alert("Price format is not valid.");
85
            Window.alert("Price format is not valid.");
81
          return;
86
            return;
82
      }
87
        }
-
 
88
        long vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
83
      if(vendorPriceUpdateListener.onUpdate(mop, dp, tp, vendorId)) {
89
        if(vendorPriceUpdateListener.onUpdate(mop, dp, tp, vendorId)) {
84
          hide();
90
            hide();
85
      }
91
        }
86
  }
92
    }
87
}
93
}