Package net.helipilot50.stocktrade.client

Source Code of net.helipilot50.stocktrade.client.CustomerWindow

package net.helipilot50.stocktrade.client;

import net.helipilot50.stocktrade.model.Customer;
import net.helipilot50.stocktrade.model.Holding;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.FillLayout;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.ButtonEvent;

public class CustomerWindow extends Window {
  Customer customer = null;

  CustomerServiceAsync customerSO;

  private CustomerDetailsPanel customerPanel;

  private CustomerHoldingsPanel holdingsPanel;
 
  public CustomerWindow(final String customerName){
    this();
    this.customerSO = Registry.get(CitrusleafStockTrade.CUSTOMER_SERVICE);
    this.customerSO.getCustomer(customerName, new AsyncCallback<Customer>() {
     
      @Override
      public void onSuccess(Customer result) {
        setCustomer(result);
        Info.display("Success", "Customer found: " + customerName);
      }
     
      @Override
      public void onFailure(Throwable caught) {
        CustomerWindow.this.showWindow(false);
        MessageBox.alert("Customer Error", caught.getMessage(), null);
       
      }
    });
  }

  /**
   * @wbp.parser.constructor
   */
  public CustomerWindow() {
    super();
   
    setHeading("Customer Stock Holdings");
    setLayout(new RowLayout(Orientation.VERTICAL));
   
   
    customerPanel = new CustomerDetailsPanel();
    add(customerPanel);
    if (this.customer != null)
      this.customerPanel.setCustomer(this.customer);

    holdingsPanel = new CustomerHoldingsPanel();
    add(holdingsPanel);
    if (this.customer != null)
      this.holdingsPanel.setHoldings(this.customer.getHoldingList());
   
    LayoutContainer layoutContainer = new LayoutContainer();
    layoutContainer.setLayout(new FillLayout(Orientation.HORIZONTAL));
   
    Button btnBuy = new Button("Buy");
    btnBuy.addListener(Events.Select, new Listener<ButtonEvent>() {
      public void handleEvent(ButtonEvent e) {
        OrderWindow orderWindow = new OrderWindow(OrderWindow.BUY_ORDER, customer.getCustomerName()null);
        orderWindow.show();
      }
    });
    layoutContainer.add(btnBuy);
   
    Button btnSell = new Button("Sell");
    btnSell.addListener(Events.Select, new Listener<ButtonEvent>() {
      public void handleEvent(ButtonEvent e) {
        OrderWindow orderWindow = new OrderWindow(OrderWindow.SELL_ORDER, customer.getCustomerName(), getSelectedHolding());
        orderWindow.show();
      }

    });
    layoutContainer.add(btnSell);
   
    Button btnExit = new Button("Exit");
    btnExit.addListener(Events.Select, new Listener<ButtonEvent>() {
      public void handleEvent(ButtonEvent e) {
        CustomerWindow.this.showWindow(false);
      }
    });
    layoutContainer.add(btnExit);
    add(layoutContainer);
    layoutContainer.setBorders(true);

  }

  private Holding getSelectedHolding() {
    return this.holdingsPanel.getSelectedHolding();
  }
 
  public Customer getCustomer() {
    return customer;
  }

  public void setCustomer(Customer customer) {
    this.customer = customer;
    if (this.customerPanel != null)
      this.customerPanel.setCustomer(this.customer);
    if (this.holdingsPanel != null)
      this.holdingsPanel.setHoldings(this.customer.getHoldingList());
  }

}
TOP

Related Classes of net.helipilot50.stocktrade.client.CustomerWindow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.