Search in sources :

Example 1 with AbstractCommand

use of org.pentaho.mantle.client.commands.AbstractCommand 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) 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 2 with AbstractCommand

use of org.pentaho.mantle.client.commands.AbstractCommand in project pentaho-platform by pentaho.

the class MantleXul method fetchPluginOverlays.

private void fetchPluginOverlays() {
    AbstractCommand cmd = new AbstractCommand() {

        protected void performOperation(boolean feedback) {
            performOperation();
        }

        protected void performOperation() {
            // $NON-NLS-1$
            final String url = GWT.getHostPageBaseURL() + "api/plugin-manager/overlays";
            RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
            builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            builder.setHeader("accept", "application/json");
            try {
                builder.sendRequest(null, new RequestCallback() {

                    public void onError(Request request, Throwable exception) {
                        Window.alert(exception.getMessage());
                    }

                    public void onResponseReceived(Request request, Response response) {
                        JsArray<JsXulOverlay> jsoverlays = JsXulOverlay.parseJson(JsonUtils.escapeJsonForEval(response.getText()));
                        ArrayList<XulOverlay> overlays = new ArrayList<XulOverlay>();
                        for (int i = 0; i < jsoverlays.length(); i++) {
                            JsXulOverlay o = jsoverlays.get(i);
                            MantleXulOverlay overlay;
                            overlay = new MantleXulOverlay(o.getId(), o.getOverlayUri(), o.getSource(), o.getResourceBundleUri(), Integer.parseInt(o.getPriority()));
                            overlays.add(overlay);
                        }
                        MantleXul.this.addOverlays(overlays);
                        // $NON-NLS-1$
                        final String url = GWT.getHostPageBaseURL() + "plugin/data-access/api/permissions/hasDataAccess";
                        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                        builder.setHeader("accept", "application/json");
                        try {
                            builder.sendRequest(null, new RequestCallback() {

                                public void onError(Request request, Throwable exception) {
                                    Window.alert(exception.getMessage());
                                }

                                public void onResponseReceived(Request request, Response response) {
                                    if (response.getText().equals("true")) {
                                        controller.loadOverlay("dataaccess");
                                    }
                                }
                            });
                        } catch (RequestException e) {
                        // showError(e);
                        }
                    }
                });
            } catch (RequestException e) {
            // showError(e);
            }
        }
    };
    cmd.execute();
}
Also used : JsArray(com.google.gwt.core.client.JsArray) RequestBuilder(com.google.gwt.http.client.RequestBuilder) AbstractCommand(org.pentaho.mantle.client.commands.AbstractCommand) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) XulOverlay(org.pentaho.ui.xul.XulOverlay) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay) RequestCallback(com.google.gwt.http.client.RequestCallback) MantleXulOverlay(org.pentaho.mantle.client.objects.MantleXulOverlay)

Aggregations

Request (com.google.gwt.http.client.Request)2 RequestBuilder (com.google.gwt.http.client.RequestBuilder)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 RequestException (com.google.gwt.http.client.RequestException)2 Response (com.google.gwt.http.client.Response)2 AbstractCommand (org.pentaho.mantle.client.commands.AbstractCommand)2 JsArray (com.google.gwt.core.client.JsArray)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ArrayList (java.util.ArrayList)1 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)1 EmptyRequestCallback (org.pentaho.mantle.client.EmptyRequestCallback)1 MantleXulOverlay (org.pentaho.mantle.client.objects.MantleXulOverlay)1 FileItem (org.pentaho.mantle.client.solutionbrowser.filelist.FileItem)1 XulOverlay (org.pentaho.ui.xul.XulOverlay)1