| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.ui.client.widgets.notification; |
| 17 | |
|
| 18 | |
import org.kuali.student.common.ui.client.mvc.Holder; |
| 19 | |
import org.kuali.student.common.ui.client.util.Elements; |
| 20 | |
|
| 21 | |
import com.google.gwt.event.logical.shared.CloseEvent; |
| 22 | |
import com.google.gwt.event.logical.shared.CloseHandler; |
| 23 | |
import com.google.gwt.event.shared.HandlerRegistration; |
| 24 | |
import com.google.gwt.user.client.Timer; |
| 25 | |
import com.google.gwt.user.client.ui.FlowPanel; |
| 26 | |
import com.google.gwt.user.client.ui.RootPanel; |
| 27 | |
|
| 28 | 0 | public class KSNotifier { |
| 29 | 0 | private static final FlowPanel notifier = new FlowPanel(); |
| 30 | |
|
| 31 | |
public static final int FADE_DURATION = 1000; |
| 32 | |
|
| 33 | |
private static final int DEFAULT_FADE_DURATION = 4000; |
| 34 | |
|
| 35 | |
static { |
| 36 | 0 | notifier.setStyleName("ks-notification-container"); |
| 37 | 0 | } |
| 38 | |
|
| 39 | 0 | private KSNotifier() { |
| 40 | |
|
| 41 | 0 | } |
| 42 | |
|
| 43 | |
public static void show(String message) { |
| 44 | 0 | add(new KSNotification(message, false, DEFAULT_FADE_DURATION)); |
| 45 | 0 | } |
| 46 | |
|
| 47 | |
public static void add(final KSNotification notification) { |
| 48 | 0 | if (notifier.getWidgetCount() == 0) { |
| 49 | 0 | RootPanel.get().add(notifier); |
| 50 | |
} |
| 51 | |
|
| 52 | 0 | final Holder<HandlerRegistration> reg = new Holder<HandlerRegistration>(); |
| 53 | 0 | reg.set(notification.addCloseHandler(new CloseHandler<KSNotification>() { |
| 54 | |
@Override |
| 55 | |
public void onClose(CloseEvent<KSNotification> event) { |
| 56 | 0 | reg.get().removeHandler(); |
| 57 | 0 | remove(notification, false); |
| 58 | 0 | } |
| 59 | |
})); |
| 60 | |
|
| 61 | 0 | Elements.setOpacity(notification.getElement(), 0); |
| 62 | 0 | notifier.add(notification); |
| 63 | 0 | Elements.fadeIn(notification, FADE_DURATION, 85, new Elements.FadeCallback() { |
| 64 | |
|
| 65 | |
@Override |
| 66 | |
public void onFadeStart() { |
| 67 | |
|
| 68 | 0 | } |
| 69 | |
|
| 70 | |
@Override |
| 71 | |
public void onFadeComplete() { |
| 72 | 0 | new Timer() { |
| 73 | |
@Override |
| 74 | |
public void run() { |
| 75 | 0 | reg.get().removeHandler(); |
| 76 | 0 | remove(notification, true); |
| 77 | 0 | } |
| 78 | |
}.schedule(notification.getDuration()); |
| 79 | 0 | } |
| 80 | |
}); |
| 81 | |
|
| 82 | 0 | } |
| 83 | |
|
| 84 | |
public static void remove(final KSNotification notification, final boolean fireEvents) { |
| 85 | 0 | if (notifier.getWidgetIndex(notification) != -1) { |
| 86 | 0 | Elements.fadeOut(notification, FADE_DURATION, 0, new Elements.FadeCallback() { |
| 87 | |
@Override |
| 88 | |
public void onFadeStart() { |
| 89 | |
|
| 90 | 0 | } |
| 91 | |
|
| 92 | |
@Override |
| 93 | |
public void onFadeComplete() { |
| 94 | 0 | notifier.remove(notification); |
| 95 | 0 | if (fireEvents) { |
| 96 | 0 | CloseEvent.fire(notification, notification); |
| 97 | |
} |
| 98 | 0 | if (notifier.getWidgetCount() == 0) { |
| 99 | 0 | RootPanel.get().remove(notifier); |
| 100 | |
} |
| 101 | 0 | } |
| 102 | |
}); |
| 103 | |
} |
| 104 | 0 | } |
| 105 | |
} |