Example usage for com.google.gwt.user.client.ui MenuBar insertSeparator

List of usage examples for com.google.gwt.user.client.ui MenuBar insertSeparator

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui MenuBar insertSeparator.

Prototype

public MenuItemSeparator insertSeparator(int beforeIndex) 

Source Link

Document

Adds a thin line to the MenuBar to separate sections of MenuItem s at the specified index.

Usage

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.
 *//*w w  w. ja v a  2 s.  co  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);
    }
}