Search in sources :

Example 1 with PerspectivesLoadedEventHandler

use of org.pentaho.mantle.client.events.PerspectivesLoadedEventHandler in project pentaho-platform by pentaho.

the class MantleController method init.

/**
 * Called when the Xul Dom is ready, grab all Xul references here.
 */
@Bindable
public void init() {
    // $NON-NLS-1$
    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");
    printBtn = (XulToolbarbutton) document.getElementById("printButton");
    // $NON-NLS-1$
    contentEditBtn = (XulToolbarbutton) document.getElementById("editContentButton");
    bf = new GwtBindingFactory(document);
    // $NON-NLS-1$ //$NON-NLS-2$
    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");
    bf.createBinding(model, "printVisible", printBtn, "visible");
    // $NON-NLS-1$
    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");
    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));
            // $NON-NLS-1$
            langMenuItem.getElement().setId(supportedLanguages.get(lang) + "_menu_item");
            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 = // $NON-NLS-1$
    new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/theme/active");
    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 = // $NON-NLS-1$
                new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/theme/list");
                getThemesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                // $NON-NLS-1$ //$NON-NLS-2$
                getThemesRequestBuilder.setHeader("accept", "application/json");
                try {
                    getThemesRequestBuilder.sendRequest(null, new RequestCallback() {

                        public void onError(Request arg0, Throwable arg1) {
                        }

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

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

                                    public void onResponseReceived(Request request, Response response) {
                                        // $NON-NLS-1$
                                        toolsMenu.setVisible("true".equalsIgnoreCase(response.getText()));
                                        // $NON-NLS-1$
                                        showHiddenFilesMenuItem.setVisible("true".equalsIgnoreCase(response.getText()));
                                    }
                                });
                            } 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()));
                                // $NON-NLS-1$
                                themeMenuItem.getElement().setId(theme.getId() + "_menu_item");
                                themeMenuItem.setChecked(theme.getId().equals(activeTheme));
                                ((MenuBar) themesMenu.getManagedObject()).addItem(themeMenuItem);
                            }
                            // $NON-NLS-1$ //$NON-NLS-2$
                            bf.createBinding(model, "saveEnabled", saveMenuItem, "!disabled");
                            // $NON-NLS-1$ //$NON-NLS-2$
                            bf.createBinding(model, "saveAsEnabled", saveAsMenuItem, "!disabled");
                            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);
    }
}
Also used : PentahoMenuItem(org.pentaho.gwt.widgets.client.menuitem.PentahoMenuItem) RequestBuilder(com.google.gwt.http.client.RequestBuilder) UserSettingsLoadedEvent(org.pentaho.mantle.client.events.UserSettingsLoadedEvent) MenuBar(com.google.gwt.user.client.ui.MenuBar) RequestException(com.google.gwt.http.client.RequestException) SwitchLocaleCommand(org.pentaho.mantle.client.commands.SwitchLocaleCommand) UserSettingsLoadedEventHandler(org.pentaho.mantle.client.events.UserSettingsLoadedEventHandler) JsSetting(org.pentaho.mantle.client.usersettings.JsSetting) JsArray(com.google.gwt.core.client.JsArray) PerspectivesLoadedEventHandler(org.pentaho.mantle.client.events.PerspectivesLoadedEventHandler) Request(com.google.gwt.http.client.Request) MenuItem(com.google.gwt.user.client.ui.MenuItem) PentahoMenuItem(org.pentaho.gwt.widgets.client.menuitem.PentahoMenuItem) Response(com.google.gwt.http.client.Response) SwitchThemeCommand(org.pentaho.mantle.client.commands.SwitchThemeCommand) PerspectivesLoadedEvent(org.pentaho.mantle.client.events.PerspectivesLoadedEvent) RequestCallback(com.google.gwt.http.client.RequestCallback) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 2 with PerspectivesLoadedEventHandler

use of org.pentaho.mantle.client.events.PerspectivesLoadedEventHandler in project pentaho-platform by pentaho.

the class MantleApplication method onMantleSettingsLoaded.

public void onMantleSettingsLoaded(MantleSettingsLoadedEvent event) {
    final HashMap<String, String> settings = event.getSettings();
    final boolean showOnlyPerspective = Boolean.parseBoolean(StringUtils.isEmpty(Window.Location.getParameter("showOnlyPerspective")) ? settings.get("showOnlyPerspective") : Window.Location.getParameter("showOnlyPerspective"));
    final String startupPerspective = StringUtils.isEmpty(Window.Location.getParameter("startupPerspective")) ? settings.get("startupPerspective") : Window.Location.getParameter("startupPerspective");
    mantleRevisionOverride = settings.get("user-console-revision");
    RootPanel.get("pucMenuBar").add(MantleXul.getInstance().getMenubar());
    RootPanel.get("pucPerspectives").add(PerspectiveManager.getInstance());
    RootPanel.get("pucToolBar").add(MantleXul.getInstance().getToolbar());
    RootPanel.get("pucUserDropDown").add(new UserDropDown());
    if (showOnlyPerspective && !StringUtils.isEmpty(startupPerspective)) {
        RootPanel.get("pucHeader").setVisible(false);
        RootPanel.get("pucContent").getElement().getStyle().setTop(0, Unit.PX);
    }
    // update supported file types
    PluginOptionsHelper.buildEnabledOptionsList(settings);
    // show stuff we've created/configured
    contentDeck.add(new Label());
    contentDeck.showWidget(0);
    contentDeck.add(SolutionBrowserPanel.getInstance());
    if (showOnlyPerspective && !StringUtils.isEmpty(startupPerspective)) {
        SolutionBrowserPanel.getInstance().setVisible(false);
    }
    contentDeck.getElement().setId("applicationShell");
    contentDeck.setStyleName("applicationShell");
    // menubar=no,location=no,resizable=yes,scrollbars=no,status=no,width=1200,height=800
    try {
        RootPanel.get("pucContent").add(contentDeck);
    } catch (Throwable t) {
    // onLoad of something is causing problems
    }
    RootPanel.get().add(WaitPopup.getInstance());
    // Add in the overlay panel
    overlayPanel.setVisible(false);
    overlayPanel.setHeight("100%");
    overlayPanel.setWidth("100%");
    overlayPanel.getElement().getStyle().setProperty("zIndex", "1000");
    overlayPanel.getElement().getStyle().setProperty("position", "absolute");
    RootPanel.get().add(overlayPanel, 0, 0);
    String submitOnEnterSetting = settings.get("submit-on-enter-key");
    submitOnEnter = submitOnEnterSetting == null ? submitOnEnter : Boolean.parseBoolean(submitOnEnterSetting);
    try {
        // $NON-NLS-1$
        String restUrl = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister";
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, restUrl);
        requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request arg0, Throwable arg1) {
                MessageDialogBox dialogBox = // $NON-NLS-1$
                new MessageDialogBox(Messages.getString("error"), arg1.getLocalizedMessage(), false, false, true);
                dialogBox.center();
            }

            @Override
            public void onResponseReceived(Request arg0, Response response) {
                Boolean isAdministrator = Boolean.parseBoolean(response.getText());
                SolutionBrowserPanel.getInstance().setAdministrator(isAdministrator);
                try {
                    // $NON-NLS-1$
                    String restUrl2 = GWT.getHostPageBaseURL() + "api/scheduler/canSchedule";
                    RequestBuilder requestBuilder2 = new RequestBuilder(RequestBuilder.GET, restUrl2);
                    requestBuilder2.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                    requestBuilder2.sendRequest(null, new RequestCallback() {

                        @Override
                        public void onError(Request arg0, Throwable arg1) {
                            MessageDialogBox dialogBox = // $NON-NLS-1$
                            new MessageDialogBox(Messages.getString("error"), arg1.getLocalizedMessage(), false, false, true);
                            dialogBox.center();
                        }

                        public void onResponseReceived(Request arg0, Response response) {
                            Boolean isScheduler = Boolean.parseBoolean(response.getText());
                            SolutionBrowserPanel.getInstance().setScheduler(isScheduler);
                            String numStartupURLsSetting = settings.get("num-startup-urls");
                            if (numStartupURLsSetting != null) {
                                // $NON-NLS-1$
                                int numStartupURLs = Integer.parseInt(numStartupURLsSetting);
                                for (int i = 0; i < numStartupURLs; i++) {
                                    // $NON-NLS-1$
                                    String url = settings.get("startup-url-" + (i + 1));
                                    // $NON-NLS-1$
                                    String name = settings.get("startup-name-" + (i + 1));
                                    if (StringUtils.isEmpty(url) == false) {
                                        // $NON-NLS-1$
                                        url = URL.decodeQueryString(url);
                                        name = URL.decodeQueryString(name);
                                        SolutionBrowserPanel.getInstance().getContentTabPanel().showNewURLTab(name != null ? name : url, url, url, false);
                                    }
                                }
                            }
                            if (SolutionBrowserPanel.getInstance().getContentTabPanel().getWidgetCount() > 0) {
                                SolutionBrowserPanel.getInstance().getContentTabPanel().selectTab(0);
                            }
                            // startup-url on the URL for the app, wins over settings
                            // $NON-NLS-1$
                            String startupURL = Window.Location.getParameter("startup-url");
                            if (startupURL != null && !"".equals(startupURL)) {
                                // $NON-NLS-1$
                                // Spaces were double encoded so that they wouldn't be replaced with '+' when creating a deep
                                // link so when following a deep link we need to replace '%20' with a space even after decoding
                                // $NON-NLS-1$
                                String title = Window.Location.getParameter("name").replaceAll("%20", " ");
                                SolutionBrowserPanel.getInstance().getContentTabPanel().showNewURLTab(title, title, startupURL, false);
                            }
                        }
                    });
                } catch (RequestException e) {
                    MessageDialogBox dialogBox = // $NON-NLS-1$
                    new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), false, false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = // $NON-NLS-1$
        new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), false, false, true);
        dialogBox.center();
    }
    if (!StringUtils.isEmpty(startupPerspective)) {
        if (PerspectiveManager.getInstance().isLoaded()) {
            PerspectiveManager.getInstance().setPerspective(startupPerspective);
        } else {
            EventBusUtil.EVENT_BUS.addHandler(PerspectivesLoadedEvent.TYPE, new PerspectivesLoadedEventHandler() {

                public void onPerspectivesLoaded(PerspectivesLoadedEvent event) {
                    PerspectiveManager.getInstance().setPerspective(startupPerspective);
                }
            });
        }
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) PerspectivesLoadedEventHandler(org.pentaho.mantle.client.events.PerspectivesLoadedEventHandler) Label(com.google.gwt.user.client.ui.Label) Request(com.google.gwt.http.client.Request) UserDropDown(org.pentaho.mantle.client.ui.UserDropDown) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) PerspectivesLoadedEvent(org.pentaho.mantle.client.events.PerspectivesLoadedEvent) RequestCallback(com.google.gwt.http.client.RequestCallback)

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 PerspectivesLoadedEvent (org.pentaho.mantle.client.events.PerspectivesLoadedEvent)2 PerspectivesLoadedEventHandler (org.pentaho.mantle.client.events.PerspectivesLoadedEventHandler)2 JsArray (com.google.gwt.core.client.JsArray)1 Label (com.google.gwt.user.client.ui.Label)1 MenuBar (com.google.gwt.user.client.ui.MenuBar)1 MenuItem (com.google.gwt.user.client.ui.MenuItem)1 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)1 PentahoMenuItem (org.pentaho.gwt.widgets.client.menuitem.PentahoMenuItem)1 SwitchLocaleCommand (org.pentaho.mantle.client.commands.SwitchLocaleCommand)1 SwitchThemeCommand (org.pentaho.mantle.client.commands.SwitchThemeCommand)1 UserSettingsLoadedEvent (org.pentaho.mantle.client.events.UserSettingsLoadedEvent)1 UserSettingsLoadedEventHandler (org.pentaho.mantle.client.events.UserSettingsLoadedEventHandler)1 UserDropDown (org.pentaho.mantle.client.ui.UserDropDown)1 JsSetting (org.pentaho.mantle.client.usersettings.JsSetting)1 GwtBindingFactory (org.pentaho.ui.xul.gwt.binding.GwtBindingFactory)1