1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.packtpub.client.ui;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Frame;
import com.packtpub.client.dto.BranchDTO;
import com.packtpub.client.rpc.GWTService;
import com.packtpub.client.rpc.GWTServiceAsync;
/**
*
* @author Shamsuddin
*/
public class BranchForm extends FormPanel {
TextField<String> branchIdField = new TextField<String>();
TextField<String> nameField = new TextField<String>();
TextField<String> locationField = new TextField<String>();
BranchDTO branchDTO;
public BranchForm() {
setHeading("Popay.Net");
setFrame(true);
Frame frame = new Frame("http://www.developpez.com/");
frame.setVisible(true);
setSize(660, 480);
add(frame);
final AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
MessageBox messageBox = new MessageBox();
@Override
public void onFailure(Throwable caught) {
messageBox.setMessage("An error occured! Cannot complete the operation");
messageBox.show();
}
@Override
public void onSuccess(Boolean result) {
if (result) {
messageBox.setMessage("Operation completed successfully");
} else {
messageBox.setMessage("An error occured! Cannot complete compltet the operation");
}
messageBox.show();
}
};
saveButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
branchDTO = new BranchDTO();
branchDTO.setBranchId(Integer.parseInt(branchIdField.getValue()));
branchDTO.setName(nameField.getValue());
branchDTO.setLocation(locationField.getValue());
((GWTServiceAsync) GWT.create(GWTService.class)).addBranch(branchDTO, callback);
}
});
final AsyncCallback<BranchDTO> callbackFind = new AsyncCallback<BranchDTO>() {
@Override
public void onFailure(Throwable caught) {
MessageBox messageBox = new MessageBox();
messageBox.setMessage("An error occured! Cannot complete the operation");
messageBox.show();
clear();
}
@Override
public void onSuccess(BranchDTO result) {
branchDTO = result;
if (result != null) {
branchIdField.setValue("" + branchDTO.getBranchId());
nameField.setValue(branchDTO.getName());
locationField.setValue(branchDTO.getLocation());
} else {
MessageBox messageBox = new MessageBox();
messageBox.setMessage("No such Branch found");
messageBox.show();
clear();
}
}
};
findButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
MessageBox inputBox = MessageBox.prompt("Input", "Enter the Branch ID");
inputBox.addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
int branchId = Integer.parseInt(be.getValue());
((GWTServiceAsync) GWT.create(GWTService.class)).findBranch(branchId, callbackFind);
}
});
}
});
updateButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
branchDTO.setName(nameField.getValue());
branchDTO.setLocation(locationField.getValue());
((GWTServiceAsync) GWT.create(GWTService.class)).updateBranch(branchDTO, callback);
clear();
}
});
deleteButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
((GWTServiceAsync) GWT.create(GWTService.class)).deleteBranch(branchDTO.getBranchId(), callback);
clear();
}
});
}
} |
Partager