Example usage for com.google.gwt.http.client RequestBuilder GET

List of usage examples for com.google.gwt.http.client RequestBuilder GET

Introduction

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

Prototype

Method GET

To view the source code for com.google.gwt.http.client RequestBuilder GET.

Click Source Link

Document

Specifies that the HTTP GET method should be used.

Usage

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel.java

License:Open Source License

public void openFile(final String fileNameWithPath, final FileCommand.COMMAND mode) {
    final String moduleBaseURL = GWT.getModuleBaseURL();
    final String moduleName = GWT.getModuleName();
    final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    final String path = fileNameWithPath; // Expecting some encoding here
    final String url = contextURL + "api/repo/files/" + pathToId(path) + "/properties"; //$NON-NLS-1$

    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 {// ww w.j  av  a2  s  .  c o  m
        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 = new JSONObject();
                    jsonObject.put("repositoryFileDto",
                            (JSONObject) JSONParser.parseLenient(response.getText()));
                    RepositoryFile repositoryFile = new RepositoryFile(jsonObject);
                    openFile(repositoryFile, mode);
                }
            }
        });
    } catch (RequestException e) {
        // showError(e);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel.java

License:Open Source License

protected void initializeExecutableFileTypes() {
    final String moduleBaseURL = GWT.getModuleBaseURL();
    final String moduleName = GWT.getModuleName();
    final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    final String url = contextURL + "api/repos/executableTypes"; //$NON-NLS-1$
    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 {//from w  w  w .  j a  va 2  s .c  om
        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);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPanel.java

License:Open Source License

public void executeActionSequence(final FileCommand.COMMAND mode) {
    if (filesListPanel.getSelectedFileItems() == null || filesListPanel.getSelectedFileItems().size() != 1) {
        return;/*from  w w  w.  jav  a2s.  co  m*/
    }

    // 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 = "api/repo/files/" //$NON-NLS-1$
                    + SolutionBrowserPanel.pathToId(
                            filesListPanel.getSelectedFileItems().get(0).getRepositoryFile().getPath())
                    + "/generatedContent"; //$NON-NLS-1$
            url = getPath() + url;

            if (mode == FileCommand.COMMAND.BACKGROUND) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), //$NON-NLS-1$
                        Messages.getString("backgroundExecutionWarning"), //$NON-NLS-1$
                        true, false, true);
                dialogBox.center();

                url += "&background=true"; //$NON-NLS-1$

                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"), //$NON-NLS-1$
                                    Messages.getString("couldNotBackgroundExecute"), false, false, true); //$NON-NLS-1$
                            dialogBox.center();
                        }

                        public void onResponseReceived(Request request, Response response) {
                        }

                    });
                } catch (RequestException e) {
                    // ignored
                }
            } else if (mode == FileCommand.COMMAND.NEWWINDOW) {
                // popup blockers might attack this
                Window.open(url, "_blank", "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$ //$NON-NLS-2$
            } else if (mode == FileCommand.COMMAND.SUBSCRIBE) {
                final String myurl = url + "&subscribepage=yes"; //$NON-NLS-1$
                contentTabPanel.showNewURLTab(selectedFileItem.getLocalizedName(),
                        selectedFileItem.getLocalizedName(), myurl, true);
            } else {
                contentTabPanel.showNewURLTab(selectedFileItem.getLocalizedName(),
                        selectedFileItem.getLocalizedName(), url, true);
            }
        }

    };

    authCmd.execute();
}

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPerspective.java

License:Open Source License

/**
 * The passed in URL has all the parameters set for background execution. We
 * simply call GET on the URL and handle the response object. If the response
 * object contains a particular string then we display success message box.
 * //from w w  w  .  ja  v  a2s  . c  om
 * @param url
 *          Complete url with all the parameters set for scheduling a job in
 *          the background.
 */
private void runInBackground(final String url) {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                /*
                 * We are checking for this specific string because if the job was
                 * scheduled successfully by QuartzBackgroundExecutionHelper then the
                 * response is an html that contains the specific string. We have
                 * coded this way because we did not want to touch the old way.
                 */
                if ("true".equals(response.getHeader("background_execution"))) {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), //$NON-NLS-1$
                            Messages.getString("backgroundJobScheduled"), false, false, true); //$NON-NLS-1$
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                Messages.getString("couldNotBackgroundExecute"), false, false, true); //$NON-NLS-1$
        dialogBox.center();
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPerspective.java

License:Open Source License

@SuppressWarnings("unchecked")
public void openFile(String path, String name, String localizedFileName, FileCommand.COMMAND mode) {
    ArrayList<String> pathSegments = solutionTree.getPathSegments(path);
    final boolean fileExists = solutionTree.doesFileExist(pathSegments, name);
    if (!fileExists) {
        final MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("open"), //$NON-NLS-1$
                Messages.getString("fileDoesNotExist", name), false, false, true); //$NON-NLS-1$
        dialogBox.center();//from  w w w  .  j  a  va  2s .  com
        return;
    }

    String repoPath = ""; //$NON-NLS-1$
    for (int i = 1; i < pathSegments.size(); i++) {
        repoPath += "/" + pathSegments.get(i); //$NON-NLS-1$
    }

    FileItem selectedFileItem = new FileItem(name, localizedFileName, localizedFileName, pathSegments.get(0),
            repoPath, "", null, null, null, false, null); //$NON-NLS-1$
    filesListPanel.setSelectedFileItem(selectedFileItem);

    solutionTree.setSelectedItem(null);
    FileTreeItem fileTreeItem = solutionTree.getTreeItem(pathSegments);
    solutionTree.setSelectedItem(fileTreeItem, true);

    TreeItem tmpTreeItem = fileTreeItem;
    while (tmpTreeItem != null) {
        tmpTreeItem.setState(true);
        tmpTreeItem = tmpTreeItem.getParentItem();
    }
    fileTreeItem.setSelected(true);

    ArrayList<com.google.gwt.xml.client.Element> files = (ArrayList<com.google.gwt.xml.client.Element>) fileTreeItem
            .getUserObject();
    if (files != null) {
        for (com.google.gwt.xml.client.Element fileElement : files) {
            if (name.equals(fileElement.getAttribute("name")) //$NON-NLS-1$
                    || name.equals(fileElement.getAttribute("localized-name"))) { //$NON-NLS-1$
                selectedFileItem.setURL(fileElement.getAttribute("url")); //$NON-NLS-1$
            }
        }
    }

    if (mode == FileCommand.COMMAND.EDIT) {
        editFile();
    } else if (mode == FileCommand.COMMAND.SCHEDULE_NEW) {
        ScheduleHelper.createSchedule(filesListPanel.getSelectedFileItem());
    } else if (mode == FileCommand.COMMAND.SHARE) {
        (new ShareFileCommand()).execute();
    } else {
        if (name.endsWith(".xaction")) { //$NON-NLS-1$
            executeActionSequence(mode);
            // contentTabPanel.setFileInfoInFrame(filesListPanel.getSelectedFileItem());
        } else if (name.endsWith(".url")) { //$NON-NLS-1$
            if (mode == FileCommand.COMMAND.NEWWINDOW) {
                Window.open(filesListPanel.getSelectedFileItem().getURL(), "_blank", //$NON-NLS-1$
                        "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
            } else {
                contentTabPanel.showNewURLTab(filesListPanel.getSelectedFileItem().getLocalizedName(),
                        filesListPanel.getSelectedFileItem().getLocalizedName(),
                        filesListPanel.getSelectedFileItem().getURL(), true);
            }
        } else {
            // see if this file is a plugin
            ContentTypePlugin plugin = PluginOptionsHelper
                    .getContentTypePlugin(filesListPanel.getSelectedFileItem().getName());
            if (plugin != null && plugin.hasCommand(mode)) {
                // load the editor for this plugin
                String url = plugin.getCommandUrl(filesListPanel.getSelectedFileItem(), mode);
                if (StringUtils.isEmpty(url)) {
                    url = filesListPanel.getSelectedFileItem().getURL();
                }

                if (GWT.isScript()) {
                    if (url != null && !"".equals(url)) { //$NON-NLS-1$
                        // we have a URL so open it
                        if (mode == FileCommand.COMMAND.NEWWINDOW) {
                            Window.open(url, "_blank", //$NON-NLS-1$
                                    "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
                        } else if (mode == FileCommand.COMMAND.BACKGROUND) {
                            RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                            try {
                                builder.sendRequest(null, new RequestCallback() {

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

                                    public void onResponseReceived(Request request, Response response) {
                                        MessageDialogBox dialogBox = new MessageDialogBox(
                                                Messages.getString("info"), //$NON-NLS-1$
                                                Messages.getString("backgroundExecutionWarning"), //$NON-NLS-1$
                                                true, false, true);
                                        dialogBox.setCallback(new IDialogCallback() {
                                            public void cancelPressed() {
                                            }

                                            public void okPressed() {
                                                if (isWorkspaceShowing()) {
                                                    workspacePanel.refreshWorkspace();
                                                }
                                            }
                                        });
                                        dialogBox.center();
                                    }

                                });
                            } catch (RequestException e) {
                                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                        e.getMessage(), //$NON-NLS-1$
                                        true, false, true);
                                dialogBox.center();
                            }
                        } else {
                            UrlCommand cmd = new UrlCommand(url,
                                    filesListPanel.getSelectedFileItem().getLocalizedName());
                            cmd.execute(new CommandCallback() {
                                public void afterExecute() {
                                    contentTabPanel.setFileInfoInFrame(filesListPanel.getSelectedFileItem());
                                }
                            });
                        }
                    }
                } else {
                    if (url != null && !"".equals(url)) { //$NON-NLS-1$
                        // we have a URL so open it in a new tab
                        String updateUrl = "/MantleService?passthru=" + url; //$NON-NLS-1$

                        if (mode == FileCommand.COMMAND.NEWWINDOW) {
                            Window.open(updateUrl, "_blank", //$NON-NLS-1$
                                    "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
                        } else {
                            contentTabPanel.showNewURLTab(
                                    filesListPanel.getSelectedFileItem().getLocalizedName(),
                                    filesListPanel.getSelectedFileItem().getLocalizedName(), updateUrl, true);
                        }
                    }
                }
            } else {
                // see if this file has a URL
                String url = filesListPanel.getSelectedFileItem().getURL();
                if (url != null && !"".equals(url)) { //$NON-NLS-1$
                    // we have a URL so open it in a new tab
                    if (mode == FileCommand.COMMAND.NEWWINDOW) {
                        Window.open(filesListPanel.getSelectedFileItem().getURL(), "_blank", //$NON-NLS-1$
                                "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$
                    } else {
                        contentTabPanel.showNewURLTab(filesListPanel.getSelectedFileItem().getLocalizedName(),
                                filesListPanel.getSelectedFileItem().getLocalizedName(),
                                filesListPanel.getSelectedFileItem().getURL(), true);
                    }
                }
            }
        }
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.SolutionBrowserPerspective.java

License:Open Source License

public void executeActionSequence(final FileCommand.COMMAND mode) {
    // open in content panel
    AbstractCommand authCmd = new AbstractCommand() {
        protected void performOperation() {
            performOperation(false);/*from w  w w.j  a  v  a2  s.  c  om*/
        }

        protected void performOperation(boolean feedback) {
            String url = null;
            String path = filesListPanel.getSelectedFileItem().getPath();
            if (path.startsWith("/")) { //$NON-NLS-1$
                path = path.substring(1);
            }
            if (GWT.isScript()) {
                url = "ViewAction?solution=" + //$NON-NLS-1$
                URL.encodeComponent(filesListPanel.getSelectedFileItem().getSolution()) + "&path=" + //$NON-NLS-1$ 
                URL.encodeComponent(path) + "&action=" + //$NON-NLS-1$
                URL.encodeComponent(filesListPanel.getSelectedFileItem().getName());
                String mypath = Window.Location.getPath();
                if (!mypath.endsWith("/")) { //$NON-NLS-1$
                    mypath = mypath.substring(0, mypath.lastIndexOf("/") + 1); //$NON-NLS-1$
                }
                mypath = mypath.replaceAll("/mantle/", "/"); //$NON-NLS-1$ //$NON-NLS-2$
                if (!mypath.endsWith("/")) { //$NON-NLS-1$
                    mypath = "/" + mypath; //$NON-NLS-1$
                }
                url = mypath + url;
            } else {
                url = "/MantleService?passthru=ViewAction&solution=" //$NON-NLS-1$
                        + filesListPanel.getSelectedFileItem().getSolution() + "&path=" + path + "&action=" //$NON-NLS-1$//$NON-NLS-2$
                        + filesListPanel.getSelectedFileItem().getName() + "&userid=joe&password=password"; //$NON-NLS-1$
            }

            if (mode == FileCommand.COMMAND.BACKGROUND) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), //$NON-NLS-1$
                        Messages.getString("backgroundExecutionWarning"), //$NON-NLS-1$
                        true, false, true);
                dialogBox.center();

                url += "&background=true"; //$NON-NLS-1$

                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                try {
                    builder.sendRequest(null, new RequestCallback() {

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

                        public void onResponseReceived(Request request, Response response) {
                        }

                    });
                } catch (RequestException e) {
                }
            } else if (mode == FileCommand.COMMAND.NEWWINDOW) {
                // popup blockers might attack this
                Window.open(url, "_blank", "menubar=yes,location=no,resizable=yes,scrollbars=yes,status=no"); //$NON-NLS-1$ //$NON-NLS-2$
            } else if (mode == FileCommand.COMMAND.SUBSCRIBE) {
                final String myurl = url + "&subscribepage=yes"; //$NON-NLS-1$
                AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {

                    public void onFailure(Throwable caught) {
                        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                Messages.getString("couldNotGetFileProperties"), false, false, true); //$NON-NLS-1$
                        dialogBox.center();
                    }

                    public void onSuccess(Boolean subscribable) {
                        if (subscribable) {
                            contentTabPanel.showNewURLTab(
                                    filesListPanel.getSelectedFileItem().getLocalizedName(),
                                    filesListPanel.getSelectedFileItem().getLocalizedName(), myurl, true);
                        } else {
                            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), //$NON-NLS-1$
                                    Messages.getString("noSchedulePermission"), false, false, true); //$NON-NLS-1$
                            dialogBox.center();
                        }
                    }
                };
                MantleServiceCache.getService().hasAccess(filesListPanel.getSelectedFileItem().getSolution(),
                        filesListPanel.getSelectedFileItem().getPath(),
                        filesListPanel.getSelectedFileItem().getName(), 3, callback);
            } else {
                contentTabPanel.showNewURLTab(filesListPanel.getSelectedFileItem().getLocalizedName(),
                        filesListPanel.getSelectedFileItem().getLocalizedName(), url, true);
            }
        }

    };
    authCmd.execute();
}

From source file:org.pentaho.mantle.client.ui.PerspectiveManager.java

License:Open Source License

private PerspectiveManager() {
    getElement().setId("mantle-perspective-switcher");
    setStyleName("mantle-perspective-switcher");

    final String url = GWT.getHostPageBaseURL() + "api/plugin-manager/perspectives?ts=" //$NON-NLS-1$
            + System.currentTimeMillis();
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("Content-Type", "application/json"); //$NON-NLS-1$//$NON-NLS-2$
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

    try {/*from w  ww  .java2  s  .  com*/
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                Window.alert("getPluginPerpectives fail: " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {

                JsArray<JsPerspective> jsperspectives = JsPerspective
                        .parseJson(JsonUtils.escapeJsonForEval(response.getText()));
                ArrayList<IPluginPerspective> perspectives = new ArrayList<IPluginPerspective>();
                for (int i = 0; i < jsperspectives.length(); i++) {
                    JsPerspective jsperspective = jsperspectives.get(i);
                    DefaultPluginPerspective perspective = new DefaultPluginPerspective();
                    perspective.setContentUrl(jsperspective.getContentUrl());
                    perspective.setId(jsperspective.getId());
                    perspective.setLayoutPriority(Integer.parseInt(jsperspective.getLayoutPriority()));

                    ArrayList<String> requiredSecurityActions = new ArrayList<String>();
                    if (jsperspective.getRequiredSecurityActions() != null) {
                        for (int j = 0; j < jsperspective.getRequiredSecurityActions().length(); j++) {
                            requiredSecurityActions.add(jsperspective.getRequiredSecurityActions().get(j));
                        }
                    }

                    // will need to iterate over jsoverlays and convert to MantleXulOverlay
                    ArrayList<XulOverlay> overlays = new ArrayList<XulOverlay>();
                    if (jsperspective.getOverlays() != null) {
                        for (int j = 0; j < jsperspective.getOverlays().length(); j++) {
                            JsXulOverlay o = jsperspective.getOverlays().get(j);
                            MantleXulOverlay overlay = new MantleXulOverlay(o.getId(), o.getOverlayUri(),
                                    o.getSource(), o.getResourceBundleUri());
                            overlays.add(overlay);
                        }
                    }
                    perspective.setOverlays(overlays);

                    perspective.setRequiredSecurityActions(requiredSecurityActions);
                    perspective.setResourceBundleUri(jsperspective.getResourceBundleUri());
                    perspective.setTitle(jsperspective.getTitle());

                    perspectives.add(perspective);
                }

                setPluginPerspectives(perspectives);
            }
        });
    } catch (RequestException e) {
        // showError(e);
    }

    registerFunctions(this);
}

From source file:org.pentaho.mantle.client.ui.xul.MantleController.java

License:Open Source License

/**
 * Called when the Xul Dom is ready, grab all Xul references here.
 *///from w w w  .  ja va2 s .c o  m
@Bindable
public void init() {

    openBtn = (XulToolbarbutton) document.getElementById("openButton"); //$NON-NLS-1$
    newBtn = (XulToolbarbutton) document.getElementById("newButton"); //$NON-NLS-1$
    saveBtn = (XulToolbarbutton) document.getElementById("saveButton"); //$NON-NLS-1$
    saveAsBtn = (XulToolbarbutton) document.getElementById("saveAsButton"); //$NON-NLS-1$
    printBtn = (XulToolbarbutton) document.getElementById("printButton");

    contentEditBtn = (XulToolbarbutton) document.getElementById("editContentButton"); //$NON-NLS-1$

    bf = new GwtBindingFactory(document);
    bf.createBinding(model, "saveEnabled", saveBtn, "visible"); //$NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "saveAsEnabled", saveAsBtn, "visible"); //$NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "contentEditEnabled", contentEditBtn, "visible"); //$NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "contentEditSelected", this, "editContentSelected"); //$NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(model, "printVisible", printBtn, "visible");

    saveMenuItem = (XulMenuitem) document.getElementById("saveMenuItem"); //$NON-NLS-1$
    saveAsMenuItem = (XulMenuitem) document.getElementById("saveAsMenuItem"); //$NON-NLS-1$
    useDescriptionsMenuItem = (XulMenuitem) document.getElementById("useDescriptionsMenuItem"); //$NON-NLS-1$
    showHiddenFilesMenuItem = (XulMenuitem) document.getElementById("showHiddenFilesMenuItem"); //$NON-NLS-1$
    languageMenu = (XulMenubar) document.getElementById("languagemenu"); //$NON-NLS-1$
    themesMenu = (XulMenubar) document.getElementById("themesmenu"); //$NON-NLS-1$
    toolsMenu = (XulMenubar) document.getElementById("toolsmenu"); //$NON-NLS-1$
    recentMenu = (XulMenubar) document.getElementById("recentmenu"); //$NON-NLS-1$
    favoriteMenu = (XulMenubar) document.getElementById("favoritesmenu"); //$NON-NLS-1$

    if (PerspectiveManager.getInstance().isLoaded()) {
        PerspectiveManager.getInstance().enablePerspective(PerspectiveManager.OPENED_PERSPECTIVE, false);
    } else {
        EventBusUtil.EVENT_BUS.addHandler(PerspectivesLoadedEvent.TYPE, new PerspectivesLoadedEventHandler() {
            public void onPerspectivesLoaded(PerspectivesLoadedEvent event) {
                PerspectiveManager.getInstance().enablePerspective(PerspectiveManager.OPENED_PERSPECTIVE,
                        false);
            }
        });
    }

    // install language sub-menus
    Map<String, String> supportedLanguages = Messages.getResourceBundle().getSupportedLanguages();
    if (supportedLanguages != null && supportedLanguages.keySet() != null && !supportedLanguages.isEmpty()) {
        MenuBar langMenu = (MenuBar) languageMenu.getManagedObject();
        langMenu.insertSeparator(0);
        for (String lang : supportedLanguages.keySet()) {
            MenuItem langMenuItem = new MenuItem(supportedLanguages.get(lang), new SwitchLocaleCommand(lang));
            langMenuItem.getElement().setId(supportedLanguages.get(lang) + "_menu_item"); //$NON-NLS-1$
            langMenu.insertItem(langMenuItem, 0);
        }
    }
    buildFavoritesAndRecent(false);

    UserSettingsManager.getInstance().getUserSettings(new AsyncCallback<JsArray<JsSetting>>() {
        public void onSuccess(JsArray<JsSetting> settings) {
            processSettings(settings);
        }

        public void onFailure(Throwable caught) {
        }
    }, false);

    EventBusUtil.EVENT_BUS.addHandler(UserSettingsLoadedEvent.TYPE, new UserSettingsLoadedEventHandler() {
        public void onUserSettingsLoaded(UserSettingsLoadedEvent event) {
            processSettings(event.getSettings());
        }

    });

    // install themes
    RequestBuilder getActiveThemeRequestBuilder = new RequestBuilder(RequestBuilder.GET,
            GWT.getHostPageBaseURL() + "api/theme/active"); //$NON-NLS-1$
    try {
        getActiveThemeRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        getActiveThemeRequestBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                final String activeTheme = response.getText();
                RequestBuilder getThemesRequestBuilder = new RequestBuilder(RequestBuilder.GET,
                        GWT.getHostPageBaseURL() + "api/theme/list"); //$NON-NLS-1$
                getThemesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                getThemesRequestBuilder.setHeader("accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$

                try {
                    getThemesRequestBuilder.sendRequest(null, new RequestCallback() {
                        public void onError(Request arg0, Throwable arg1) {
                        }

                        public void onResponseReceived(Request request, Response response) {
                            try {
                                final String url = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister"; //$NON-NLS-1$
                                RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
                                requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                                requestBuilder.setHeader("accept", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
                                requestBuilder.sendRequest(null, new RequestCallback() {

                                    public void onError(Request request, Throwable caught) {
                                    }

                                    public void onResponseReceived(Request request, Response response) {
                                        toolsMenu.setVisible("true".equalsIgnoreCase(response.getText())); //$NON-NLS-1$
                                        showHiddenFilesMenuItem
                                                .setVisible("true".equalsIgnoreCase(response.getText())); //$NON-NLS-1$
                                    }

                                });
                            } catch (RequestException e) {
                                Window.alert(e.getMessage());
                            }

                            JsArray<JsTheme> themes = JsTheme
                                    .getThemes(JsonUtils.escapeJsonForEval(response.getText()));

                            for (int i = 0; i < themes.length(); i++) {
                                JsTheme theme = themes.get(i);
                                PentahoMenuItem themeMenuItem = new PentahoMenuItem(theme.getName(),
                                        new SwitchThemeCommand(theme.getId()));
                                themeMenuItem.getElement().setId(theme.getId() + "_menu_item"); //$NON-NLS-1$
                                themeMenuItem.setChecked(theme.getId().equals(activeTheme));
                                ((MenuBar) themesMenu.getManagedObject()).addItem(themeMenuItem);
                            }

                            bf.createBinding(model, "saveEnabled", saveMenuItem, "visible"); //$NON-NLS-1$ //$NON-NLS-2$
                            bf.createBinding(model, "saveAsEnabled", saveAsMenuItem, "visible"); //$NON-NLS-1$ //$NON-NLS-2$

                            if (PerspectiveManager.getInstance().isLoaded()) {
                                executeAdminContent();
                            } else {
                                EventBusUtil.EVENT_BUS.addHandler(PerspectivesLoadedEvent.TYPE,
                                        new PerspectivesLoadedEventHandler() {
                                            public void onPerspectivesLoaded(PerspectivesLoadedEvent event) {
                                                executeAdminContent();
                                            }
                                        });
                            }

                            setupNativeHooks(MantleController.this);
                        }
                    });

                } catch (RequestException e) {
                    // showError(e);
                }
            }

        });

    } catch (RequestException e) {
        Window.alert(e.getMessage());
        // showError(e);
    }
}

From source file:org.pentaho.mantle.client.ui.xul.MantleController.java

License:Open Source License

private void executeAdminContent() {

    try {/*  w  ww .  j  a  v  a 2s .  c  om*/
        RequestCallback internalCallback = new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                JsArray<JsSetting> jsSettings = null;
                try {
                    jsSettings = JsSetting.parseSettingsJson(response.getText());
                } catch (Throwable t) {
                    // happens when there are no settings
                }
                if (jsSettings == null) {
                    return;
                }
                for (int i = 0; i < jsSettings.length(); i++) {
                    String content = jsSettings.get(i).getValue();
                    StringTokenizer nameValuePairs = new StringTokenizer(content, ";"); //$NON-NLS-1$
                    String perspective = null, content_panel_id = null, content_url = null;
                    for (int j = 0; j < nameValuePairs.countTokens(); j++) {
                        String currentToken = nameValuePairs.tokenAt(j).trim();
                        if (currentToken.startsWith("perspective=")) { //$NON-NLS-1$
                            perspective = currentToken.substring("perspective=".length()); //$NON-NLS-1$
                        }
                        if (currentToken.startsWith("content-panel-id=")) { //$NON-NLS-1$
                            content_panel_id = currentToken.substring("content-panel-id=".length()); //$NON-NLS-1$
                        }
                        if (currentToken.startsWith("content-url=")) { //$NON-NLS-1$
                            content_url = currentToken.substring("content-url=".length()); //$NON-NLS-1$
                        }
                    }

                    if (content_panel_id != null && content_url != null) {
                        overrideContentPanelId = content_panel_id;
                        overrideContentUrl = content_url;
                    }

                    if (perspective != null) {
                        PerspectiveManager.getInstance().setPerspective(perspective);
                    }

                    if (perspective == null && content_panel_id == null && content_url == null) {
                        GwtMessageBox warning = new GwtMessageBox();
                        warning.setTitle(Messages.getString("warning")); //$NON-NLS-1$
                        warning.setMessage(content);
                        warning.setButtons(new Object[GwtMessageBox.ACCEPT]);
                        warning.setAcceptLabel(Messages.getString("close")); //$NON-NLS-1$
                        warning.show();
                    }
                }
            }
        };

        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
                GWT.getHostPageBaseURL() + "api/mantle/getAdminContent"); //$NON-NLS-1$
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.setHeader("accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$
        builder.sendRequest(null, internalCallback);
        // TO DO Reset the menuItem click for browser and workspace here?
    } catch (RequestException e) {
        //ignore
    }
}

From source file:org.pentaho.mantle.client.ui.xul.MantleXul.java

License:Open Source License

/**
 * Callback method for the MantleXulLoader. This is called when the Xul file has been processed.
 * /*from  w w  w .  ja va2s.c om*/
 * @param runner
 *          GwtXulRunner instance ready for event handlers and initializing.
 */
public void xulLoaded(GwtXulRunner runner) {
    // handlers need to be wrapped generically in GWT, create one and pass it our reference.

    // instantiate our Model and Controller
    controller = new MantleController(new MantleModel(this));

    // Add handler to container
    container = (GwtXulDomContainer) runner.getXulDomContainers().get(0);
    container.addEventHandler(controller);

    try {
        runner.initialize();
    } catch (XulException e) {
        Window.alert("Error initializing XUL runner: " + e.getMessage()); //$NON-NLS-1$
        e.printStackTrace();
        return;
    }

    // Get the toolbar from the XUL doc
    Widget bar = (Widget) container.getDocumentRoot().getElementById("mainToolbarWrapper").getManagedObject(); //$NON-NLS-1$
    Widget xultoolbar = (Widget) container.getDocumentRoot().getElementById("mainToolbar").getManagedObject(); //$NON-NLS-1$
    xultoolbar.getElement().removeClassName("toolbar");
    toolbar.setStylePrimaryName("mainToolbar-Wrapper");
    toolbar.setWidget(bar);

    // Get the menubar from the XUL doc
    Widget menu = (Widget) container.getDocumentRoot().getElementById("mainMenubar").getManagedObject(); //$NON-NLS-1$
    menubar.setWidget(menu);

    // check based on user permissions
    final String moduleBaseURL = GWT.getModuleBaseURL();
    final String moduleName = GWT.getModuleName();
    final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    final String url = contextURL + "api/repo/files/canCreate"; //$NON-NLS-1$
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("accept", "text/plain");
    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) {
                    Boolean visible = new Boolean(response.getText());
                    controller.setMenuBarEnabled("newmenu", visible);
                    controller.setToolBarButtonEnabled("newButton", visible);
                }
            }
        });
    } catch (RequestException e) {
        // showError(e);
    }

    // get the admin perspective from the XUL doc
    Widget admin = (Widget) container.getDocumentRoot().getElementById("adminPerspective").getManagedObject(); //$NON-NLS-1$
    admin.setStyleName("admin-perspective");
    admin.getElement().getStyle().clearHeight();
    admin.getElement().getStyle().clearWidth();
    adminPerspective.setWidget(admin);

    Panel adminContentPanel = (Panel) container.getDocumentRoot().getElementById("adminContentPanel")
            .getManagedObject();
    adminContentPanel.add(adminContentDeck);
    adminContentDeck.setHeight("100%");
    adminContentDeck.getElement().getStyle().setProperty("height", "100%");
    fetchPluginOverlays();
}