001    package org.gwtbootstrap3.extras.notify.client.ui;
002    
003    /*
004     * #%L
005     * GwtBootstrap3
006     * %%
007     * Copyright (C) 2013 - 2015 GwtBootstrap3
008     * %%
009     * Licensed under the Apache License, Version 2.0 (the "License");
010     * you may not use this file except in compliance with the License.
011     * You may obtain a copy of the License at
012     * 
013     *      http://www.apache.org/licenses/LICENSE-2.0
014     * 
015     * Unless required by applicable law or agreed to in writing, software
016     * distributed under the License is distributed on an "AS IS" BASIS,
017     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018     * See the License for the specific language governing permissions and
019     * limitations under the License.
020     * #L%
021     */
022    
023    import org.gwtbootstrap3.client.ui.constants.IconType;
024    import org.gwtbootstrap3.client.ui.constants.Styles;
025    import org.gwtbootstrap3.extras.notify.client.constants.NotifyPlacement;
026    import org.gwtbootstrap3.extras.notify.client.constants.NotifyType;
027    
028    import com.google.gwt.core.client.JavaScriptObject;
029    
030    /**
031     * This class represent instance of displayed Notify.
032     * <p/>
033     * You can display new Notify using static methods, e.g.:
034     * {@link #notify(String)},
035     * {@link #notify(String, NotifyType)},
036     * {@link #notify(String, NotifySettings)} and others
037     * <p/>
038     * To further configure Notify before displaying see:
039     * {@see org.gwtbootstrap3.extras.notify.client.ui.NotifySettings}
040     * <p/>
041     * You can update displayed Notify by:
042     * {@link #updateTitle(String)},
043     * {@link #updateMessage(String)},
044     * {@link #updateIcon(String)},
045     * {@link #updateType(NotifyType)},
046     * <p/>
047     * You can hide displayed Notify:
048     * {@link #hide()},
049     * {@link #hideAll()},
050     * {@link #hideAll(NotifyPlacement)}
051     *
052     * @author jeffisenhart
053     * @author Sven Jacobs
054     * @author Joshua Godi
055     * @author Pavel Zlámal
056     */
057    public class Notify extends JavaScriptObject {
058    
059        protected Notify() {
060        }
061    
062        /**
063         * Display Notify with custom message, and default settings.
064         *
065         * @param message Message to set
066         * @return Displayed Notify for update or hiding.
067         */
068        public static final native Notify notify(final String message) /*-{
069            return $wnd.jQuery.notify({ message: message }, null);
070        }-*/;
071    
072        /**
073         * Display Notify with custom title, message, and default settings.
074         *
075         * @param title   Title to set
076         * @param message Message to set
077         * @return Displayed Notify for update or hiding.
078         */
079        public static final native Notify notify(final String title, final String message) /*-{
080            return $wnd.jQuery.notify({ title: title, message: message }, null);
081        }-*/;
082    
083        /**
084         * Display Notify with custom title, message, icon, and default settings.
085         *
086         * @param title   Title to set
087         * @param message Message to set
088         * @param icon    Icon to set
089         * @return Displayed Notify for update or hiding.
090         */
091        public static final native Notify notify(final String title, final String message, final String icon) /*-{
092            return $wnd.jQuery.notify({ title: title, message: message, icon: icon }, null);
093        }-*/;
094    
095        /**
096         * Display Notify with custom title, message, icon, and default settings.
097         *
098         * @param title    Title to set
099         * @param message  Message to set
100         * @param iconType IconType to set
101         * @return Displayed Notify for update or hiding.
102         */
103        public static final Notify notify(final String title, final String message, final IconType iconType) {
104            return Notify.notify(title, message, Styles.FONT_AWESOME_BASE + " " + iconType.getCssName());
105        }
106    
107        /**
108         * Display Notify with custom title, message, icon, URL, and default settings.
109         *
110         * @param title   Title to set
111         * @param message Message to set
112         * @param icon    IconType to set
113         * @param url     Url to set
114         * @return Displayed Notify for update or hiding.
115         */
116        public static final native Notify notify(final String title, final String message, final String icon, final String url) /*-{
117            return $wnd.jQuery.notify({ title: title, message: message, icon: icon, url: url }, null);
118        }-*/;
119    
120        /**
121         * Display Notify with custom title, message, icon, url and default settings.
122         *
123         * @param title    Title to set
124         * @param message  Message to set
125         * @param iconType IconType to set
126         * @param url      Url to set
127         * @return Displayed Notify for update or hiding.
128         */
129        public static final Notify notify(final String title, final String message, final IconType iconType, final String url) {
130            return Notify.notify(title, message, Styles.FONT_AWESOME_BASE + " " + iconType.getCssName(), url);
131        }
132    
133        /**
134         * Display Notify with custom message, type and default settings.
135         *
136         * @param message Message to set
137         * @param type    NotifyType
138         * @return Displayed Notify for update or hiding.
139         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyType
140         */
141        public static final native Notify notify(final String message, final NotifyType type) /*-{
142            return $wnd.jQuery.notify({ message: message }, { type: type.@org.gwtbootstrap3.extras.notify.client.constants.NotifyType::getCssName()() });
143        }-*/;
144    
145        /**
146         * Display Notify with custom title, message, type and default settings.
147         *
148         * @param title   Title to set
149         * @param message Message to set
150         * @param type    NotifyType
151         * @return Displayed Notify for update or hiding.
152         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyType
153         */
154        public static final native Notify notify(final String title, final String message, final NotifyType type) /*-{
155            return $wnd.jQuery.notify({ title: title, message: message }, { type: type.@org.gwtbootstrap3.extras.notify.client.constants.NotifyType::getCssName()() });
156        }-*/;
157    
158        /**
159         * Display Notify with custom title, message, icon, type and default settings.
160         *
161         * @param title   Title to set
162         * @param message Message to set
163         * @param icon    Icon to set
164         * @param type    NotifyType
165         * @return Displayed Notify for update or hiding.
166         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyType
167         */
168        public static final native Notify notify(final String title, final String message, final String icon, final NotifyType type) /*-{
169            return $wnd.jQuery.notify({ title: title, message: message, icon: icon }, { type: type.@org.gwtbootstrap3.extras.notify.client.constants.NotifyType::getCssName()() });
170        }-*/;
171    
172        /**
173         * Display Notify with custom title, message, icon, type and default settings.
174         *
175         * @param title    Title to set
176         * @param message  Message to set
177         * @param iconType IconType to set (css name of icon form FONT AWESOME)
178         * @param type     NotifyType
179         * @return Displayed Notify for update or hiding.
180         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyType
181         */
182        public static final Notify notify(final String title, final String message, final IconType iconType, final NotifyType type) {
183            return Notify.notify(title, message, Styles.FONT_AWESOME_BASE + " " + iconType.getCssName(), type);
184        }
185    
186        /**
187         * Display Notify with custom title, message, icon, url, type and default settings.
188         *
189         * @param title   Title to set
190         * @param message Message to set
191         * @param icon    Icon to set
192         * @param url     Url to set
193         * @param type    NotifyType
194         * @return Displayed Notify for update or hiding.
195         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyType
196         */
197        public static final native Notify notify(final String title, final String message, final String icon, final String url, final NotifyType type) /*-{
198            return $wnd.jQuery.notify({ title: title, message: message, icon: icon, url: url }, { type: type.@org.gwtbootstrap3.extras.notify.client.constants.NotifyType::getCssName()() });
199        }-*/;
200    
201        /**
202         * Display Notify with custom title, message, icon, url, type and default settings.
203         *
204         * @param title    Title to set
205         * @param message  Message to set
206         * @param iconType IconType to set (css name of icon form FONT AWESOME)
207         * @param url      Url to set
208         * @param type     NotifyType
209         * @return Displayed Notify for update or hiding.
210         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyType
211         */
212        public static final Notify notify(final String title, final String message, final IconType iconType, final String url, final NotifyType type) {
213            return Notify.notify(title, message, Styles.FONT_AWESOME_BASE + " " + iconType.getCssName(), url, type);
214        }
215    
216        /**
217         * Display Notify with custom message and custom settings.
218         *
219         * @param message Message to set
220         * @param settings custom settings
221         * @return Displayed Notify for update or hiding.
222         * @see org.gwtbootstrap3.extras.notify.client.ui.NotifySettings
223         */
224        public static final native Notify notify(final String message, final NotifySettings settings) /*-{
225            return $wnd.jQuery.notify({ message: message }, settings);
226        }-*/;
227    
228        /**
229         * Display Notify with custom title, message and custom settings.
230         *
231         * @param title   Title to set
232         * @param message Message to set
233         * @param settings custom settings
234         * @return Displayed Notify for update or hiding.
235         * @see org.gwtbootstrap3.extras.notify.client.ui.NotifySettings
236         */
237        public static final native Notify notify(final String title, final String message, final NotifySettings settings) /*-{
238            return $wnd.jQuery.notify({ title: title, message: message }, settings);
239        }-*/;
240    
241        /**
242         * Display Notify with custom title, message, icon and custom settings.
243         *
244         * @param title   Title to set
245         * @param message Message to set
246         * @param icon    Icon to set
247         * @param settings custom settings
248         * @return Displayed Notify for update or hiding.
249         * @see org.gwtbootstrap3.extras.notify.client.ui.NotifySettings
250         */
251        public static final native Notify notify(final String title, final String message, final String icon, final NotifySettings settings) /*-{
252            return $wnd.jQuery.notify({ title: title, message: message, icon: icon }, settings);
253        }-*/;
254    
255        /**
256         * Display Notify with custom title, message, icon and custom settings.
257         *
258         * @param title    Title to set
259         * @param message  Message to set
260         * @param iconType IconType to set (css name of icon form FONT AWESOME)
261         * @param settings  custom settings
262         * @return Displayed Notify for update or hiding.
263         * @see org.gwtbootstrap3.extras.notify.client.ui.NotifySettings
264         */
265        public static final Notify notify(final String title, final String message, final IconType iconType, final NotifySettings settings) {
266            return Notify.notify(title, message, Styles.FONT_AWESOME_BASE + " " + iconType.getCssName(), settings);
267        }
268    
269        /**
270         * Display Notify with custom title, message, icon, URL and custom settings.
271         *
272         * @param title   Title to set
273         * @param message Message to set
274         * @param icon    Icon to set
275         * @param url     Url to set
276         * @param settings custom settings
277         * @return Displayed Notify for update or hiding.
278         * @see org.gwtbootstrap3.extras.notify.client.ui.NotifySettings
279         */
280        public static final native Notify notify(final String title, final String message, final String icon, final String url, final NotifySettings settings) /*-{
281            return $wnd.jQuery.notify({ title: title, message: message, icon: icon, url: url}, settings);
282        }-*/;
283    
284        /**
285         * Display Notify with custom title, message, icon, URL and custom settings.
286         *
287         * @param title    Title to set
288         * @param message  Message to set
289         * @param iconType IconType to set
290         * @param url      Url to set
291         * @param settings custom settings
292         * @return Displayed Notify for update or hiding.
293         * @see org.gwtbootstrap3.extras.notify.client.ui.NotifySettings
294         */
295        public static final Notify notify(final String title, final String message, final IconType iconType, final String url, final NotifySettings settings) {
296            return Notify.notify(title, message, Styles.FONT_AWESOME_BASE + " " + iconType.getCssName(), url, settings);
297        }
298    
299        /**
300         * Hide all displayed Notifies.
301         */
302        public static final native void hideAll() /*-{
303            $wnd.jQuery.notifyClose();
304        }-*/;
305    
306        /**
307         * Hide all displayed Notifies on specific screen location.
308         *
309         * @param placement Notify's placement on screen.
310         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyPlacement
311         */
312        public static final native void hideAll(NotifyPlacement placement) /*-{
313            if (plamenet !== null) {
314                $wnd.jQuery.notifyClose(placement.@org.gwtbootstrap3.extras.notify.client.constants.NotifyPlacement::getPlacement()());
315            }
316        }-*/;
317    
318        /**
319         * Updates title parameter of once displayed Notify.
320         *
321         * @param title Title to set
322         */
323        public final native void updateTitle(String title) /*-{
324            this.update('title', title);
325        }-*/;
326    
327        /**
328         * Updates message parameter of once displayed Notify.
329         *
330         * @param message Message to set
331         */
332        public final native void updateMessage(String message) /*-{
333            this.update('message', message);
334        }-*/;
335    
336        /**
337         * Updates Icon parameter of once displayed Notify.
338         *
339         * @param icon Icon to set
340         */
341        public final native void updateIcon(String icon) /*-{
342            this.update('icon', icon);
343        }-*/;
344    
345        /**
346         * Updates Icon parameter of once displayed Notify.
347         * This method is shortcut when using FONT AWESOME iconic font.
348         *
349         * @param type IconType to get CSS class name to set
350         */
351        public final void updateIcon(final IconType type) {
352            if (type != null) updateIcon(Styles.FONT_AWESOME_BASE + " " + type.getCssName());
353        }
354    
355        /**
356         * Update type of once displayed Notify (CSS style class name).
357         *
358         * @param type one of INFO, WARNING, DANGER, SUCCESS
359         * @see org.gwtbootstrap3.extras.notify.client.constants.NotifyType
360         */
361        public final void updateType(final NotifyType type) {
362            if (type != null) {
363                updateType(type.getCssName());
364            }
365        }
366    
367        /**
368         * Update type of once displayed Notify (CSS style class name).
369         * Resulting class name to use is "alert-[type]".
370         *
371         * @param type CSS class name to set
372         */
373        private final native void updateType(String type) /*-{
374            this.update('type', type);
375        }-*/;
376    
377        /**
378         * Update URL target of once displayed Notify.
379         *
380         * @param target URL target to set
381         */
382        private final native void updateTarget(String target) /*-{
383            this.update('target', target);
384        }-*/;
385    
386        /**
387         * Hide this Notify.
388         */
389        public final native void hide() /*-{
390            this.close();
391        }-*/;
392    
393    }