Pārlūkot izejas kodu

Use Notification.show(Page) as the official entry point (#8907)

Also remove some static shorthands
tags/7.0.0.alpha3
Leif Åstrand pirms 12 gadiem
vecāks
revīzija
fee6f30696

+ 3
- 4
src/com/vaadin/terminal/Page.java Parādīt failu

@@ -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);
}

+ 15
- 80
src/com/vaadin/ui/Notification.java Parādīt failu

@@ -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());
}
}

+ 13
- 8
tests/testbench/com/vaadin/tests/TestComponentAddAndRecursion.java Parādīt failu

@@ -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());
}
}


+ 2
- 1
tests/testbench/com/vaadin/tests/components/notification/Notifications.java Parādīt failu

@@ -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());
}
}

+ 2
- 1
tests/testbench/com/vaadin/tests/components/notification/NotificationsHtmlAllowed.java Parādīt failu

@@ -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() {

+ 4
- 5
tests/testbench/com/vaadin/tests/integration/JSR286PortletRoot.java Parādīt failu

@@ -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

+ 11
- 8
tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java Parādīt failu

@@ -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());

}
});

Notiek ielāde…
Atcelt
Saglabāt