From: Leif Åstrand Date: Mon, 25 Jun 2012 12:31:29 +0000 (+0300) Subject: Use Notification.show(Page) as the official entry point (#8907) X-Git-Tag: 7.0.0.alpha3~66 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fee6f306961ffff67809c33715c719075ba2c450;p=vaadin-framework.git Use Notification.show(Page) as the official entry point (#8907) Also remove some static shorthands --- diff --git a/src/com/vaadin/terminal/Page.java b/src/com/vaadin/terminal/Page.java index 65fa500d27..8506e17898 100644 --- a/src/com/vaadin/terminal/Page.java +++ b/src/com/vaadin/terminal/Page.java @@ -603,14 +603,13 @@ public class Page implements Serializable { * Shows a notification message. * * @see Notification - * @see #showNotification(String) - * @see #showNotification(String, int) - * @see #showNotification(String, String) - * @see #showNotification(String, String, int) * * @param notification * The notification message to show + * + * @deprecated Use Notification.show(Page) instead. */ + @Deprecated public void showNotification(Notification notification) { addNotification(notification); } diff --git a/src/com/vaadin/ui/Notification.java b/src/com/vaadin/ui/Notification.java index 075ab50196..0358283cb4 100644 --- a/src/com/vaadin/ui/Notification.java +++ b/src/com/vaadin/ui/Notification.java @@ -320,8 +320,15 @@ public class Notification implements Serializable { return htmlContentAllowed; } - public void show() { - Page.getCurrent().showNotification(this); + /** + * Shows this notification on a Page. + * + * @param page + * The page on which the notification should be shown + */ + public void show(Page page) { + // TODO Can avoid deprecated API when Notification extends Extension + page.showNotification(this); } /** @@ -331,14 +338,14 @@ public class Notification implements Serializable { * Care should be taken to to avoid XSS vulnerabilities as the caption is * rendered as html. * - * @see #showNotification(Notification) - * @see Notification + * @see #Notification(String) + * @see #show(Page) * * @param caption * The message */ public static void show(String caption) { - new Notification(caption).show(); + new Notification(caption).show(Page.getCurrent()); } /** @@ -350,8 +357,8 @@ public class Notification implements Serializable { * Care should be taken to to avoid XSS vulnerabilities as the caption is * rendered as html. * - * @see #showNotification(Notification) - * @see Notification + * @see #Notification(String, int) + * @see #show(Page) * * @param caption * The message @@ -359,78 +366,6 @@ public class Notification implements Serializable { * The message type */ public static void show(String caption, int type) { - new Notification(caption, type).show(); - } - - /** - * Shows a notification consisting of a bigger caption and a smaller - * description on the middle of the current page. The message automatically - * disappears ("humanized message"). - * - * Care should be taken to to avoid XSS vulnerabilities as the caption and - * description are rendered as html. - * - * @see #showNotification(Notification) - * @see Notification - * - * @param caption - * The caption of the message - * @param description - * The message description - * - */ - public static void show(String caption, String description) { - new Notification(caption, description).show(); - } - - /** - * Shows a notification consisting of a bigger caption and a smaller - * description. The position and behavior of the message depends on the - * type, which is one of the basic types defined in {@link Notification}, - * for instance Notification.TYPE_WARNING_MESSAGE. - * - * Care should be taken to to avoid XSS vulnerabilities as the caption and - * description are rendered as html. - * - * @see #showNotification(Notification) - * @see Notification - * - * @param caption - * The caption of the message - * @param description - * The message description - * @param type - * The message type - */ - public static void show(String caption, String description, int type) { - - new Notification(caption, description, type).show(); - } - - /** - * Shows a notification consisting of a bigger caption and a smaller - * description. The position and behavior of the message depends on the - * type, which is one of the basic types defined in {@link Notification}, - * for instance Notification.TYPE_WARNING_MESSAGE. - * - * Care should be taken to avoid XSS vulnerabilities if html content is - * allowed. - * - * @see #showNotification(Notification) - * @see Notification - * - * @param caption - * The message caption - * @param description - * The message description - * @param type - * The type of message - * @param htmlContentAllowed - * Whether html in the caption and description should be - * displayed as html or as plain text - */ - public static void show(String caption, String description, int type, - boolean htmlContentAllowed) { - new Notification(caption, description, type, htmlContentAllowed).show(); + new Notification(caption, type).show(Page.getCurrent()); } } \ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/TestComponentAddAndRecursion.java b/tests/testbench/com/vaadin/tests/TestComponentAddAndRecursion.java index c63c0caf16..3adaff93ea 100644 --- a/tests/testbench/com/vaadin/tests/TestComponentAddAndRecursion.java +++ b/tests/testbench/com/vaadin/tests/TestComponentAddAndRecursion.java @@ -3,6 +3,7 @@ */ package com.vaadin.tests; +import com.vaadin.terminal.Page; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.CustomComponent; @@ -91,11 +92,13 @@ public class TestComponentAddAndRecursion extends CustomComponent { public void buttonClick(ClickEvent event) { try { p3.addComponent(p2); - Notification.show("ERROR", "This should have failed", - Notification.TYPE_ERROR_MESSAGE); + new Notification("ERROR", "This should have failed", + Notification.TYPE_ERROR_MESSAGE).show(Page + .getCurrent()); } catch (Exception e) { - Notification.show("OK", "threw, as expected", - Notification.TYPE_ERROR_MESSAGE); + new Notification("OK", "threw, as expected", + Notification.TYPE_ERROR_MESSAGE).show(Page + .getCurrent()); } } @@ -108,11 +111,13 @@ public class TestComponentAddAndRecursion extends CustomComponent { p.addComponent(p2); try { p3.addComponent(p); - Notification.show("ERROR", "This should have failed", - Notification.TYPE_ERROR_MESSAGE); + new Notification("ERROR", "This should have failed", + Notification.TYPE_ERROR_MESSAGE).show(Page + .getCurrent()); } catch (Exception e) { - Notification.show("OK", "threw, as expected", - Notification.TYPE_ERROR_MESSAGE); + new Notification("OK", "threw, as expected", + Notification.TYPE_ERROR_MESSAGE).show(Page + .getCurrent()); } } diff --git a/tests/testbench/com/vaadin/tests/components/notification/Notifications.java b/tests/testbench/com/vaadin/tests/components/notification/Notifications.java index a36fbe3121..5a158c8f03 100644 --- a/tests/testbench/com/vaadin/tests/components/notification/Notifications.java +++ b/tests/testbench/com/vaadin/tests/components/notification/Notifications.java @@ -1,5 +1,6 @@ package com.vaadin.tests.components.notification; +import com.vaadin.terminal.Page; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -52,6 +53,6 @@ public class Notifications extends TestBase implements ClickListener { public void buttonClick(ClickEvent event) { Notification n = new Notification(tf.getValue(), (Integer) type.getValue()); - n.show(); + n.show(Page.getCurrent()); } } diff --git a/tests/testbench/com/vaadin/tests/components/notification/NotificationsHtmlAllowed.java b/tests/testbench/com/vaadin/tests/components/notification/NotificationsHtmlAllowed.java index a16b8edcde..8e42db57f3 100644 --- a/tests/testbench/com/vaadin/tests/components/notification/NotificationsHtmlAllowed.java +++ b/tests/testbench/com/vaadin/tests/components/notification/NotificationsHtmlAllowed.java @@ -1,5 +1,6 @@ package com.vaadin.tests.components.notification; +import com.vaadin.terminal.Page; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -45,7 +46,7 @@ public class NotificationsHtmlAllowed extends TestBase implements ClickListener public void buttonClick(ClickEvent event) { Notification n = makeNotification(); - n.show(); + n.show(Page.getCurrent()); } private Notification makeNotification() { diff --git a/tests/testbench/com/vaadin/tests/integration/JSR286PortletRoot.java b/tests/testbench/com/vaadin/tests/integration/JSR286PortletRoot.java index 913ce8f54c..b4de4fd3da 100644 --- a/tests/testbench/com/vaadin/tests/integration/JSR286PortletRoot.java +++ b/tests/testbench/com/vaadin/tests/integration/JSR286PortletRoot.java @@ -109,11 +109,10 @@ public class JSR286PortletRoot extends Root { tf.setEnabled((request.getPortletMode() == PortletMode.EDIT)); // Show notification about current mode and state - Notification.show( - "Portlet status", - "Mode: " + request.getPortletMode() + " State: " - + request.getWindowState(), - Notification.TYPE_WARNING_MESSAGE); + new Notification("Portlet status", "Mode: " + + request.getPortletMode() + " State: " + + request.getWindowState(), + Notification.TYPE_WARNING_MESSAGE).show(getPage()); // Display current user info Map uinfo = (Map) request diff --git a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java index 8b7f498b0e..9397206f1e 100644 --- a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java +++ b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java @@ -9,6 +9,7 @@ import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.event.Action; import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.Page; import com.vaadin.terminal.Resource; import com.vaadin.terminal.ThemeResource; import com.vaadin.terminal.gwt.client.ui.label.ContentMode; @@ -595,8 +596,8 @@ public class LiferayThemeDemo extends Application.LegacyApplication { Button show = new Button("Humanized Notification", new Button.ClickListener() { public void buttonClick(ClickEvent event) { - Notification.show(title.getValue(), message.getValue()); - + new Notification(title.getValue(), message.getValue()) + .show(Page.getCurrent()); } }); l.addComponent(show); @@ -604,8 +605,9 @@ public class LiferayThemeDemo extends Application.LegacyApplication { l.addComponent(new Label("Warning", ContentMode.XHTML)); show = new Button("Warning Notification", new Button.ClickListener() { public void buttonClick(ClickEvent event) { - Notification.show(title.getValue(), message.getValue(), - Notification.TYPE_WARNING_MESSAGE); + new Notification(title.getValue(), message.getValue(), + Notification.TYPE_WARNING_MESSAGE).show(Page + .getCurrent()); } }); @@ -614,8 +616,8 @@ public class LiferayThemeDemo extends Application.LegacyApplication { l.addComponent(new Label("Error", ContentMode.XHTML)); show = new Button("Error Notification", new Button.ClickListener() { public void buttonClick(ClickEvent event) { - Notification.show(title.getValue(), message.getValue(), - Notification.TYPE_ERROR_MESSAGE); + new Notification(title.getValue(), message.getValue(), + Notification.TYPE_ERROR_MESSAGE).show(Page.getCurrent()); } }); @@ -624,8 +626,9 @@ public class LiferayThemeDemo extends Application.LegacyApplication { l.addComponent(new Label("Tray", ContentMode.XHTML)); show = new Button("Tray Notification", new Button.ClickListener() { public void buttonClick(ClickEvent event) { - Notification.show(title.getValue(), message.getValue(), - Notification.TYPE_TRAY_NOTIFICATION); + new Notification(title.getValue(), message.getValue(), + Notification.TYPE_TRAY_NOTIFICATION).show(Page + .getCurrent()); } });