Search in sources :

Example 1 with JsSetting

use of org.pentaho.mantle.client.usersettings.JsSetting in project pentaho-platform by pentaho.

the class MantleApplication method loadApplication.

public void loadApplication() {
    // registered our native JSNI hooks
    setupNativeHooks(this, new LoginCommand());
    FileChooserDialog.setupNativeHooks();
    UserSettingsManager.getInstance().getUserSettings(new AsyncCallback<JsArray<JsSetting>>() {

        public void onSuccess(JsArray<JsSetting> settings) {
            onUserSettingsLoaded(new UserSettingsLoadedEvent(settings));
        }

        public void onFailure(Throwable caught) {
        }
    }, false);
}
Also used : JsSetting(org.pentaho.mantle.client.usersettings.JsSetting) JsArray(com.google.gwt.core.client.JsArray) LoginCommand(org.pentaho.mantle.client.commands.LoginCommand) UserSettingsLoadedEvent(org.pentaho.mantle.client.events.UserSettingsLoadedEvent)

Example 2 with JsSetting

use of org.pentaho.mantle.client.usersettings.JsSetting in project pentaho-platform by pentaho.

the class MantleController method loadRecentAndFavorites.

private void loadRecentAndFavorites(boolean force) {
    UserSettingsManager.getInstance().getUserSettings(new AsyncCallback<JsArray<JsSetting>>() {

        public void onSuccess(JsArray<JsSetting> result) {
            if (result == null) {
                return;
            }
            JsSetting setting;
            for (int j = 0; j < result.length(); j++) {
                setting = result.get(j);
                if ("favorites".equalsIgnoreCase(setting.getName())) {
                    // $NON-NLS-1$
                    try {
                        // handle favorite
                        JSONArray favorites = JSONParser.parseLenient(setting.getValue()).isArray();
                        if (favorites != null) {
                            // Create the FavoritePickList object from the JSONArray
                            favoritePickList = FavoritePickList.getInstanceFromJSON(favorites);
                        } else {
                            favoritePickList = FavoritePickList.getInstance();
                        }
                    } catch (Throwable t) {
                    // ignore
                    }
                } else if ("recent".equalsIgnoreCase(setting.getName())) {
                    // $NON-NLS-1$
                    try {
                        // handle recent
                        JSONArray recents = JSONParser.parseLenient(setting.getValue()).isArray();
                        if (recents != null) {
                            // Create the RecentPickList object from the JSONArray
                            recentPickList = RecentPickList.getInstanceFromJSON(recents);
                        } else {
                            recentPickList = RecentPickList.getInstance();
                        }
                        recentPickList.setMaxSize(10);
                    } catch (Throwable t) {
                    // ignore
                    }
                }
            }
        }

        public void onFailure(Throwable caught) {
        }
    }, force);
}
Also used : JsSetting(org.pentaho.mantle.client.usersettings.JsSetting) JsArray(com.google.gwt.core.client.JsArray) JSONArray(com.google.gwt.json.client.JSONArray)

Example 3 with JsSetting

use of org.pentaho.mantle.client.usersettings.JsSetting 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 4 with JsSetting

use of org.pentaho.mantle.client.usersettings.JsSetting in project pentaho-platform by pentaho.

the class MantleController method executeAdminContent.

private void executeAdminContent() {
    try {
        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();
                    // $NON-NLS-1$
                    StringTokenizer nameValuePairs = new StringTokenizer(content, ";");
                    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$
                            // $NON-NLS-1$
                            perspective = currentToken.substring("perspective=".length());
                        }
                        if (currentToken.startsWith("content-panel-id=")) {
                            // $NON-NLS-1$
                            // $NON-NLS-1$
                            content_panel_id = currentToken.substring("content-panel-id=".length());
                        }
                        if (currentToken.startsWith("content-url=")) {
                            // $NON-NLS-1$
                            // $NON-NLS-1$
                            content_url = currentToken.substring("content-url=".length());
                        }
                    }
                    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();
                        // $NON-NLS-1$
                        warning.setTitle(Messages.getString("warning"));
                        warning.setMessage(content);
                        warning.setButtons(new Object[GwtMessageBox.ACCEPT]);
                        // $NON-NLS-1$
                        warning.setAcceptLabel(Messages.getString("close"));
                        warning.show();
                    }
                }
            }
        };
        RequestBuilder builder = // $NON-NLS-1$
        new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/mantle/getAdminContent");
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        // $NON-NLS-1$ //$NON-NLS-2$
        builder.setHeader("accept", "application/json");
        builder.sendRequest(null, internalCallback);
    // TO DO Reset the menuItem click for browser and workspace here?
    } catch (RequestException e) {
    // ignore
    }
}
Also used : Response(com.google.gwt.http.client.Response) JsSetting(org.pentaho.mantle.client.usersettings.JsSetting) StringTokenizer(org.pentaho.gwt.widgets.client.utils.string.StringTokenizer) RequestCallback(com.google.gwt.http.client.RequestCallback) RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException) GwtMessageBox(org.pentaho.ui.xul.gwt.tags.GwtMessageBox)

Example 5 with JsSetting

use of org.pentaho.mantle.client.usersettings.JsSetting in project pentaho-platform by pentaho.

the class MantleController method processSettings.

public void processSettings(JsArray<JsSetting> settings) {
    if (settings == null) {
        return;
    }
    for (int i = 0; i < settings.length(); i++) {
        JsSetting setting = settings.get(i);
        try {
            if (IMantleUserSettingsConstants.MANTLE_SHOW_NAVIGATOR.equals(setting.getName())) {
                // $NON-NLS-1$
                boolean showNavigator = "true".equals(setting.getValue());
                model.setShowNavigatorSelected(showNavigator);
            } else if (IMantleUserSettingsConstants.MANTLE_SHOW_DESCRIPTIONS_FOR_TOOLTIPS.equals(setting.getName())) {
                // $NON-NLS-1$
                boolean checked = "true".equals(setting.getValue());
                ((PentahoMenuItem) useDescriptionsMenuItem.getManagedObject()).setChecked(checked);
            } else if (IMantleUserSettingsConstants.MANTLE_SHOW_HIDDEN_FILES.equals(setting.getName())) {
                // $NON-NLS-1$
                boolean checked = "true".equals(setting.getValue());
                ((PentahoMenuItem) showHiddenFilesMenuItem.getManagedObject()).setChecked(checked);
            }
        } catch (Exception e) {
            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), Messages.getString("couldNotGetUserSettings"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
            true);
            dialogBox.center();
        }
    }
}
Also used : PentahoMenuItem(org.pentaho.gwt.widgets.client.menuitem.PentahoMenuItem) JsSetting(org.pentaho.mantle.client.usersettings.JsSetting) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

JsSetting (org.pentaho.mantle.client.usersettings.JsSetting)6 JsArray (com.google.gwt.core.client.JsArray)3 RequestException (com.google.gwt.http.client.RequestException)3 Request (com.google.gwt.http.client.Request)2 RequestBuilder (com.google.gwt.http.client.RequestBuilder)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 Response (com.google.gwt.http.client.Response)2 PentahoMenuItem (org.pentaho.gwt.widgets.client.menuitem.PentahoMenuItem)2 UserSettingsLoadedEvent (org.pentaho.mantle.client.events.UserSettingsLoadedEvent)2 JSONArray (com.google.gwt.json.client.JSONArray)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 StringTokenizer (org.pentaho.gwt.widgets.client.utils.string.StringTokenizer)1 LoginCommand (org.pentaho.mantle.client.commands.LoginCommand)1 SwitchLocaleCommand (org.pentaho.mantle.client.commands.SwitchLocaleCommand)1 SwitchThemeCommand (org.pentaho.mantle.client.commands.SwitchThemeCommand)1 PerspectivesLoadedEvent (org.pentaho.mantle.client.events.PerspectivesLoadedEvent)1 PerspectivesLoadedEventHandler (org.pentaho.mantle.client.events.PerspectivesLoadedEventHandler)1 UserSettingsLoadedEventHandler (org.pentaho.mantle.client.events.UserSettingsLoadedEventHandler)1