Package welcome.client.ui.store

Source Code of welcome.client.ui.store.StoreForm

package welcome.client.ui.store;

import java.util.ArrayList;
import java.util.Iterator;

import welcome.client.GreetingService;
import welcome.client.GreetingServiceAsync;
import welcome.client.ui.Content;
import welcome.client.ui.ContentContainer;
import welcome.client.ui.popup.Popup;

import welcome.shared.store.Store;
import welcome.shared.store.Article;

import com.google.gwt.user.client.Window;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class StoreForm extends Content {

  /**
   * Create a remote service proxy to talk to the server-side Greeting
   * service.
   */
  private final GreetingServiceAsync storeService = GWT.create(GreetingService.class);

  private Store store;

  private FlexTable articleTable = new FlexTable();
  private VerticalPanel mainPanel = new VerticalPanel();
  private CaptionPanel newArticleCptPanel;
  private HorizontalPanel horizontalPanel;
  private Label newNameLabel;
  private TextBox newNameTB;
  private Label newAmountLabel;
  private IntegerBox newAmountTB;
  private Button addBt;
  private Button openInPopupBt;

  public StoreForm() {

//
//    this.storeService.getPersistStore("testStore", new AsyncCallback<Store>() {
//
//      @Override
//      public void onFailure(Throwable caught) {
//        Window.alert(caught.getMessage());
//        System.out.println("onFaillure");
//      }
//
//      @Override
//      public void onSuccess(Store result) {
//       
//       
//        store = result;
//       
//        System.out.println("getting store with "+store.size()+" elements");
//
//        articleTable.setWidget(0, 0, new Label ("Name"));
//        articleTable.setWidget(0, 1,  new Label ("Amount"));
//        articleTable.setWidget(0, 2,  new Label ("Ordering Amount"));
//        articleTable.setWidget(0, 3,  new Label ("Order "));
//        articleTable.setWidget(0, 4,  new Label ("Index Label"));
//       
//       
//        Label nameLabel;
//        Label amountLabel;
//        IntegerBox amountTB;
//        Button removeBT;
////        Label indexLabel;
//
//        Iterator<Article> it = store.iterator();
//        Article currentArticle;
//
//        for (int i = 1; it.hasNext(); i++) {
//
//          currentArticle = it.next();
//          nameLabel = new Label(currentArticle.getName());
//          amountLabel = new Label(String.valueOf(currentArticle.getAmount()));
//
//          amountTB = new IntegerBox();
//          amountTB.setValue(0);
//          amountTB.setWidth("20px");
//          removeBT = new Button("Remove");
//           removeBT.addClickHandler(new ClickHandler() {
//           
//            @Override
//            public void onClick(ClickEvent event) {
//              store.getSupplies().remove(1);
//              sendStoreToDataStore();
//             
//            }
//          });
//         
////          indexLabel = new Label(currentArticle.getId());
//         
//          articleTable.setWidget(i, 0, nameLabel);
//          articleTable.setWidget(i, 1, amountLabel);
//          articleTable.setWidget(i, 2, amountTB);
//          articleTable.setWidget(i, 3, removeBT);
////          articleTable.setWidget(i, 4, indexLabel);
//     
//        }
//      }
//
//
//    });

    mainPanel.add(articleTable);
    initWidget(mainPanel);
    mainPanel.setSize("558px", "126px");

    this.newArticleCptPanel = new CaptionPanel("Add a new article");
    mainPanel.add(this.newArticleCptPanel);

    this.horizontalPanel = new HorizontalPanel();
    this.newArticleCptPanel.setContentWidget(this.horizontalPanel);
    this.horizontalPanel.setSize("506px", "55px");

    this.newNameLabel = new Label("Article Name :");
    this.horizontalPanel.add(this.newNameLabel);
    this.newNameLabel.setWidth("90px");

    this.newNameTB = new TextBox();
    this.horizontalPanel.add(this.newNameTB);
    this.newNameTB.setSize("109px", "18px");

    this.newAmountLabel = new Label("Amount in stock :");
    this.horizontalPanel.add(this.newAmountLabel);

    this.newAmountTB = new IntegerBox();
    this.horizontalPanel.add(this.newAmountTB);
    this.newAmountTB.setSize("30px", "18px");

    this.addBt = new Button("Add");

    this.addBt.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {

        if (newNameTB.getText() != null && newAmountTB.getValue() != null) {
          Article article = new Article(newNameTB.getText(), newAmountTB.getValue());

          store.addArticle(article);
//          sendStoreToDataStore();


        } else
          Window.alert("Cannot add article, please enter valids parameters");
      }


    });
    this.horizontalPanel.add(this.addBt);

    this.openInPopupBt = new Button("Open the store in a popup");
    this.openInPopupBt.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {

        Popup pop = new Popup("The Official Store !!");

        // do not forget a store is a Content and a content is an
        // extension of Widget.
        pop.setContent(new StoreForm());
        pop.center();

      }
    });
    mainPanel.add(this.openInPopupBt);

  }
 
//  private void sendStoreToDataStore() {
//    storeService.persistStore(store, new AsyncCallback<Object>() {
//
//      @Override
//      public void onFailure(Throwable caught) {
//
//        Window.alert(caught.getMessage());
//      }
//
//      @Override
//      public void onSuccess(Object result) {
//
//        ContentContainer.setContent(new StoreForm(), "content");
//      }
//    });
//  }
 
 
}
TOP

Related Classes of welcome.client.ui.store.StoreForm

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.