Package welcome.client.ui.store

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

package welcome.client.ui.store;

import welcome.client.GreetingService;
import welcome.client.GreetingServiceAsync;
import welcome.client.ui.Content;
import welcome.client.ui.popup.Popup;
import welcome.shared.store.Article;

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.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Grid;



public class ArticleEditor extends Content {
  private CaptionPanel editorCaptionPanel;
  private VerticalPanel horizontalPanel;
  private TextBox nameTB;
  private IntegerBox amoutnTB;
  private Button okButton;
  private Label articleNameLabel;
  private Label amountLabel;
 
  private Long articleId;
  private Article currentArticle;
  private Popup parentPopup;
 
  private final GreetingServiceAsync storeService = GWT.create(GreetingService.class);
  private Grid grid;
 
  public ArticleEditor(Long articleId2, Popup parentPopup2) {
   
    this.articleId=articleId2;
    this.parentPopup=parentPopup2;
    this.editorCaptionPanel = new CaptionPanel("Edit Article");
    initWidget(this.editorCaptionPanel);
    this.editorCaptionPanel.setSize("304px", "190px");
   
    this.horizontalPanel = new VerticalPanel();
    this.editorCaptionPanel.setContentWidget(this.horizontalPanel);
    this.horizontalPanel.setSize("239px", "136px");
   
    this.grid = new Grid(3, 2);
    this.horizontalPanel.add(this.grid);
    this.grid.setSize("267px", "149px");
   
    this.articleNameLabel = new Label("Name :");
    this.grid.setWidget(0, 0, this.articleNameLabel);
   
    this.nameTB = new TextBox();
    this.grid.setWidget(0, 1, this.nameTB);
    this.nameTB.setSize("200px", "18px");
   
    this.amountLabel = new Label("Amount :");
    this.grid.setWidget(1, 0, this.amountLabel);
   
    this.amoutnTB = new IntegerBox();
    this.grid.setWidget(1, 1, this.amoutnTB);
    this.amoutnTB.setSize("200px", "18px");
   
    this.okButton = new Button("OK");
    this.grid.setWidget(2, 1, this.okButton);
    this.okButton.setSize("54px", "33px");
   
    this.okButton.addClickHandler(new ClickHandler() {
     
      @Override
      public void onClick(ClickEvent event) {
       
        storeService.updateArticle(articleId, nameTB.getText(), amoutnTB.getValue(), new AsyncCallback<Object>() {

          @Override
          public void onFailure(Throwable caught) {
            Window.alert(caught.getMessage());
           
          }

          @Override
          public void onSuccess(Object result) {
           
            parentPopup.setVisible(false);
           
          }
        });
       
      }
    });
   
 
   
   
    this.storeService.getArticle(articleId, new AsyncCallback<Article>() {
     
      @Override
      public void onSuccess(Article result) {
        currentArticle = result;
        nameTB.setText(currentArticle.getName());
        amoutnTB.setValue(currentArticle.getAmount());
      }
     
      @Override
      public void onFailure(Throwable caught) {
        Window.alert(caught.getMessage());
       
      }
    });
   
   
  }

 
 
 
}
TOP

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

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.