use of com.google.gwt.http.client.RequestCallback 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
ResourceBundle resourceBundle = Messages.getResourceBundle();
Map<String, String> supportedLanguages = resourceBundle.getSupportedLanguages();
if (supportedLanguages != null && !supportedLanguages.isEmpty()) {
String currentLanguage = resourceBundle.getLanguage();
MenuBar langMenu = (MenuBar) languageMenu.getManagedObject();
langMenu.insertSeparator(0);
for (String lang : supportedLanguages.keySet()) {
CheckBoxMenuItem langMenuItem = new CheckBoxMenuItem(supportedLanguages.get(lang), new SwitchLocaleCommand(lang));
langMenuItem.getElement().setId(supportedLanguages.get(lang) + "_menu_item");
langMenuItem.setChecked(lang.equalsIgnoreCase(currentLanguage));
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(HTTP_REQUEST_ACCEPT_HEADER, JSON_REQUEST_HEADER);
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(HTTP_REQUEST_ACCEPT_HEADER, "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);
}
}
use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.
the class MantleXul method fetchPluginOverlays.
private void fetchPluginOverlays() {
AbstractCommand cmd = new AbstractCommand() {
protected void performOperation(boolean feedback) {
performOperation();
}
protected void performOperation() {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/plugin-manager/overlays";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
public void onResponseReceived(Request request, Response response) {
JsArray<JsXulOverlay> jsoverlays = JsXulOverlay.parseJson(JsonUtils.escapeJsonForEval(response.getText()));
ArrayList<XulOverlay> overlays = new ArrayList<XulOverlay>();
for (int i = 0; i < jsoverlays.length(); i++) {
JsXulOverlay o = jsoverlays.get(i);
MantleXulOverlay overlay;
overlay = new MantleXulOverlay(o.getId(), o.getOverlayUri(), o.getSource(), o.getResourceBundleUri(), Integer.parseInt(o.getPriority()));
overlays.add(overlay);
}
MantleXul.this.addOverlays(overlays);
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "plugin/data-access/api/permissions/hasDataAccess";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
public void onResponseReceived(Request request, Response response) {
if (response.getText().equals("true")) {
controller.loadOverlay("dataaccess");
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
};
cmd.execute();
}
use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.
the class PermissionsPanel method setAdmin.
private void setAdmin() {
try {
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister";
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
// $NON-NLS-1$ //$NON-NLS-2$
requestBuilder.setHeader("accept", "text/plain");
// $NON-NLS-1$ //$NON-NLS-2$
requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
requestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable caught) {
isAdmin = false;
}
public void onResponseReceived(Request request, Response response) {
// $NON-NLS-1$
isAdmin = "true".equalsIgnoreCase(response.getText());
}
});
} catch (RequestException e) {
isAdmin = false;
}
}
use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.
the class AbstractFilePickList method reloadFavorites.
public void reloadFavorites(final T pickListItem, final String command) {
final String url = GWT.getHostPageBaseURL() + "api/user-settings/favorites";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.setHeader("accept", "application/json");
builder.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_NO_CONTENT && FILE_PICK_ADD.equals(command)) {
filePickList = new ArrayList<T>();
add(filePickList.size(), pickListItem);
} else if (response.getStatusCode() == Response.SC_OK) {
try {
JSONArray jsonArr = (JSONArray) JSONParser.parse(response.getText());
filePickList = new ArrayList<T>();
T filePickItem;
for (int i = 0; i < jsonArr.size(); i++) {
filePickItem = createFilePickItem(jsonArr.get(i).isObject());
filePickList.add(filePickItem);
}
if (FILE_PICK_ADD.equals(command)) {
add(filePickList.size(), pickListItem);
} else if (FILE_PICK_REMOVE.equals(command)) {
filePickList.remove(pickListItem);
fireItemsChangedEvent();
}
} catch (Exception e) {
if (FILE_PICK_ADD.equals(command)) {
add(filePickList.size(), pickListItem);
} else if (FILE_PICK_REMOVE.equals(command)) {
filePickList.remove(pickListItem);
fireItemsChangedEvent();
}
}
}
}
});
} catch (RequestException e) {
// showError(e);
}
}
use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.
the class AbstractFilePickList method save.
/**
* Convert the FilePickList to JSON and save it to a user setting
*
* @param settingName
*/
public void save(String settingName) {
String url = GWT.getHostPageBaseURL() + "api/user-settings/" + settingName;
RequestBuilder builder = new CsrfRequestBuilder(RequestBuilder.POST, url);
try {
builder.setHeader("accept", "application/json");
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
builder.sendRequest(toJson().toString(), new RequestCallback() {
public void onError(Request request, Throwable exception) {
MessageDialogBox dialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("couldNotSetUserSettings"), true, false, true);
dialog.center();
}
public void onResponseReceived(Request request, Response response) {
fireOnSavedEvent();
}
});
} catch (RequestException e) {
// showError(e);
}
}
Aggregations