// At the StateMachine
@Override
protected void onMain_BtnLoginAction(Component c, ActionEvent event) {
if (findTxtUsername().getText().equals("") || findTxtPassword().getText().equals("")) {
Dialog.show("Notification:", "Please fill all required fields", "OK", null);
} else {
authenticationData.setUsername(findTxtUsername().getText());
authenticationData.setPassword(findTxtPassword().getText());
MyCustomersService.authenticateAndGetData();
}
}
// At the MyCustomersService
public static void authenticateAndGetData() {
MyCustomersRequestHandler myCustomersRequestHandler = new MyCustomersRequestHandler();
InfiniteProgress infiniteProgress = new InfiniteProgress();
Dialog dialog = infiniteProgress.showInifiniteBlocking();
myCustomersRequestHandler.setPost(false);
myCustomersRequestHandler.setUrl(/////);
myCustomersRequestHandler.addArgument("username",
StateMachine.getAuthenticationData().getUsername());
myCustomersRequestHandler.addArgument("password", StateMachine.getAuthenticationData().getPassword());
myCustomersRequestHandler.setDisposeOnCompletion(dialog);
NetworkManager.getInstance().addToQueue(myCustomersRequestHandler);
}
// At MyCustomersResponseHandler
@Override
protected void postResponse() {
NetworkManager.getInstance().shutdown();
if (AuthenticationParser.isAuthorized(getDocument())) {
StateMachine.setMyCustomersResponces(MyCustomerResponseParser.parseElementToObject(getDocument()));
StateMachine.getStateMachine().showForm("Home", null);
} else {
StateMachine.getStateMachine().showForm("Main", null);
}
}
@Override
protected void readResponse(InputStream inputStream) throws IOException {
if (inputStream != null) {
setDocument(SimpleXMLParser.parseInputStream(inputStream));
}
}
// At the StateMachine
@Override
protected void beforeHome(Form f) {
MyCustomersService.populateMyCustomers();
}