summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java36
-rw-r--r--server/src/com/vaadin/terminal/Page.java4
-rw-r--r--server/src/com/vaadin/ui/Notification.java66
-rw-r--r--server/src/com/vaadin/ui/Root.java9
-rwxr-xr-xshared/src/com/vaadin/shared/Position.java20
-rw-r--r--tests/testbench/com/vaadin/tests/components/notification/Notifications.java4
6 files changed, 90 insertions, 49 deletions
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java b/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java
index 6e253c9137..b4cea2dc72 100644
--- a/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java
@@ -29,6 +29,7 @@ import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.shared.Position;
import com.vaadin.shared.ui.root.RootConstants;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
@@ -38,13 +39,13 @@ import com.vaadin.terminal.gwt.client.ui.VOverlay;
public class VNotification extends VOverlay {
- public static final int CENTERED = 1;
- public static final int CENTERED_TOP = 2;
- public static final int CENTERED_BOTTOM = 3;
- public static final int TOP_LEFT = 4;
- public static final int TOP_RIGHT = 5;
- public static final int BOTTOM_LEFT = 6;
- public static final int BOTTOM_RIGHT = 7;
+ public static final Position CENTERED = Position.MIDDLE_CENTER;
+ public static final Position CENTERED_TOP = Position.TOP_CENTER;
+ public static final Position CENTERED_BOTTOM = Position.BOTTOM_CENTER;
+ public static final Position TOP_LEFT = Position.TOP_LEFT;
+ public static final Position TOP_RIGHT = Position.TOP_RIGHT;
+ public static final Position BOTTOM_LEFT = Position.BOTTOM_LEFT;
+ public static final Position BOTTOM_RIGHT = Position.BOTTOM_RIGHT;
public static final int DELAY_FOREVER = -1;
public static final int DELAY_NONE = 0;
@@ -144,21 +145,21 @@ public class VNotification extends VOverlay {
show(CENTERED, style);
}
- public void show(int position) {
+ public void show(com.vaadin.shared.Position position) {
show(position, null);
}
- public void show(Widget widget, int position, String style) {
+ public void show(Widget widget, Position position, String style) {
setWidget(widget);
show(position, style);
}
- public void show(String html, int position, String style) {
+ public void show(String html, Position position, String style) {
setWidget(new HTML(html));
show(position, style);
}
- public void show(int position, String style) {
+ public void show(Position position, String style) {
setOpacity(getElement(), startOpacity);
if (style != null) {
temporaryStyle = style;
@@ -231,7 +232,7 @@ public class VNotification extends VOverlay {
}
}
- public void setPosition(int position) {
+ public void setPosition(com.vaadin.shared.Position position) {
final Element el = getElement();
DOM.setStyleAttribute(el, "top", "");
DOM.setStyleAttribute(el, "left", "");
@@ -260,17 +261,17 @@ public class VNotification extends VOverlay {
DOM.setStyleAttribute(el, "bottom", "0px");
DOM.setStyleAttribute(el, "left", "0px");
break;
- case CENTERED_TOP:
+ case TOP_CENTER:
center();
DOM.setStyleAttribute(el, "top", "0px");
break;
- case CENTERED_BOTTOM:
+ case BOTTOM_CENTER:
center();
DOM.setStyleAttribute(el, "top", "");
DOM.setStyleAttribute(el, "bottom", "0px");
break;
default:
- case CENTERED:
+ case MIDDLE_CENTER:
center();
break;
}
@@ -417,8 +418,11 @@ public class VNotification extends VOverlay {
.hasAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_STYLE) ? notification
.getStringAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_STYLE)
: null;
- final int position = notification
+
+ final int pos = notification
.getIntAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_POSITION);
+ Position position = Position.values()[pos];
+
final int delay = notification
.getIntAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_DELAY);
createNotification(delay).show(html, position, style);
diff --git a/server/src/com/vaadin/terminal/Page.java b/server/src/com/vaadin/terminal/Page.java
index d41d500bb0..41ab8cc8b6 100644
--- a/server/src/com/vaadin/terminal/Page.java
+++ b/server/src/com/vaadin/terminal/Page.java
@@ -493,8 +493,8 @@ public class Page implements Serializable {
true);
}
target.addAttribute(
- RootConstants.ATTRIBUTE_NOTIFICATION_POSITION,
- n.getPosition());
+ RootConstants.ATTRIBUTE_NOTIFICATION_POSITION, n
+ .getPosition().ordinal());
target.addAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_DELAY,
n.getDelayMsec());
if (n.getStyleName() != null) {
diff --git a/server/src/com/vaadin/ui/Notification.java b/server/src/com/vaadin/ui/Notification.java
index d408889519..22ad31dffe 100644
--- a/server/src/com/vaadin/ui/Notification.java
+++ b/server/src/com/vaadin/ui/Notification.java
@@ -18,6 +18,7 @@ package com.vaadin.ui;
import java.io.Serializable;
+import com.vaadin.shared.Position;
import com.vaadin.terminal.Page;
import com.vaadin.terminal.Resource;
@@ -61,18 +62,33 @@ import com.vaadin.terminal.Resource;
*
*/
public class Notification implements Serializable {
- public static final int TYPE_HUMANIZED_MESSAGE = 1;
- public static final int TYPE_WARNING_MESSAGE = 2;
- public static final int TYPE_ERROR_MESSAGE = 3;
- public static final int TYPE_TRAY_NOTIFICATION = 4;
-
- public static final int POSITION_CENTERED = 1;
- public static final int POSITION_CENTERED_TOP = 2;
- public static final int POSITION_CENTERED_BOTTOM = 3;
- public static final int POSITION_TOP_LEFT = 4;
- public static final int POSITION_TOP_RIGHT = 5;
- public static final int POSITION_BOTTOM_LEFT = 6;
- public static final int POSITION_BOTTOM_RIGHT = 7;
+ public enum Type {
+ HUMANIZED_MESSAGE, WARNING_MESSAGE, ERROR_MESSAGE, TRAY_NOTIFICATION;
+ }
+
+ @Deprecated
+ public static final Type TYPE_HUMANIZED_MESSAGE = Type.HUMANIZED_MESSAGE;
+ @Deprecated
+ public static final Type TYPE_WARNING_MESSAGE = Type.WARNING_MESSAGE;
+ @Deprecated
+ public static final Type TYPE_ERROR_MESSAGE = Type.ERROR_MESSAGE;
+ @Deprecated
+ public static final Type TYPE_TRAY_NOTIFICATION = Type.TRAY_NOTIFICATION;
+
+ @Deprecated
+ public static final Position POSITION_CENTERED = Position.MIDDLE_CENTER;
+ @Deprecated
+ public static final Position POSITION_CENTERED_TOP = Position.TOP_CENTER;
+ @Deprecated
+ public static final Position POSITION_CENTERED_BOTTOM = Position.BOTTOM_CENTER;
+ @Deprecated
+ public static final Position POSITION_TOP_LEFT = Position.TOP_LEFT;
+ @Deprecated
+ public static final Position POSITION_TOP_RIGHT = Position.TOP_RIGHT;
+ @Deprecated
+ public static final Position POSITION_BOTTOM_LEFT = Position.BOTTOM_LEFT;
+ @Deprecated
+ public static final Position POSITION_BOTTOM_RIGHT = Position.BOTTOM_RIGHT;
public static final int DELAY_FOREVER = -1;
public static final int DELAY_NONE = 0;
@@ -80,7 +96,7 @@ public class Notification implements Serializable {
private String caption;
private String description;
private Resource icon;
- private int position = POSITION_CENTERED;
+ private Position position = Position.MIDDLE_CENTER;
private int delayMsec = 0;
private String styleName;
private boolean htmlContentAllowed;
@@ -107,7 +123,7 @@ public class Notification implements Serializable {
* @param type
* The type of message
*/
- public Notification(String caption, int type) {
+ public Notification(String caption, Type type) {
this(caption, null, type);
}
@@ -141,7 +157,7 @@ public class Notification implements Serializable {
* @param type
* The type of message
*/
- public Notification(String caption, String description, int type) {
+ public Notification(String caption, String description, Type type) {
this(caption, description, type, false);
}
@@ -161,7 +177,7 @@ public class Notification implements Serializable {
* Whether html in the caption and description should be
* displayed as html or as plain text
*/
- public Notification(String caption, String description, int type,
+ public Notification(String caption, String description, Type type,
boolean htmlContentAllowed) {
this.caption = caption;
this.description = description;
@@ -169,22 +185,22 @@ public class Notification implements Serializable {
setType(type);
}
- private void setType(int type) {
+ private void setType(Type type) {
switch (type) {
- case TYPE_WARNING_MESSAGE:
+ case WARNING_MESSAGE:
delayMsec = 1500;
styleName = "warning";
break;
- case TYPE_ERROR_MESSAGE:
+ case ERROR_MESSAGE:
delayMsec = -1;
styleName = "error";
break;
- case TYPE_TRAY_NOTIFICATION:
+ case TRAY_NOTIFICATION:
delayMsec = 3000;
- position = POSITION_BOTTOM_RIGHT;
+ position = Position.BOTTOM_RIGHT;
styleName = "tray";
- case TYPE_HUMANIZED_MESSAGE:
+ case HUMANIZED_MESSAGE:
default:
break;
}
@@ -233,7 +249,7 @@ public class Notification implements Serializable {
*
* @return The position
*/
- public int getPosition() {
+ public Position getPosition() {
return position;
}
@@ -243,7 +259,7 @@ public class Notification implements Serializable {
* @param position
* The desired notification position
*/
- public void setPosition(int position) {
+ public void setPosition(Position position) {
this.position = position;
}
@@ -373,7 +389,7 @@ public class Notification implements Serializable {
* @param type
* The message type
*/
- public static void show(String caption, int type) {
+ public static void show(String caption, Type type) {
new Notification(caption, type).show(Page.getCurrent());
}
} \ No newline at end of file
diff --git a/server/src/com/vaadin/ui/Root.java b/server/src/com/vaadin/ui/Root.java
index 35517044c0..67f2e04a65 100644
--- a/server/src/com/vaadin/ui/Root.java
+++ b/server/src/com/vaadin/ui/Root.java
@@ -1124,7 +1124,7 @@ public abstract class Root extends AbstractComponentContainer implements
* Notification.show does not allow HTML.
*/
@Deprecated
- public void showNotification(String caption, int type) {
+ public void showNotification(String caption, Notification.Type type) {
Notification notification = new Notification(caption, type);
notification.setHtmlContentAllowed(true);// Backwards compatibility
getPage().showNotification(notification);
@@ -1179,7 +1179,8 @@ public abstract class Root extends AbstractComponentContainer implements
* be aware that HTML by default not allowed.
*/
@Deprecated
- public void showNotification(String caption, String description, int type) {
+ public void showNotification(String caption, String description,
+ Notification.Type type) {
Notification notification = new Notification(caption, description, type);
notification.setHtmlContentAllowed(true);// Backwards compatibility
getPage().showNotification(notification);
@@ -1210,8 +1211,8 @@ public abstract class Root extends AbstractComponentContainer implements
* @deprecated As of 7.0, use new Notification(...).show(Page).
*/
@Deprecated
- public void showNotification(String caption, String description, int type,
- boolean htmlContentAllowed) {
+ public void showNotification(String caption, String description,
+ Notification.Type type, boolean htmlContentAllowed) {
getPage()
.showNotification(
new Notification(caption, description, type,
diff --git a/shared/src/com/vaadin/shared/Position.java b/shared/src/com/vaadin/shared/Position.java
new file mode 100755
index 0000000000..89d6a4261c
--- /dev/null
+++ b/shared/src/com/vaadin/shared/Position.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.shared;
+
+public enum Position {
+ TOP_LEFT, TOP_CENTER, TOP_RIGHT, MIDDLE_LEFT, MIDDLE_CENTER, MIDDLE_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT;
+}
diff --git a/tests/testbench/com/vaadin/tests/components/notification/Notifications.java b/tests/testbench/com/vaadin/tests/components/notification/Notifications.java
index ab632a2a57..97e038dc1a 100644
--- a/tests/testbench/com/vaadin/tests/components/notification/Notifications.java
+++ b/tests/testbench/com/vaadin/tests/components/notification/Notifications.java
@@ -7,6 +7,7 @@ import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.Notification;
+import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.TextArea;
public class Notifications extends TestBase implements ClickListener {
@@ -52,8 +53,7 @@ public class Notifications extends TestBase implements ClickListener {
@Override
public void buttonClick(ClickEvent event) {
- Notification n = new Notification(tf.getValue(),
- (Integer) type.getValue());
+ Notification n = new Notification(tf.getValue(), (Type) type.getValue());
n.setHtmlContentAllowed(true);
n.show(Page.getCurrent());
}