Search in sources :

Example 61 with RequestBuilder

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

the class ShowBrowserCommand method execute.

public void execute() {
    final SolutionBrowserPanel solutionBrowserPerspective = SolutionBrowserPanel.getInstance();
    solutionBrowserPerspective.setNavigatorShowing(state);
    if (PerspectiveManager.getInstance().getActivePerspective().getId().equalsIgnoreCase(PerspectiveManager.OPENED_PERSPECTIVE)) {
        PerspectiveManager.getInstance().setPerspective(PerspectiveManager.OPENED_PERSPECTIVE);
    }
    String url = GWT.getHostPageBaseURL() + "api/user-settings/MANTLE_SHOW_NAVIGATOR";
    RequestBuilder builder = new CsrfRequestBuilder(RequestBuilder.POST, url);
    try {
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.sendRequest("" + state, EmptyRequestCallback.getInstance());
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) RequestException(com.google.gwt.http.client.RequestException) SolutionBrowserPanel(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel)

Example 62 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder 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 63 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder 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 64 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder 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 65 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder 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

RequestBuilder (com.google.gwt.http.client.RequestBuilder)132 RequestException (com.google.gwt.http.client.RequestException)116 RequestCallback (com.google.gwt.http.client.RequestCallback)113 Response (com.google.gwt.http.client.Response)111 Request (com.google.gwt.http.client.Request)110 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)27 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)22 JSONString (com.google.gwt.json.client.JSONString)19 ArrayList (java.util.ArrayList)16 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)13 JSONObject (com.google.gwt.json.client.JSONObject)11 JsArrayString (com.google.gwt.core.client.JsArrayString)9 JSONArray (com.google.gwt.json.client.JSONArray)8 List (java.util.List)8 HTML (com.google.gwt.user.client.ui.HTML)7 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)7 EmptyRequestCallback (org.pentaho.mantle.client.EmptyRequestCallback)7 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)6 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)6