Example usage for com.google.gwt.http.client RequestBuilder sendRequest

List of usage examples for com.google.gwt.http.client RequestBuilder sendRequest

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder sendRequest.

Prototype

public Request sendRequest(String requestData, RequestCallback callback) throws RequestException 

Source Link

Document

Sends an HTTP request based on the current builder configuration with the specified data and callback.

Usage

From source file:org.eclipselabs.emfjson.gwt.handlers.HttpHandler.java

License:Open Source License

@Override
public void exists(URI uri, Map<?, ?> options, final Callback<Boolean> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.HEAD, URL.encode(uri.toString()));

    try {/*from  www.jav  a 2  s.  c om*/
        builder.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                int code = response.getStatusCode();
                if (code >= 200 && code < 300) {
                    callback.onSuccess(true);
                } else {
                    callback.onSuccess(false);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.freemedsoftware.gwt.client.CurrentState.java

License:Open Source License

/**
 * Set user specific configuration value.
 * /*  w w  w . j a  va  2s  .  co m*/
 * @param key
 * @param value
 */
public static synchronized void setUserConfig(String key, Object value) {
    // Set key locally
    if (value == null) {
        value = new String("");
        JsonUtil.debug("For key = " + key + ", value was null");
    }
    if (value instanceof String) {
        userConfiguration.put(key, (String) value);
    } else if (value instanceof HashMap) {
        userConfiguration.put(key, JsonUtil.jsonify(value));
    } else if (value instanceof Serializable) {
        userConfiguration.put(key, ((Serializable) value).toString());
    } else {
        JsonUtil.debug("Unable to serialize value");
    }

    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // STUBBED mode
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.SetConfigValue",
                        new String[] { key, JsonUtil.jsonify(value) })));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("CurrentState", "Failed to update configuration value.");
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        Util.showInfoMsg("CurrentState", "Updated configuration value.");
                    } else {
                        Util.showErrorMsg("CurrentState", "Failed to update configuration value.");
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("CurrentState", "Failed to update configuration value.");
        }

    } else {
        // GWT-RPC
    }
}

From source file:org.freemedsoftware.gwt.client.CurrentState.java

License:Open Source License

/**
 * Pull user configuration settings into CurrentState object.
 * //from   www. ja va 2  s.c om
 * @param forceReload
 */
public static void retrieveUserConfiguration(boolean forceReload, final Command onLoad) {

    JsonUtil.debug("retrieveUserConfiguration called");

    if (userConfiguration == null || forceReload) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            // STUBBED mode
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetEMRConfiguration",
                            new String[] {})));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                    }

                    @SuppressWarnings("unchecked")
                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode() && !response.getText().contentEquals("[]")) {
                            HashMap<String, Object> r = (HashMap<String, Object>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,Object>");
                            if (r != null) {
                                JsonUtil.debug("successfully retrieved User Configuration");
                                userConfiguration = r;
                                if (userConfiguration.get("usermodules") != null) {
                                    userModules = (HashMap<String, String>) getUserConfig("usermodules",
                                            "HashMap<String,String>");
                                }
                                if (userConfiguration.get("LeftNavigationMenu") != null) {
                                    leftNavigationOptions = (HashMap<String, HashMap<String, Integer>>) JsonUtil
                                            .shoehornJson(
                                                    JSONParser.parseStrict(CurrentState
                                                            .getUserConfig("LeftNavigationMenu").toString()),
                                                    "HashMap<String,HashMap<String,Integer>>");
                                    mainScreen.initMainScreen();
                                }
                                if (onLoad != null) {
                                    onLoad.execute();
                                }
                            }
                        } else {
                            userConfiguration = new HashMap<String, Object>();
                            if (onLoad != null) {
                                onLoad.execute();
                            }
                        }
                    }
                });
            } catch (RequestException e) {
            }

        } else {
            // GWT-RPC
        }
    }
}

From source file:org.freemedsoftware.gwt.client.CurrentState.java

License:Open Source License

/**
 * Pull system configuration settings into CurrentState object.
 * /*from w w w. ja  va2 s .  c o  m*/
 * @param forceReload
 * @param onLoad
 *            - executes command after loading
 */
public static void retrieveSystemConfiguration(boolean forceReload, final Command onLoad) {

    JsonUtil.debug("retrieveUserConfiguration called");

    if (systemConfiguration == null || forceReload || systemConfiguration.size() == 0) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            // STUBBED mode
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util
                    .getJsonRequest("org.freemedsoftware.api.SystemConfig.GetAllSysOptions", new String[] {})));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                    }

                    @SuppressWarnings("unchecked")
                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode() && !response.getText().contentEquals("[]")) {

                            HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (r != null) {
                                JsonUtil.debug("successfully retrieved System Configuration");
                                systemConfiguration = r;
                                reEvaluateSystemConfiguration();
                                if (onLoad != null) {
                                    onLoad.execute();
                                }
                            }
                        } else {
                            systemConfiguration = new HashMap<String, String>();
                            if (onLoad != null) {
                                onLoad.execute();
                            }
                        }
                    }
                });
            } catch (RequestException e) {
            }

        } else {
            // GWT-RPC
        }
    }
}

From source file:org.freemedsoftware.gwt.client.EntryScreenInterface.java

License:Open Source License

/**
 * Set the internal id associated with this form.
 * /*from  w  ww. j a  v a 2 s  .  c om*/
 * @param id
 */
public void setInternalId(Integer id) {
    internalId = id;
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO: Emulate stubbed mode
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { moduleName, JsonUtil.jsonify(id) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleGetRecordMethod", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                        if (r != null) {
                            ui.setValues(r);
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        ModuleInterfaceAsync service = null;
        try {
            service = (ModuleInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface");
        } catch (Exception ex) {
            GWT.log("Exception", ex);
        }
        service.ModuleGetRecordMethod(moduleName, id, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> r) {
                ui.setValues(r);
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.EntryScreenInterface.java

License:Open Source License

public void processData(HashMap<String, String> data) {
    if (internalId.intValue() > 0) {
        JsonUtil.debug("Found internalId, using modify");
        data.put("id", internalId.toString());
    }/* ww  w  .jav a  2 s. co m*/

    if (internalId.intValue() == 0) {
        // Add record
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            Util.showInfoMsg(moduleName, _("Added successfully."));
            if (doneCommand != null) {
                doneCommand.execute();
            }
            closeScreen();
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            String[] params = { moduleName, JsonUtil.jsonify(data) };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleAddMethod", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Util.showErrorMsg(moduleName, _("Failed to add record."));
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {
                            Integer r = (Integer) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                            if (r != null) {
                                Util.showInfoMsg(moduleName, _("Added successfully."));
                                if (doneCommand != null) {
                                    doneCommand.execute();
                                }
                                closeScreen();
                            }
                        } else {
                            Util.showErrorMsg(moduleName, _("Failed to add record."));
                        }
                    }
                });
            } catch (RequestException e) {
                Util.showErrorMsg(moduleName, _("Failed to add record."));
            }
        } else {
            ModuleInterfaceAsync service = null;
            try {
                service = (ModuleInterfaceAsync) Util
                        .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface");
            } catch (Exception ex) {
                GWT.log("Exception", ex);
            }
            service.ModuleAddMethod(moduleName, data, new AsyncCallback<Integer>() {
                public void onSuccess(Integer r) {
                    Util.showInfoMsg(moduleName, "Added successfully.");
                    if (doneCommand != null) {
                        doneCommand.execute();
                    }
                    closeScreen();
                }

                public void onFailure(Throwable t) {
                    GWT.log("Exception", t);
                }
            });
        }
    } else {
        // Modify record
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            Util.showInfoMsg(moduleName, "Modified successfully.");
            closeScreen();
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            String[] params = { moduleName, JsonUtil.jsonify(data) };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleModifyMethod", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Util.showErrorMsg(moduleName, _("Failed to modify record."));
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {
                            Boolean r = (Boolean) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                            if (r != false && r != null) {
                                Util.showInfoMsg(moduleName, "Modified successfully");
                                if (doneCommand != null) {
                                    doneCommand.execute();
                                }
                                closeScreen();
                            } else {
                                Util.showErrorMsg(moduleName, _("Failed to modify record."));
                            }
                        } else {
                            Util.showErrorMsg(moduleName, _("Failed to modify record."));
                        }
                    }
                });
            } catch (RequestException e) {
            }
        } else {
            ModuleInterfaceAsync service = null;
            try {
                service = (ModuleInterfaceAsync) Util
                        .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface");
            } catch (Exception ex) {
                GWT.log("Exception", ex);
            }
            service.ModuleModifyMethod(moduleName, data, new AsyncCallback<Integer>() {
                public void onSuccess(Integer r) {
                    Util.showInfoMsg(moduleName, _("Modified successfully."));
                    if (doneCommand != null) {
                        doneCommand.execute();
                    }
                    closeScreen();
                }

                public void onFailure(Throwable t) {
                    GWT.log("Exception", t);
                }
            });
        }
    }

}

From source file:org.freemedsoftware.gwt.client.FreemedInterface.java

License:Open Source License

/**
 * This is the entry point method./*from   www.  j  av  a  2 s. co m*/
 */
public void onModuleLoad() {
    Log.setUncaughtExceptionHandler();

    // Test to make sure we're logged in
    loginDialog = new LoginDialog();
    loginDialog.setFreemedInterface(this);
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Skip checking for logged in...
        // loginDialog.center();
        resume();
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = {};
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.public.Login.LoggedIn", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        Boolean r = (Boolean) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                "Boolean");
                        if (r != null) {
                            if (r.booleanValue()) {
                                // If logged in, continue
                                resume();
                            } else {
                                // Force login loop
                                loginDialog.center();
                                loginDialog.setFocusToUserField();
                            }
                        } else {
                            loginDialog.center();
                            loginDialog.setFocusToUserField();
                        }
                    } else {
                        Window.alert(response.toString());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        LoginAsync service = null;
        try {
            service = (LoginAsync) Util.getProxy("org.freemedsoftware.gwt.client.Public.Login");

            service.LoggedIn(new AsyncCallback<Boolean>() {
                public void onSuccess(Boolean result) {
                    if (result.booleanValue()) {
                        // If logged in, continue
                        resume();
                    } else {
                        // Force login loop
                        loginDialog.center();
                    }
                }

                public void onFailure(Throwable t) {
                    Window.alert(t.getMessage());
                    /*
                     * Window .alert("Unable to contact RPC service, try
                     * again later.");
                     */
                }
            });
        } catch (Exception e) {
            Window.alert("exception: " + e.getMessage());
        }
    }
}

From source file:org.freemedsoftware.gwt.client.i18n.I18nUtil.java

License:Open Source License

/**
 * Load language definitions from the server.
 * //from   w w w . j a v  a 2 s .  c om
 * @param localeName
 * @param callback
 */
public static void loadLocale(String localeName, final Command callback) {
    String loadFrom = RESOURCES_DIR + localeName + ".json";
    loadedLocaleName = localeName;
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(loadFrom));
    BUSY_LOADING = true;
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                BUSY_LOADING = false;
                JsonUtil.debug(exception.toString());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    long beginTime = System.currentTimeMillis();
                    JSONValue o = JSONParser.parseStrict(response.getText());
                    if (o.isObject() != null) {
                        JsonUtil.debug("Bad data presented.");
                        BUSY_LOADING = false;
                    }

                    // Empty out *everything* we have now.
                    locale.clear();

                    // Import everything
                    for (String key : ((JSONObject) o).keySet()) {
                        if (((JSONObject) o).get(key) != null) {
                            locale.put(key, ((JSONString) ((JSONObject) o).get(key)).stringValue());
                        }
                    }

                    long endTime = System.currentTimeMillis();

                    JsonUtil.debug("Locale " + loadedLocaleName + " parsed and loaded in "
                            + (endTime - beginTime) + "ms");

                    BUSY_LOADING = false;
                } else {
                    BUSY_LOADING = false;
                    JsonUtil.debug(response.getStatusText());
                }

                if (callback != null) {
                    callback.execute();
                }
            }
        });
    } catch (RequestException e) {
        BUSY_LOADING = false;
        JsonUtil.debug(e.toString());
        if (callback != null) {
            callback.execute();
        }
    }
}

From source file:org.freemedsoftware.gwt.client.LoginDialog.java

License:Open Source License

public LoginDialog() {
    try {/*w ww  .jav  a  2 s . c om*/
        service = (LoginAsync) Util.getProxy("org.freemedsoftware.gwt.client.Public.Login");
    } catch (Exception e) {
        GWT.log("Caught exception: ", e);
    }

    final AbsolutePanel absolutePanel = new AbsolutePanel();
    absolutePanel.setTitle("Login");
    absolutePanel.setStylePrimaryName("loginPanel");
    absolutePanel.setStyleName("loginPanel");
    absolutePanel.setSize("300px", "300px");

    final Label userLabel = new Label(_("User Name"));
    absolutePanel.add(userLabel, 25, 71);
    userLabel.setStylePrimaryName("gwt-Label-RAlign");

    userLogin = new TextBox();
    absolutePanel.add(userLogin, 92, 71);
    userLogin.setSize("139px", "22px");
    userLogin.setStylePrimaryName("freemed-LoginFields");
    userLogin.setText("");
    userLogin.setAccessKey('u');
    userLogin.setTabIndex(1);

    final Label passwordLabel = new Label(_("Password"));
    absolutePanel.add(passwordLabel, 25, 100);
    passwordLabel.setStylePrimaryName("gwt-Label-RAlign");

    loginPassword = new PasswordTextBox();
    absolutePanel.add(loginPassword, 92, 102);
    loginPassword.setSize("139px", "22px");
    loginPassword.setStylePrimaryName("freemed-LoginFields");
    loginPassword.setText("");
    loginPassword.setTabIndex(2);

    final Label facilityLabel = new Label(_("Facility"));
    absolutePanel.add(facilityLabel, 28, 152);
    facilityLabel.setStylePrimaryName("gwt-Label-RAlign");
    facilityLabel.setSize("59px", "19px");

    facilityList = new CustomListBox();
    absolutePanel.add(facilityList, 94, 149);
    facilityList.setSize("191px", "22px");
    facilityList.setStylePrimaryName("freemed-LoginFields");
    facilityList.setTabIndex(3);
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        facilityList.addItem("Mt. Ascutney Hospital Medical Clinic Examination Room", "1");
        facilityList.addItem("Associates in Surgery & Gastroenterology, LLC", "2");
        facilityList.addItem("Valley Regional Hospital", "3");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = {};
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.public.Login.GetLocations", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        String[][] r = (String[][]) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "String[][]");
                        if (r != null) {
                            for (int iter = 0; iter < r.length; iter++) {
                                facilityList.addItem(r[iter][0], r[iter][1]);
                            }
                        }
                    } else {
                        Window.alert(response.toString());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        service.GetLocations(new AsyncCallback<String[][]>() {
            public void onSuccess(String[][] r) {
                for (int iter = 0; iter < r.length; iter++) {
                    facilityList.addItem(r[iter][0], r[iter][1]);
                }
            }

            public void onFailure(Throwable t) {
                Window.alert(t.getMessage());
            }
        });
    }

    final Label languageLabel = new Label(_("Language"));
    absolutePanel.add(languageLabel, 28, 183);
    languageLabel.setStylePrimaryName("gwt-Label-RAlign");
    languageLabel.setSize("59px", "19px");

    languageList = new CustomListBox();
    absolutePanel.add(languageList, 94, 180);
    languageList.setSize("190px", "22px");
    languageList.setStylePrimaryName("freemed-LoginFields");
    languageList.setTabIndex(4);

    // Force load on update
    languageList.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            I18nUtil.loadLocale(languageList.getStoredValue(), new Command() {
                @Override
                public void execute() {
                    JsonUtil.debug("Completed async language load.");
                }
            });
        }
    });

    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        languageList.addItem("English", "en_US");
        languageList.addItem("Deutsch", "de_DE");
        languageList.addItem("Espanol (Mexico)", "es_MX");
        languageList.addItem("Polski", "pl_PL");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = {};
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.public.Login.GetLanguages", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        String[][] r = (String[][]) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "String[][]");
                        if (r != null) {
                            for (int iter = 0; iter < r.length; iter++) {
                                languageList.addItem(r[iter][0], r[iter][1]);
                            }
                        }
                    } else {
                        Window.alert(response.toString());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        service.GetLanguages(new AsyncCallback<String[][]>() {
            public void onSuccess(String[][] r) {
                for (int iter = 0; iter < r.length; iter++) {
                    languageList.addItem(r[iter][0], r[iter][1]);
                }
            }

            public void onFailure(Throwable t) {
                Window.alert(t.toString());
            }
        });
    }

    final Image imageUp = new Image("resources/images/button_on.png");
    imageUp.setSize("100%", "100%");

    final Image imageDown = new Image("resources/images/button_on_down.png");
    imageDown.setSize("100%", "100%");

    loginButton = new PushButton(imageUp, imageDown);
    loginButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent w) {
            attemptLogin();
        }
    });
    loginButton.setTabIndex(5);
    absolutePanel.add(loginButton, 83, 233);
    loginButton.setStylePrimaryName("gwt-LoginButton");

    // final Label loginLabel = new Label("Login");
    // absolutePanel.add(loginLabel, 140, 242);
    // loginLabel.setStylePrimaryName("gwt-Label-RAlign");

    loadingImage = new Image(GWT.getHostPageBaseURL() + "resources/images/login_loading.32x27.gif");
    loadingImage.setVisible(false);
    absolutePanel.add(loadingImage, 185, 237);

    final SimplePanel simplePanel = new SimplePanel();
    simplePanel.setWidget(absolutePanel);

    // Add custom keyboard listener to allow submit from password field.
    loginPassword.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            int keyCode = event.getNativeKeyCode();
            switch (keyCode) {
            case KeyCodes.KEY_ENTER:
                attemptLogin();
                try {
                    ((TextBox) event.getSource()).cancelKey();
                } catch (Exception ex) {
                }
                break;
            default:
                break;
            }
        }
    });

    this.setWidget(simplePanel);

    userLogin.setFocus(true);// set focus to user name input box
}

From source file:org.freemedsoftware.gwt.client.PatientEntryScreenInterface.java

License:Open Source License

public void submitForm() {
    ModuleInterfaceAsync service = getProxy();
    // Form hashmap ...
    final HashMap<String, String> rec = new HashMap<String, String>();
    Iterator<String> iter = setters.keySet().iterator();
    while (iter.hasNext()) {
        String k = iter.next();/*from   w  ww.  j a va2 s  .co  m*/
        JsonUtil.debug("grabbing key " + k + " from setters");
        rec.put(k, setters.get(k).getStoredValue());
    }

    // Set patient ID
    rec.put(patientIdName, patientId.toString());

    // Debug
    JsonUtil.debug("PatientEntryScreenInterface.submitForm() called with : " + JsonUtil.jsonify(rec));

    if (!internalId.equals(new Integer(0))) {
        // Modify
        JsonUtil.debug("PatientEntryScreenInterface.submitForm() attempting modify");
        rec.put("id", (String) internalId.toString());
        if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            String[] params = { getModuleName(), JsonUtil.jsonify(rec) };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleModifyMethod", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Util.showErrorMsg(getModuleName(), "Failed to update.");
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {
                            Integer r = (Integer) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                            if (r != null) {
                                Util.showInfoMsg(getModuleName(), "Updated.");
                            }
                        } else {
                            Util.showErrorMsg(getModuleName(), "Failed to update.");
                        }
                    }
                });
            } catch (RequestException e) {
                Util.showErrorMsg(getModuleName(), "Failed to update.");
            }
        } else { // if programmode == JSONRPC (modify)
            // Modify
            service.ModuleModifyMethod(getModuleName(), rec, new AsyncCallback<Integer>() {
                public void onSuccess(Integer result) {
                    Util.showErrorMsg(getModuleName(), "Failed to update.");
                }

                public void onFailure(Throwable th) {
                    Util.showErrorMsg(getModuleName(), "Failed to update.");
                }
            });
        }
    } else { // if this is an "add" request ...
        JsonUtil.debug("PatientEntryScreenInterface.submitForm() attempting add");
        if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            JsonUtil.debug("Try to build parameters");
            String[] params = { getModuleName(), JsonUtil.jsonify(rec) };
            JsonUtil.debug("Create requestbuilder for " + getModuleName() + ", " + JsonUtil.jsonify(rec));
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleAddMethod", params)));
            JsonUtil.debug("Entering try statement");
            try {
                JsonUtil.debug("Sending request");
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Util.showErrorMsg(getModuleName(), "Failed to add.");
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {
                            Integer r = (Integer) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                            if (r != null) {
                                Util.showInfoMsg(getModuleName(), "Added.");
                            }
                        } else {
                            Util.showErrorMsg(getModuleName(), "Failed to add.");
                        }
                    }
                });
            } catch (RequestException e) {
                Util.showErrorMsg(getModuleName(), "Failed to update.");
            }
        } else { // add clause GWT-RPC
            // Add
            service.ModuleAddMethod(getModuleName(), rec, new AsyncCallback<Integer>() {
                public void onSuccess(Integer result) {
                    Util.showInfoMsg(getModuleName(), "Added.");
                }

                public void onFailure(Throwable th) {
                    Util.showErrorMsg(getModuleName(), "Failed to Add.");
                }
            });
        } // end add cause
    } // if add/mod selector
}