Rev 12435 | 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;/*** This dialog is used to add/edit item related prices (DealerPrice, MOP, TransferPrice) for a vendor.**/public class VendorPricesDialog extends DialogBox {interface Binder extends UiBinder<Widget, VendorPricesDialog> { }private static final Binder binder = GWT.create(Binder.class);/*** Listener for update button click.*/public interface VendorPriceUpdateListener{boolean onUpdate(double mop, double dp, double tp, double nlc, long vendorId);}private VendorPriceUpdateListener vendorPriceUpdateListener;@UiField Button closeButton, updateButton;@UiField TextBox mop, dealerPrice, transferPrice, nlc;@UiField ListBox vendor;public VendorPricesDialog() {setText("Vendor Prices");setWidget(binder.createAndBindUi(this));setAnimationEnabled(true);center();for(Entry<Long, String> e : Utils.getAllVendors().entrySet()){vendor.addItem(e.getValue());}}public VendorPricesDialog(String mop, String dp, String tp, String nlc) {this();setPrices(mop, dp, tp, nlc);}public void setPrices(String mop, String dp, String tp, String nlc) {this.mop.setText(mop);this.dealerPrice.setText(dp);this.transferPrice.setText(tp);this.nlc.setText(nlc);this.vendor.setEnabled(false);}/*** listener for click on update button is set in ItemDetails and ItemForm* @param vPriceUpdateListener*/public void setVendorPriceUpdateListener(VendorPriceUpdateListener vPriceUpdateListener) {this.vendorPriceUpdateListener = vPriceUpdateListener;}@UiHandler("closeButton")void onCloseClicked(ClickEvent event) {hide();}@UiHandler("updateButton")void onEditClicked(ClickEvent event) {double mop, dp, tp, nlc;try {mop = Double.parseDouble(this.mop.getText());dp = Double.parseDouble(this.dealerPrice.getText());tp = Double.parseDouble(this.transferPrice.getText());nlc = Double.parseDouble(this.nlc.getText());} catch(NumberFormatException ex) {Window.alert("Price format is not valid.");return;}long vendorId = Utils.getVendorId(this.vendor.getItemText(this.vendor.getSelectedIndex()));if(vendorPriceUpdateListener.onUpdate(mop, dp, tp, nlc, vendorId)) {hide();}}}