Subversion Repositories SmartDukaan

Rev

Rev 3463 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.hotspot.dashbaord.client.inbox;

import in.shop2020.hotspot.dashbaord.client.event.AddWeightEvent;
import in.shop2020.hotspot.dashbaord.shared.actions.Order;

import org.enunes.gwt.mvp.client.EventBus;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class AddWeightBox extends DialogBox {
    private Label errorLabel = new Label("");
    
    private Label weightLabel = new Label("Weight");
    
    private TextBox weightBox = new TextBox();
    
    private Button submitbutton = new Button("Submit");
    
    private HorizontalPanel hpanel;
    
    private VerticalPanel vpanel = new VerticalPanel();
    
    
    public AddWeightBox(final EventBus eventBus, final Order order){
        vpanel.add(errorLabel);
        
        hpanel = new HorizontalPanel();
        hpanel.setSpacing(5);
        hpanel.add(weightLabel);
        hpanel.add(weightBox);
        hpanel.setCellWidth(weightLabel, "50px");
        vpanel.add(hpanel);
        
        vpanel.add(submitbutton);
            
        setWidget(vpanel);
        setAutoHideEnabled(true);
        setGlassEnabled(true);
        setText("Please enter weight");
        setModal(true);
        
        submitbutton.addClickHandler(new ClickHandler() {
            
            @Override
            public void onClick(ClickEvent event) {
                String weightStr = weightBox.getText();
                try{
                    double weight = Double.parseDouble(weightStr);
                    eventBus.fireEvent(new AddWeightEvent(order, weight));
                }catch(NumberFormatException nfe){
                    errorLabel.setText("Invalid Weight.");
                    return;
                }
                clear();
                hide();
            }
        });
    }
    
    public void clear(){
        weightBox.setText("");
    }
}