Search in sources :

Example 1 with MantleXulOverlay

use of org.pentaho.mantle.client.objects.MantleXulOverlay 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

JsArray (com.google.gwt.core.client.JsArray)1 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 ArrayList (java.util.ArrayList)1 AbstractCommand (org.pentaho.mantle.client.commands.AbstractCommand)1 MantleXulOverlay (org.pentaho.mantle.client.objects.MantleXulOverlay)1 XulOverlay (org.pentaho.ui.xul.XulOverlay)1