Search in sources :

Example 81 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class RunInBackgroundCommand method checkSchedulePermissionAndDialog.

protected void checkSchedulePermissionAndDialog() {
    // $NON-NLS-1$
    final String url = getFullyQualifiedURL() + "api/scheduler/isScheduleAllowed?id=" + repositoryFile.getRepositoryFile().getId();
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    final MessageDialogBox errorDialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("noSchedulePermission"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
    true);
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable caught) {
                errorDialog.center();
            }

            public void onResponseReceived(Request request, Response response) {
                if ("true".equalsIgnoreCase(response.getText())) {
                    showDialog(true);
                } else {
                    errorDialog.center();
                }
            }
        });
    } catch (RequestException re) {
        errorDialog.center();
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException)

Example 82 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class SwitchThemeCommand method performOperation.

protected void performOperation(boolean feedback) {
    final HTML messageTextBox = new HTML(Messages.getString("confirmSwitchTheme.message"));
    final PromptDialogBox fileMoveToTrashWarningDialogBox = new PromptDialogBox(Messages.getString("confirmSwitchTheme.title"), Messages.getString("confirmSwitchTheme.ok"), Messages.getString("confirmSwitchTheme.cancel"), true, true);
    fileMoveToTrashWarningDialogBox.setContent(messageTextBox);
    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
        }

        public void okPressed() {
            // $NON-NLS-1$
            final String url = GWT.getHostPageBaseURL() + "api/theme/set";
            RequestBuilder setThemeRequestBuilder = new CsrfRequestBuilder(RequestBuilder.POST, url);
            setThemeRequestBuilder.setHeader("accept", "text/plain");
            setThemeRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            try {
                setThemeRequestBuilder.sendRequest(theme, new RequestCallback() {

                    public void onError(Request request, Throwable exception) {
                    // showError(exception);
                    }

                    public void onResponseReceived(Request request, Response response) {
                        // forcing a setTimeout to fix a problem in IE BISERVER-6385
                        Scheduler.get().scheduleDeferred(new Command() {

                            public void execute() {
                                Window.Location.reload();
                            }
                        });
                    }
                });
            } catch (RequestException e) {
                Window.alert(e.getMessage());
            // showError(e);
            }
        }
    };
    fileMoveToTrashWarningDialogBox.setCallback(callback);
    fileMoveToTrashWarningDialogBox.center();
}
Also used : Response(com.google.gwt.http.client.Response) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) Command(com.google.gwt.user.client.Command) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) Request(com.google.gwt.http.client.Request) HTML(com.google.gwt.user.client.ui.HTML) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) RequestException(com.google.gwt.http.client.RequestException)

Example 83 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class SolutionBrowserPanel method initializeExecutableFileTypes.

protected void initializeExecutableFileTypes() {
    final String moduleBaseURL = GWT.getModuleBaseURL();
    final String moduleName = GWT.getModuleName();
    final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    // $NON-NLS-1$
    final String url = contextURL + "api/repos/executableTypes";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    JSONObject jsonObject = (JSONObject) JSONParser.parse(response.getText());
                    JSONArray jsonList = (JSONArray) jsonObject.get("executableFileTypeDto");
                    for (int i = 0; i < jsonList.size(); i++) {
                        JSONObject executableType = (JSONObject) jsonList.get(i);
                        executableFileExtensions.add(executableType.get("extension").isString().stringValue());
                    }
                }
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) JSONObject(com.google.gwt.json.client.JSONObject) Request(com.google.gwt.http.client.Request) JSONArray(com.google.gwt.json.client.JSONArray) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException)

Example 84 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class SolutionBrowserPanel method executeActionSequence.

public void executeActionSequence(final FileCommand.COMMAND mode) {
    if (filesListPanel.getSelectedFileItems() == null || filesListPanel.getSelectedFileItems().size() != 1) {
        return;
    }
    // open in content panel
    AbstractCommand authCmd = new AbstractCommand() {

        protected void performOperation() {
            performOperation(false);
        }

        protected void performOperation(boolean feedback) {
            final FileItem selectedFileItem = filesListPanel.getSelectedFileItems().get(0);
            String url = null;
            url = // $NON-NLS-1$ //$NON-NLS-2$
            "api/repo/files/" + SolutionBrowserPanel.pathToId(filesListPanel.getSelectedFileItems().get(0).getRepositoryFile().getPath()) + "/generatedContent";
            url = getPath() + url;
            if (mode == FileCommand.COMMAND.BACKGROUND) {
                MessageDialogBox dialogBox = new // $NON-NLS-1$
                MessageDialogBox(// $NON-NLS-1$
                Messages.getString("info"), // $NON-NLS-1$
                Messages.getString("backgroundExecutionWarning"), true, false, true);
                dialogBox.center();
                // $NON-NLS-1$
                url += "&background=true";
                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                try {
                    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                    builder.sendRequest(null, new RequestCallback() {

                        public void onError(Request request, Throwable exception) {
                            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), Messages.getString("couldNotBackgroundExecute"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                            true);
                            dialogBox.center();
                        }

                        public void onResponseReceived(Request request, Response response) {
                        }
                    });
                } catch (RequestException e) {
                // ignored
                }
            } else if (mode == FileCommand.COMMAND.NEWWINDOW) {
                // popup blockers might attack this
                // $NON-NLS-1$ //$NON-NLS-2$
                Window.open(url, "_blank", "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no");
            } else if (mode == FileCommand.COMMAND.SUBSCRIBE) {
                // $NON-NLS-1$
                final String myurl = url + "&subscribepage=yes";
                contentTabPanel.showNewURLTab(selectedFileItem.getLocalizedName(), selectedFileItem.getLocalizedName(), myurl, true);
            } else {
                contentTabPanel.showNewURLTab(selectedFileItem.getLocalizedName(), selectedFileItem.getLocalizedName(), url, true);
            }
        }
    };
    authCmd.execute();
}
Also used : Response(com.google.gwt.http.client.Response) FileItem(org.pentaho.mantle.client.solutionbrowser.filelist.FileItem) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) AbstractCommand(org.pentaho.mantle.client.commands.AbstractCommand) Request(com.google.gwt.http.client.Request) JsArrayString(com.google.gwt.core.client.JsArrayString) RequestException(com.google.gwt.http.client.RequestException)

Example 85 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class FilePropertiesDialog method applyPanel.

/**
 */
private void applyPanel() {
    ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>();
    for (int i = 0; i < propertyTabs.getTabCount(); i++) {
        Widget w = propertyTabs.getTab(i).getContent();
        if (w instanceof IFileModifier) {
            // get requests from sub panels
            if (((IFileModifier) w).prepareRequests() != null) {
                requestBuilders.addAll(((IFileModifier) w).prepareRequests());
            }
        }
    }
    RequestCallback requestCallback;
    // chain requests from subpanels using callbacks to try and avoid any StaleItemStateExceptions
    for (int i = 0; i <= requestBuilders.size() - 1; i++) {
        RequestBuilder requestBuilder = requestBuilders.get(i);
        if (i < requestBuilders.size() - 1) {
            final RequestBuilder nextRequest = requestBuilders.get(i + 1);
            // This header is required to force Internet Explorer to not cache values from the GET response.
            nextRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            requestCallback = new ChainedRequestCallback(nextRequest);
        } else {
            requestCallback = new RequestCallback() {

                @Override
                public void onError(Request request, Throwable th) {
                    WaitPopup.getInstance().setVisible(false);
                    MessageDialogBox dialogBox = // $NON-NLS-1$
                    new MessageDialogBox(Messages.getString("error"), th.toString(), false, false, true);
                    dialogBox.center();
                }

                @Override
                public void onResponseReceived(Request arg0, Response arg1) {
                    WaitPopup.getInstance().setVisible(false);
                    if (arg1.getStatusCode() == Response.SC_OK) {
                        dirty = false;
                        // Refresh current folder or parent folder
                        PerspectiveManager.getInstance().setPerspective(PerspectiveManager.BROWSER_PERSPECTIVE);
                        GenericEvent ge = new GenericEvent();
                        ge.setEventSubType("RefreshFolderEvent");
                        ge.setStringParam(parentPath);
                        EventBusUtil.EVENT_BUS.fireEvent(ge);
                    } else {
                        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), Messages.getString("operationPermissionDenied"), false, false, // $NON-NLS-1$
                        true);
                        dialogBox.center();
                    }
                }
            };
        }
        requestBuilder.setCallback(requestCallback);
    }
    // start the chain
    try {
        if (!requestBuilders.isEmpty()) {
            WaitPopup.getInstance().setVisible(true);
            requestBuilders.get(0).send();
        }
    } catch (RequestException e) {
    // ignored
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) ArrayList(java.util.ArrayList) Widget(com.google.gwt.user.client.ui.Widget) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) GenericEvent(org.pentaho.mantle.client.events.GenericEvent)

Aggregations

RequestCallback (com.google.gwt.http.client.RequestCallback)175 Response (com.google.gwt.http.client.Response)170 Request (com.google.gwt.http.client.Request)169 RequestException (com.google.gwt.http.client.RequestException)162 RequestBuilder (com.google.gwt.http.client.RequestBuilder)113 JSONException (com.google.gwt.json.client.JSONException)55 HttpException (com.willshex.gson.web.service.client.HttpException)55 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)16 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)14 BlockUsersRequest (com.willshex.blogwt.shared.api.user.call.BlockUsersRequest)12 BlockUsersResponse (com.willshex.blogwt.shared.api.user.call.BlockUsersResponse)12 ChangePasswordRequest (com.willshex.blogwt.shared.api.user.call.ChangePasswordRequest)12 ChangePasswordResponse (com.willshex.blogwt.shared.api.user.call.ChangePasswordResponse)12 ChangeUserAccessRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessRequest)12 ChangeUserAccessResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessResponse)12 ChangeUserDetailsRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsRequest)12 ChangeUserDetailsResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsResponse)12 CheckUsernameRequest (com.willshex.blogwt.shared.api.user.call.CheckUsernameRequest)12 CheckUsernameResponse (com.willshex.blogwt.shared.api.user.call.CheckUsernameResponse)12 FollowUsersRequest (com.willshex.blogwt.shared.api.user.call.FollowUsersRequest)12