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;
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;
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;
}
}
- 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", "");
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;
}
.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);
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) {
import java.io.Serializable;
+import com.vaadin.shared.Position;
import com.vaadin.terminal.Page;
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;
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;
* @param type
* The type of message
*/
- public Notification(String caption, int type) {
+ public Notification(String caption, Type type) {
this(caption, null, type);
}
* @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);
}
* 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;
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;
}
*
* @return The position
*/
- public int getPosition() {
+ public Position getPosition() {
return position;
}
* @param position
* The desired notification position
*/
- public void setPosition(int position) {
+ public void setPosition(Position position) {
this.position = position;
}
* @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
* 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);
* 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);
* @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,
--- /dev/null
+/*
+ * 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;
+}
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 {
@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());
}