package org.aplikator.client.local.widgets;
import org.gwtbootstrap3.extras.notify.client.constants.NotifyType;
import org.gwtbootstrap3.extras.notify.client.ui.Notify;
import org.gwtbootstrap3.extras.notify.client.ui.NotifySettings;
import org.jboss.errai.enterprise.client.jaxrs.api.ResponseException;
import com.google.gwt.http.client.Response;
/**
* @author vlahoda
*/
public class Messages {
private static final int Z_INDEX = 99999;
public static void success(String text) {
NotifySettings go = NotifySettings.newSettings();
go.setType(NotifyType.SUCCESS);
go.setAllowDismiss(false);
go.setZIndex(Z_INDEX);
Notify.notify(text, go);
}
public static void error(String text) {
NotifySettings go = NotifySettings.newSettings();
go.setType(NotifyType.DANGER);
go.setAllowDismiss(true);
go.setDelay(0);
go.setPauseOnMouseOver(true);
go.setZIndex(Z_INDEX);
Notify.notify(text, go);
}
public static void info(String text) {
NotifySettings go = NotifySettings.newSettings();
go.setType(NotifyType.INFO);
go.setAllowDismiss(true);
go.setDelay(10000);
go.setZIndex(Z_INDEX);
Notify.notify(text, go);
}
public static void warning(String text) {
NotifySettings go = NotifySettings.newSettings();
go.setType(NotifyType.WARNING);
go.setDelay(10000);
go.setPauseOnMouseOver(true);
go.setAllowDismiss(false);
go.setZIndex(Z_INDEX);
Notify.notify(text, go);
}
public static void cleanAll() {
Notify.hideAll();
}
public static void restError(String text, Throwable throwable) {
try {
throw throwable;
} catch (ResponseException e) {
Response response = e.getResponse();
Messages.error(text + " " + response.getStatusCode() + " (" + response.getStatusText() + ") " + response.getText());
} catch (Throwable t) {
Messages.error(text + " " + t);
}
}
}