Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5504 phani.kuma 1
 
2
package in.shop2020.catalog.dashboard.client;
3
 
4
import in.shop2020.catalog.dashboard.shared.Utils;
5
 
6
import com.google.gwt.core.client.GWT;
7
import com.google.gwt.event.dom.client.ClickEvent;
8
import com.google.gwt.uibinder.client.UiBinder;
9
import com.google.gwt.uibinder.client.UiField;
10
import com.google.gwt.uibinder.client.UiHandler;
11
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.ui.Button;
13
import com.google.gwt.user.client.ui.DialogBox;
14
import com.google.gwt.user.client.ui.ListBox;
15
import com.google.gwt.user.client.ui.TextBox;
16
import com.google.gwt.user.client.ui.Widget;
17
 
18
public class VoucherItemDialog extends DialogBox {
19
 
20
    interface Binder extends UiBinder<Widget, VoucherItemDialog> { }
21
    private static final Binder binder = GWT.create(Binder.class);
22
 
23
    /**
24
     * Listener for update button click.
25
     */
26
    public interface VoucherUpdateListener{
27
        boolean onUpdate(String voucherType, long voucherAmount);
28
    }
29
 
30
    private VoucherUpdateListener voucherUpdateListener;
31
 
32
    @UiField Button closeButton, updateButton;
33
    @UiField TextBox voucherAmount;
34
    @UiField ListBox voucherType;
35
 
36
    public VoucherItemDialog() {
37
        setText("Vouchers");
38
        setWidget(binder.createAndBindUi(this));
39
        setAnimationEnabled(true);
40
        center();
41
        for(String voucher: Utils.voucherType){
42
        	voucherType.addItem(voucher);
43
        }
44
    }
45
 
46
    public VoucherItemDialog(String voucherAmount) {
47
        this();
48
        setVoucherAmount(voucherAmount);
49
    }
50
 
51
    public void setVoucherAmount(String voucherAmount) {
52
        this.voucherAmount.setText(voucherAmount);
53
        this.voucherType.setEnabled(false);
54
    }
55
 
56
    /**
57
     * listener for click on update button is set in ItemDetails and ItemForm
58
     * @param voucherUpdateListener
59
     */
60
    public void setVoucherUpdateListener(VoucherUpdateListener voucherUpdateListener) {
61
        this.voucherUpdateListener = voucherUpdateListener;
62
    }
63
 
64
    @UiHandler("closeButton")
65
    void onCloseClicked(ClickEvent event) {
66
        hide();
67
    }
68
 
69
    @UiHandler("updateButton")
70
    void onEditClicked(ClickEvent event) {
71
        long voucherAmount;
72
        try {
73
        	voucherAmount = Long.parseLong(this.voucherAmount.getText());
74
        	if(voucherAmount == 0){
75
        		Window.alert("Amount is not valid.");
76
                return;
77
        	}
78
        } catch(NumberFormatException ex) {
79
            Window.alert("Amount format is not valid.");
80
            return;
81
        }
82
        String voucherType = this.voucherType.getItemText(this.voucherType.getSelectedIndex());
83
        if(voucherUpdateListener.onUpdate(voucherType, voucherAmount)) {
84
            hide();
85
        }
86
    }
87
}