Package net.helipilot50.stocktrade.client.vanilla

Source Code of net.helipilot50.stocktrade.client.vanilla.CustomerPanel

package net.helipilot50.stocktrade.client.vanilla;

import net.helipilot50.stocktrade.client.CustomerSO;
import net.helipilot50.stocktrade.client.CustomerSOAsync;
import net.helipilot50.stocktrade.model.Customer;
import net.helipilot50.stocktrade.model.Holding;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.DoubleBox;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment;

public class CustomerPanel extends Composite {
  private final CustomerSOAsync customerSO = GWT
      .create(CustomerSO.class);

  private TextBox phoneField;
  private TextArea addressField;
  private DoubleBox cashBalanceField;
  private TextBox customerNameField;
  private CellTable<Holding> holdingListField;
  private TextColumn<Holding> stockNameColumn;
  private TextColumn<Holding> quantityColumn;
  private TextColumn<Holding> priceColumn;

  private Customer customer = null;
  private HorizontalPanel horizontalPanel;
  private Button buyButton;
  private Button sellButton;
  private Button exitButton;

  public CustomerPanel() {
   
    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    initWidget(verticalPanel);
   
    Grid grid = new Grid(4, 2);
    verticalPanel.add(grid);
   
    Label lblName = new Label("Name");
    grid.setWidget(0, 0, lblName);
   
    customerNameField = new TextBox();
    this.customerNameField.setEnabled(false);
    this.customerNameField.setReadOnly(true);
    grid.setWidget(0, 1, customerNameField);
    customerNameField.setHeight("100%");
   
    Label lblAddress = new Label("Address");
    grid.setWidget(1, 0, lblAddress);
   
    addressField = new TextArea();
    this.addressField.setEnabled(false);
    this.addressField.setReadOnly(true);
    grid.setWidget(1, 1, addressField);
    addressField.setSize("170px", "60px");
   
    Label lblPhone = new Label("Phone");
    grid.setWidget(2, 0, lblPhone);
   
    phoneField = new TextBox();
    this.phoneField.setEnabled(false);
    this.phoneField.setReadOnly(true);
    grid.setWidget(2, 1, phoneField);
   
    Label lblCashBalance = new Label("Cash Balance");
    grid.setWidget(3, 0, lblCashBalance);
   
    cashBalanceField = new DoubleBox();
    this.cashBalanceField.setEnabled(false);
    this.cashBalanceField.setReadOnly(true);
    this.cashBalanceField.setAlignment(TextAlignment.RIGHT);
    grid.setWidget(3, 1, cashBalanceField);
    grid.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
    grid.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    grid.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    grid.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
    grid.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    grid.getCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_TOP);
    grid.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    grid.getCellFormatter().setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_TOP);

    holdingListField = new CellTable<Holding>();
    holdingListField.setPageSize(5);
    verticalPanel.add(holdingListField);
   
    stockNameColumn = new TextColumn<Holding>() {

      @Override
      public String getValue(Holding object) {
        return object.getStockName();
      }
    };
    this.stockNameColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    quantityColumn = new TextColumn<Holding>() {

      @Override
      public String getValue(Holding object) {
        return Integer.toString(object.getQuantity());
      }
    };
    this.quantityColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    priceColumn = new TextColumn<Holding>() {

      @Override
      public String getValue(Holding object) {
        return Float.toString(object.getPrice());
      }
    };
    this.priceColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    holdingListField.addColumn(stockNameColumn, "Stock Name");
    holdingListField.addColumn(quantityColumn, "Quantity");
    holdingListField.addColumn(priceColumn, "Price");
   
    horizontalPanel = new HorizontalPanel();
    horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel.add(horizontalPanel);
   
    buyButton = new Button("Buy");
    buyButton.setText("Buy");
    horizontalPanel.add(buyButton);
   
    this.sellButton = new Button("Sell");
    this.sellButton.setText("Sell");
    this.horizontalPanel.add(this.sellButton);
   
    this.exitButton = new Button("Exit");
    this.exitButton.setText("Exit");
    this.horizontalPanel.add(this.exitButton);
   
  }

  public void loadCustomer(final String name){
    customerSO.getCustomer(name, new AsyncCallback<Customer>() {
     
      @Override
      public void onSuccess(Customer result) {
        setCustomer(result);
       
      }
     
      @Override
      public void onFailure(Throwable caught) {
        Window.alert("Could not load customer " + name + "\nError: " + caught.getMessage());
       
      }
    });
  }
 
  public void saveCustomer(){
   
  }

  public void newCustomer(){
   
  }
 
  private void setCustomer(Customer customer){
    this.customer = customer;
    customerNameField.setText(this.customer.getCustomerName());
    addressField.setText(this.customer.getAddress());
    phoneField.setText(this.customer.getPhoneNumber());
    cashBalanceField.setValue((double) this.customer.getCashBalance());
    ListDataProvider<Holding> dataProvider = new ListDataProvider<Holding>(this.customer.getHoldingList());
    dataProvider.addDataDisplay(holdingListField);
  }

}
TOP

Related Classes of net.helipilot50.stocktrade.client.vanilla.CustomerPanel

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.