Subversion Repositories SmartDukaan

Rev

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


package in.shop2020.catalog.dashboard.client;

import in.shop2020.catalog.dashboard.shared.Utils;

import java.util.Map.Entry;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;


public class VendorPricesDialog extends DialogBox {

  interface Binder extends UiBinder<Widget, VendorPricesDialog> { }
  private static final Binder binder = GWT.create(Binder.class);

  public interface VendorPriceUpdateListener{
      boolean onUpdate(double mop, double dp, double tp, long vendorId);
  }
  
  private VendorPriceUpdateListener vendorPriceUpdateListener;
  
  @UiField Button closeButton, updateButton;
  @UiField TextBox mop, dealerPrice, transferPrice;
  @UiField ListBox vendor;

  public VendorPricesDialog() {
      setText("Vendor Prices");
      setWidget(binder.createAndBindUi(this));
      setAnimationEnabled(true);
      //setGlassEnabled(true);
      center();
      for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){
          vendor.addItem(e.getValue());
      }
  }
  
  public VendorPricesDialog(String mop, String dp, String tp) {
    this();
    setPrices(mop, dp, tp);
  }
  
  public void setPrices(String mop, String dp, String tp) {
    this.mop.setText(mop);
    this.dealerPrice.setText(dp);
    this.transferPrice.setText(tp);
    this.vendor.setEnabled(false);
  }
  
  public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {
      this.vendorPriceUpdateListener = vPriceUpdateListener;
  }

  @UiHandler("closeButton")
  void onCloseClicked(ClickEvent event) {
    hide();
  }
  
  @UiHandler("updateButton")
  void onEditClicked(ClickEvent event) {
      double mop;
      double dp;
      double tp;
      long vendorId;
      try {
          mop = Double.parseDouble(this.mop.getText());
          dp = Double.parseDouble(this.dealerPrice.getText());
          tp = Double.parseDouble(this.transferPrice.getText());
          vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));
      } catch(NumberFormatException ex) {
          Window.alert("Price format is not valid.");
          return;
      }
      if(vendorPriceUpdateListener.onUpdate(mop, dp, tp, vendorId)) {
          hide();
      }
  }
}