Example usage for com.google.gwt.http.client URL encode

List of usage examples for com.google.gwt.http.client URL encode

Introduction

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

Prototype

public static String encode(String decodedURL) 

Source Link

Document

Returns a string where all characters that are not valid for a complete URL have been escaped.

Usage

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

License:Open Source License

/**
 * Pull user configuration settings into CurrentState object.
 * /*from ww w.  jav  a2  s . c  o  m*/
 * @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 ww w  .  j ava2s.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.
 * //  w w w.j ava  2s. c o  m
 * @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());
    }//from  w w  w . ja v  a 2 s .  c om

    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 w w w.j a v a2s.c  om*/
 */
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.
 * // w  w w . j a v a2s  . 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 {//from  w ww. ja va 2s.co  m
        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();//w  w  w. j  av a 2 s  .c  o  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
}

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

License:Open Source License

/**
 * Internal method to load stock data into form.
 */// w w w. j  a v a2  s .co m
protected void loadData() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // STUB
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { getModuleName(), internalId.toString() };
        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) {
                    Util.showErrorMsg(getModuleName(), "Failed to load data.");
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    JsonUtil.debug("onResponseReceived");
                    if (200 == response.getStatusCode()) {
                        JsonUtil.debug(response.getText());
                        HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                        if (r != null) {
                            populateData(r);
                        }
                    } else {
                        Util.showErrorMsg(getModuleName(), "Failed to load data.");
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        ModuleInterfaceAsync service = getProxy();
        service.ModuleGetRecordMethod(getModuleName(), internalId,
                new AsyncCallback<HashMap<String, String>>() {
                    public void onSuccess(HashMap<String, String> r) {
                        populateData(r);
                    }

                    public void onFailure(Throwable t) {
                        Util.showErrorMsg(getModuleName(), "Failed to load data.");
                    }
                });
    }
}

From source file:org.freemedsoftware.gwt.client.screen.AccountsReceivableScreen.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void refreshSearch() {
    if (validateForm()) {//validate form first
        sortableTable.clearData();//from  www .  j a  v a  2 s.  c o  m
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            HashMap<String, String> a = new HashMap<String, String>();
            a.put("item_type", "item type1");
            a.put("item", "item 1");
            a.put("patient", "abc");
            a.put("provider", "JEFF");
            a.put("date_of", "1979-08-10");
            a.put("total_balance", "28");
            a.put("payment_date", "1979-09-10");
            a.put("procedure_id", "22");
            a.put("money_out", "200");
            a.put("money_in", "500");
            a.put("id", "1");

            List<HashMap<String, String>> l = new ArrayList<HashMap<String, String>>();
            l.add(a);
            sortableTable.loadData((HashMap<String, String>[]) l.toArray(new HashMap<?, ?>[0]));
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            HashMap<String, String> criteria = populateCreteria();

            String[] params = { JsonUtil.jsonify(criteria) };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.api.Ledger.AgingReportQualified", 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 (Util.checkValidSessionResponse(response.getText())) {
                            if (200 == response.getStatusCode()) {
                                HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                "HashMap<String,String>[]");
                                if (result.length > 0) {
                                    sortableTableEmptyLabel.setVisible(false);
                                } else {
                                    sortableTableEmptyLabel.setVisible(true);
                                    Util.showErrorMsg(getClass().getName(), _("No record found!"));
                                }
                                sortableTable.loadData(result);
                            } else {
                                Window.alert(response.toString());
                                sortableTableEmptyLabel.setVisible(true);
                            }
                        }
                    }
                });
            } catch (RequestException e) {
                Window.alert(e.toString());
                sortableTableEmptyLabel.setVisible(true);
            }
        } else {

            // TODO normal mode code goes here 
        }
    }
}