Subversion Repositories SmartDukaan

Rev

Rev 585 | Blame | Last modification | View Log | RSS feed

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

import java.io.PrintStream;
import java.util.List;

import in.shop2020.hotspot.dashbaord.client.dispatch.DispatcherAsync;
import in.shop2020.hotspot.dashbaord.client.event.AcceptOrderEvent;
import in.shop2020.hotspot.dashbaord.client.event.AcceptOrderEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.AddressLabelEvent;
import in.shop2020.hotspot.dashbaord.client.event.AddressLabelEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.BilledOrderEvent;
import in.shop2020.hotspot.dashbaord.client.event.BilledOrderEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadAcceptedOrderListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadAcceptedOrderListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadAllItemsListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadAllItemsListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadAllOrdersListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadAllOrdersListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadBestDealsEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadBestDealsEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadBestSellersEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadBestSellersEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadBilledOrderListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadBilledOrderListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadItemDetailsEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadItemDetailsEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadLatestArrivalsEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadLatestArrivalsEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadNostockOrderListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadNostockOrderListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadNotAvailableOrderListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderDetailsEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderDetailsEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadRejectedOrderListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadRejectedOrderListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.LoadShippedOrderListEvent;
import in.shop2020.hotspot.dashbaord.client.event.LoadShippedOrderListEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.NostockOrderEvent;
import in.shop2020.hotspot.dashbaord.client.event.NostockOrderEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.RefreshDetailsEvent;
import in.shop2020.hotspot.dashbaord.client.event.RefreshDetailsEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.RejectOrderEvent;
import in.shop2020.hotspot.dashbaord.client.event.RejectOrderEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.ShippedOrderEvent;
import in.shop2020.hotspot.dashbaord.client.event.ShippedOrderEventHandler;
import in.shop2020.hotspot.dashbaord.client.event.SignOutEvent;
import in.shop2020.hotspot.dashbaord.client.inbox.InboxPresenter.Display;
import in.shop2020.hotspot.dashbaord.shared.actions.AcceptOrderRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.AcceptOrderResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.AcceptedOrderListRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.AcceptedOrderListResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.AddressRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.AddressResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.AllItemsListRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.AllItemsListResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.AllOrderListRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.AllOrderListResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.BestDealsRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.BestDealsResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.BestSellersRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.BestSellersResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.BillOrderRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.BillOrderResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.BilledOrderListRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.BilledOrderListResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.DetailsMask;
import in.shop2020.hotspot.dashbaord.shared.actions.Item;
import in.shop2020.hotspot.dashbaord.shared.actions.ItemDetailsRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.ItemDetailsResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.LatestArrivalsRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.LatestArrivalsResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.NostockOrderListRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.NostockOrderListResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.NostockOrderRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.NostockOrderResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
import in.shop2020.hotspot.dashbaord.shared.actions.OrderDetailsRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.OrderDetailsResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.OrderRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.OrderResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
import in.shop2020.hotspot.dashbaord.shared.actions.RejectOrderRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.RejectOrderResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.RejectedOrderListRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.RejectedOrderListResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.ShipOrderRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.ShipOrderResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.ShippedOrderListRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.ShippedOrderListResponse;

import net.customware.gwt.dispatch.client.DispatchAsync;

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

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SplitLayoutPanel;
import com.google.inject.Inject;

public class InboxPresenterImpl extends BasePresenter<InboxPresenter.Display> implements InboxPresenter{
        
        private final DispatchAsync dispatcher;
        private StatusDialog dialog;
        private GwtEvent<?> pollingEvent = null;
        private String user;
        private long warehouseId;
        
        @Inject
        public InboxPresenterImpl(EventBus eventBus, Display display, final DispatchAsync dispatcher) {
                super(eventBus, display);               
                this.dispatcher = dispatcher;
        }

        @Override
        public void initialize() {
                
                dialog = new StatusDialog();
                
                display.getNewOrdersAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadOrderListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });
                
                display.getSignOutLink().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new SignOutEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });
                
                display.getOrdersTreeHeader().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadAllItemsListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });
                
                display.getAcceptedOrdersAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadAcceptedOrderListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });

                display.getNotAvailableAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadNostockOrderListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });

                display.getRejectedOrdersAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadRejectedOrderListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });
                
                display.getBilledOrdersAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadBilledOrderListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });
                
                display.getShippedOrdersAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadShippedOrderListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });
                
                display.getAllOrdersAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadAllOrdersListEvent());
                                eventBus.fireEvent(new RefreshDetailsEvent());
                        }
                });
                
                //Add an event handler to show the items in the catalogue
                display.getCatalogTreeHeader().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadAllItemsListEvent());
                        }
                });

                display.getAllItemsAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadAllItemsListEvent());
                        }
                });
                
                display.getBestDealsAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadBestDealsEvent());
                        }
                });
                
                display.getBestSellersAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadBestSellersEvent());
                        }
                });
                
                display.getLatestArrivalsAnchor().addClickHandler(new ClickHandler() {
                        
                        @Override
                        public void onClick(ClickEvent event) {
                                eventBus.fireEvent(new LoadLatestArrivalsEvent());
                                GWT.log("Latest Arrivals event fired");
                        }
                });
                
                Timer t = new Timer() {
                        
                        @Override
                        public void run() {
                                if (pollingEvent != null){
                                        eventBus.fireEvent(pollingEvent);
                                }
                                
                        }
                };
                
                t.scheduleRepeating(60000);             
        }

        @Override
        public void refreshOrderList(List<Order> order) {
                display.updateOrderList(new OrderList(eventBus, order));        
        }

        @Override
        public void refreshItemList(List<Item> items) {
                display.updateItemList(new ItemList(eventBus, items));
        }
        
        @Override
        public void bind(){
                super.bind();
                registerHandler(eventBus.addHandler(LoadOrderListEvent.getType(), new LoadOrderListEventHandler() {
                        
                        @Override
                        public void onLoadOrderList(LoadOrderListEvent event) {
                                dispatcher.execute(new OrderRequest(OrderType.NEW, warehouseId), new AsyncCallback<OrderResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                                                                
                                        }

                                        @Override
                                        public void onSuccess(OrderResponse result) {
                                                refreshOrderList(result.getOrders());
                                                pollingEvent = new LoadOrderListEvent();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadOrderDetailsEvent.getType(), new LoadOrderDetailsEventHandler() {
                        
                        @Override
                        public void onLoadOrderDetails(final LoadOrderDetailsEvent event) {
                                dispatcher.execute(new OrderDetailsRequest(event.getOrder().getOrderId()), new AsyncCallback<OrderDetailsResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                int i = 1;
                                        }

                                        @Override
                                        public void onSuccess(OrderDetailsResponse result) {
                                                display.updateDetailsPane(new OrderDetails(eventBus, event.getOrder(), result.getOrder(), result.getMask(), user));
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(AcceptOrderEvent.getType(), new AcceptOrderEventHandler() {
                        
                        @Override
                        public void onAcceptOrder(AcceptOrderEvent event) {
                                //change status of this order.
                                dispatcher.execute(new AcceptOrderRequest(event.getOrder()), new AsyncCallback<AcceptOrderResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                dialog.setTitle("Accept Order Failed");
                                                dialog.setText("Order could not be accepted");
                                                dialog.show();
                                        }

                                        @Override
                                        public void onSuccess(AcceptOrderResponse result) {

                                                if(result == null){
                                                        dialog.setTitle("Could not fetch the value");
                                                        dialog.setText("Looks like server is unable to do anything here");
                                                        dialog.show();
                                                }else if(result.isStatus()){
                                                        dialog.setTitle("Accepted Order");
                                                        dialog.setText("Order "+ result.getOrder().getOrderId()+ " was accepted");
                                                        dialog.show();
                                                        eventBus.fireEvent(new LoadAcceptedOrderListEvent());
                                                        eventBus.fireEvent(new LoadOrderDetailsEvent(result.getOrder()));
                                                        //display.updateOrderDetails(new OrderDetails(eventBus, result.getOrder(), result.getOrder(), DetailsMask.ACCEPT, user));
                                                }else {
                                                        dialog.setTitle("Accept Order Failed");
                                                        dialog.setText("Order "+ result.getOrder().getOrderId()+ " could not be accepted");
                                                        dialog.show();
                                                }
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(NostockOrderEvent.getType(), new NostockOrderEventHandler() {
                        
                        @Override
                        public void onNostockOrder(NostockOrderEvent event) {
                                //change status of this order.
                                dispatcher.execute(new NostockOrderRequest(event.getOrder()), new AsyncCallback<NostockOrderResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(NostockOrderResponse result) {

                                                if(result == null){
                                                        dialog.setTitle("Could not fetch the value");
                                                        dialog.setText("Looks like server is unable to do anything here");
                                                        dialog.show();
                                                } else if(result.isStatus()){
                                                        dialog.setTitle("No Order");
                                                        dialog.setText("Order "+ result.getOrder().getOrderId()+ " is marked as 'No Stock'");
                                                        dialog.show();
                                                        eventBus.fireEvent(new LoadNostockOrderListEvent());
                                                        eventBus.fireEvent(new LoadOrderDetailsEvent(result.getOrder()));
                                                        //display.updateOrderDetails(new OrderDetails(eventBus, result.getOrder(), result.getOrder(), DetailsMask.ACCEPT, user));
                                                }else {
                                                        dialog.setTitle("No stock Order Failed");
                                                        dialog.setText("Order "+ result.getOrder().getOrderId()+ " could not be marked as 'No Stock'");
                                                        dialog.show();
                                                }
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(RejectOrderEvent.getType(), new RejectOrderEventHandler() {
                        
                        @Override
                        public void onRejectOrder(RejectOrderEvent event) {
                                //change status of this order.
                                dispatcher.execute(new RejectOrderRequest(event.getOrder(), event.getRejectReason(), event.getRejectedBy(), event.isInfo()), new AsyncCallback<RejectOrderResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(RejectOrderResponse result) {
                                                if(result == null){
                                                        dialog.setTitle("Could not fetch the value");
                                                        dialog.setText("Looks like server is unable to do anything here");
                                                        dialog.show();
                                                }else if(result.isStatus()){
                                                        dialog.setTitle("Rejected Order");
                                                        dialog.setText("Order "+ result.getOrder().getOrderId()+ " was rejected");
                                                        dialog.show();
                                                        eventBus.fireEvent(new LoadRejectedOrderListEvent());
                                                        eventBus.fireEvent(new LoadOrderDetailsEvent(result.getOrder()));
                                                        //display.updateOrderDetails(new OrderDetails(eventBus, result.getOrder(), result.getOrder(), DetailsMask.ACCEPT, user));
                                                }else {
                                                        dialog.setTitle("Reject Order Failed");
                                                        dialog.setText("Order "+ result.getOrder().getOrderId()+ " could not be rejected");
                                                        dialog.show();
                                                }
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadAcceptedOrderListEvent.getType(), new LoadAcceptedOrderListEventHandler() {
                        
                        @Override
                        public void onLoadAcceptOrderList(LoadAcceptedOrderListEvent event) {
                                dispatcher.execute(new AcceptedOrderListRequest(OrderType.ACCEPTED, warehouseId), new AsyncCallback<AcceptedOrderListResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(AcceptedOrderListResponse result) {
                                                refreshOrderList(result.getOrders());
                                                pollingEvent = new LoadAcceptedOrderListEvent();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadRejectedOrderListEvent.getType(), new LoadRejectedOrderListEventHandler() {
                        
                        @Override
                        public void onLoadRejectedOrderList(LoadRejectedOrderListEvent event) {
                                dispatcher.execute(new RejectedOrderListRequest(OrderType.REJECTED, warehouseId), new AsyncCallback<RejectedOrderListResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(RejectedOrderListResponse result) {
                                                refreshOrderList(result.getOrders());
                                                pollingEvent = new LoadRejectedOrderListEvent();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadAllOrdersListEvent.getType(), new LoadAllOrdersListEventHandler() {
                        
                        @Override
                        public void onLoadAllOrdersEvent(LoadAllOrdersListEvent event) {
                                dispatcher.execute(new AllOrderListRequest(OrderType.ALL, warehouseId), new AsyncCallback< AllOrderListResponse >() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(AllOrderListResponse result) {
                                                refreshOrderList(result.getOrders());
                                                pollingEvent = new LoadAllOrdersListEvent();
                                        }
                                });                             
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadBilledOrderListEvent.getType(), new LoadBilledOrderListEventHandler() {
                        
                        @Override
                        public void onLoadBilledOrderList(LoadBilledOrderListEvent event) {
                                dispatcher.execute(new BilledOrderListRequest(OrderType.BILLED, warehouseId), new AsyncCallback<BilledOrderListResponse>() {
                                
                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(BilledOrderListResponse result) {
                                                refreshOrderList(result.getOrders());
                                                pollingEvent = new LoadBilledOrderListEvent();
                                        }

                        
                                });
                        }
                }));

                registerHandler(eventBus.addHandler(LoadNostockOrderListEvent.getType(), new LoadNostockOrderListEventHandler() {
                        
                        @Override
                        public void onLoadNostockOrderList(LoadNostockOrderListEvent event) {
                                dispatcher.execute(new NostockOrderListRequest(OrderType.NO_STOCK, warehouseId), new AsyncCallback<NostockOrderListResponse>() {
                                
                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(NostockOrderListResponse result) {
                                                refreshOrderList(result.getOrders());
                                                pollingEvent = new LoadNostockOrderListEvent();
                                        }
                                });
                        }
                }));

                registerHandler(eventBus.addHandler(LoadShippedOrderListEvent.getType(), new LoadShippedOrderListEventHandler() {
                        
                        @Override
                        public void onLoadShippedOrderList(LoadShippedOrderListEvent event) {
                                dispatcher.execute(new ShippedOrderListRequest(OrderType.SHIPPED, warehouseId), new AsyncCallback<ShippedOrderListResponse>() {
                                        
                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(ShippedOrderListResponse result) {
                                                refreshOrderList(result.getOrders());
                                                pollingEvent = new LoadShippedOrderListEvent();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(AddressLabelEvent.getType(), new AddressLabelEventHandler() {
                        
                        @Override
                        public void onAddressRequest(AddressLabelEvent event) {
                                dispatcher.execute(new AddressRequest(event.getOrder()), new AsyncCallback<AddressResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(AddressResponse result) {
                                                AddressWidget adialog = new AddressWidget(result.getAddress());
                                                adialog.center();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(ShippedOrderEvent.getType(), new ShippedOrderEventHandler() {
                        
                        @Override
                        public void onShippedOrder(ShippedOrderEvent event) {
                                dispatcher.execute(new ShipOrderRequest(event.getOrder(), event.getAirwayBillNumber(), event.getTracker(), event.getProvider(), event.isInfo()), new AsyncCallback<ShipOrderResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(ShipOrderResponse result) {
                                                if(result.isInfo()){
                                                        StatusDialog dialog = new StatusDialog();
                                                        
                                                        dialog.setTitle("Order Shipped");
                                                        dialog.setText("Order shipment status "+ result.isStatus()+"\n"+result.getStatusMessage());
                                                        dialog.center();
                                                        eventBus.fireEvent(new LoadOrderDetailsEvent(result.getOrder()));
                                                }else{
                                                        if(result.isStatus()){
                                                                eventBus.fireEvent(new LoadShippedOrderListEvent());
                                                                eventBus.fireEvent(new LoadOrderDetailsEvent(result.getOrder()));
                                                        }
                                                        else{
                                                                StatusDialog dialog = new StatusDialog();
                                                                
                                                                dialog.setTitle("Order Cannot be shipped");
                                                                dialog.setText("Order shipment status "+ result.isStatus()+"\n"+result.getStatusMessage());
                                                                dialog.center();
                                                        }
                                                }
                                        }
                                });
                                
                        }
                }));
                
                registerHandler(eventBus.addHandler(BilledOrderEvent.getType(), new BilledOrderEventHandler() {
                        
                        @Override
                        public void onBillingOrder(BilledOrderEvent event) {
                                dispatcher.execute(new BillOrderRequest(event.getOrder(), event.getBillNumber(), event.getCreatedBy()), new AsyncCallback<BillOrderResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                
                                        }

                                        @Override
                                        public void onSuccess(BillOrderResponse result) {
                                                if (result.isStatus()){
                                                        dialog.setTitle("Order Billing");
                                                        dialog.setText("Order billing status "+ result.isStatus()+"\n"+result.getStatusMessage());
                                                        dialog.center();
                                                        eventBus.fireEvent(new LoadBilledOrderListEvent());
                                                        eventBus.fireEvent(new LoadOrderDetailsEvent(result.getOrder()));
                                                }else{
                                                        StatusDialog dialog = new StatusDialog();
                                                        
                                                        dialog.setTitle("Order Billing");
                                                        dialog.setText("Order billing status "+ result.isStatus()+"\n"+result.getStatusMessage());
                                                        dialog.center();
                                                        eventBus.fireEvent(new LoadOrderDetailsEvent(result.getOrder()));
                                                }                                               
                                        }
                                });
                                
                        }
                }));
        
                registerHandler(eventBus.addHandler(RefreshDetailsEvent.getType(), new RefreshDetailsEventHandler() {
                        
                        @Override
                        public void onRefresh(RefreshDetailsEvent event) {
                                display.removeDetailsPane();                            
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadAllItemsListEvent.getType(),new LoadAllItemsListEventHandler() {
                        
                        @Override
                        public void onLoadAllItemsList(LoadAllItemsListEvent loadAllItemsListEvent) {
                                dispatcher.execute(new AllItemsListRequest(), new AsyncCallback<AllItemsListResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                StatusDialog dialog = new StatusDialog();
                                                
                                                dialog.setTitle("Can't display items");
                                                caught.printStackTrace();
                                                dialog.center();
                                        }

                                        @Override
                                        public void onSuccess(AllItemsListResponse result) {
                                                refreshItemList(result.getItems());
                                                pollingEvent = new LoadAllItemsListEvent();
                                        }
                                });
                        }
                }));

                registerHandler(eventBus.addHandler(LoadBestSellersEvent.getType(), new LoadBestSellersEventHandler() {
                        
                        @Override
                        public void onLoadBestSellers(LoadBestSellersEvent loadBestSellersEvent) {
                                dispatcher.execute(new BestSellersRequest(), new AsyncCallback<BestSellersResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                dialog.setTitle("Couldn't fetch the best sellers");
                                                caught.printStackTrace();
                                                dialog.setText("Can't display items");
                                                dialog.center();                                                
                                        }

                                        @Override
                                        public void onSuccess(BestSellersResponse result) {
                                                refreshItemList(result.getItems());
                                                pollingEvent = new LoadBestSellersEvent();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadBestDealsEvent.getType(), new LoadBestDealsEventHandler() {
                        
                        @Override
                        public void onLoadBestDeals(LoadBestDealsEvent loadBestDealsEvent) {
                                dispatcher.execute(new BestDealsRequest(), new AsyncCallback<BestDealsResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                dialog.setTitle("Couldn't fetch the best deals");
                                                caught.printStackTrace();
                                                dialog.setText("Can't display items");
                                                dialog.center();                                                
                                        }

                                        @Override
                                        public void onSuccess(BestDealsResponse result) {
                                                refreshItemList(result.getItems());
                                                pollingEvent = new LoadBestDealsEvent();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadLatestArrivalsEvent.getType(), new LoadLatestArrivalsEventHandler() {
                        
                        @Override
                        public void onLoadLatestArrivals(LoadLatestArrivalsEvent loadLatestArrivalsEvent) {
                                dispatcher.execute(new LatestArrivalsRequest(), new AsyncCallback<LatestArrivalsResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                dialog.setTitle("Can't display items");
                                                caught.printStackTrace();
                                                dialog.setText(caught.getStackTrace().toString());
                                                dialog.center();                                                
                                        }

                                        @Override
                                        public void onSuccess(LatestArrivalsResponse result) {
                                                refreshItemList(result.getItems());
                                                pollingEvent = new LoadLatestArrivalsEvent();
                                        }
                                });
                        }
                }));
                
                registerHandler(eventBus.addHandler(LoadItemDetailsEvent.getType(), new LoadItemDetailsEventHandler() {
                        
                        @Override
                        public void onLoadItemDetails(LoadItemDetailsEvent loadItemDetailsEvent) {
                                dispatcher.execute(new ItemDetailsRequest(loadItemDetailsEvent.getItemId()), new AsyncCallback<ItemDetailsResponse>() {

                                        @Override
                                        public void onFailure(Throwable caught) {
                                                dialog.setTitle("Complete Disaster");
                                                dialog.setText("Item couldn't be fetched");
                                                dialog.show();
                                        }

                                        @Override
                                        public void onSuccess(ItemDetailsResponse result) {
                                                if(result != null && result.getItem()!=null){
                                                        display.updateDetailsPane(new ItemDetails(eventBus, result.getItem()));
                                                }else{
                                                        dialog.setTitle("Could not fetch the item");
                                                        dialog.setText("Item couldn't be fetched");
                                                        dialog.show();
                                                }
                                        }
                                });
                        }
                }));
        }
        
        public void setUsername(String name){
                this.user = name;
        }

        public String getUsername(){
                return this.user;
        }

        @Override
        public void setWarehouseId(long warehouseId) {
                this.warehouseId = warehouseId;
                
        }

        @Override
        public long getWarehouseId() {
                return this.warehouseId;
        }

}