]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use constants for some more UIDL attribute names.
authorHenri Sara <hesara@vaadin.com>
Wed, 22 Feb 2012 12:36:23 +0000 (14:36 +0200)
committerHenri Sara <hesara@vaadin.com>
Wed, 22 Feb 2012 12:36:23 +0000 (14:36 +0200)
src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java
src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java
src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VNotification.java
src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java
src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java
src/com/vaadin/ui/MenuBar.java
src/com/vaadin/ui/Root.java
src/com/vaadin/ui/TabSheet.java
src/com/vaadin/ui/Tree.java

index 5e061175c00ce6e69c658015853864c7d5d09647..f205162769ad1d357df87be20b2995eeeb6036ba 100644 (file)
@@ -541,10 +541,10 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
          * Updates style names in suggestion popup to help theme building.
          */
         public void updateStyleNames(UIDL uidl) {
-            if (uidl.hasAttribute("style")) {
+            if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE)) {
                 setStyleName(CLASSNAME + "-suggestpopup");
-                final String[] styles = uidl.getStringAttribute("style").split(
-                        " ");
+                final String[] styles = uidl.getStringAttribute(
+                        VAbstractPaintableWidget.ATTRIBUTE_STYLE).split(" ");
                 for (int i = 0; i < styles.length; i++) {
                     addStyleDependentName(styles[i]);
                 }
index 3bd90e17e697da4b425632a8aa607d8721d6d9a7..a6bc1f2c4e2ba758aad183a9683d2ad9b38a4a89 100644 (file)
@@ -68,6 +68,7 @@ public class VMenuBar extends SimpleFocusablePanel implements
     public static final String ATTRIBUTE_ITEM_DESCRIPTION = VAbstractPaintableWidget.ATTRIBUTE_DESCRIPTION;
     public static final String ATTRIBUTE_ITEM_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON;
     public static final String ATTRIBUTE_ITEM_DISABLED = VAbstractPaintableWidget.ATTRIBUTE_DISABLED;
+    public static final String ATTRIBUTE_ITEM_STYLE = VAbstractPaintableWidget.ATTRIBUTE_STYLE;
 
     public static final String HTML_CONTENT_ALLOWED = "usehtml";
 
@@ -913,8 +914,9 @@ public class VMenuBar extends SimpleFocusablePanel implements
                 setCheckable(false);
             }
 
-            if (uidl.hasAttribute("style")) {
-                String itemStyle = uidl.getStringAttribute("style");
+            if (uidl.hasAttribute(ATTRIBUTE_ITEM_STYLE)) {
+                String itemStyle = uidl
+                        .getStringAttribute(ATTRIBUTE_ITEM_STYLE);
                 addStyleDependentName(itemStyle);
             }
 
index 690dd5692cb92d320c30a3e6ee1d53d16e6e203c..ee86ef4e5254e7e56a409370e3d18995f9abe296 100644 (file)
@@ -121,9 +121,13 @@ public class VMenuBarPaintable extends VAbstractPaintableWidget {
                 iteratorStack.push(itr);
                 itr = item.getChildIterator();
                 currentMenu = new VMenuBar(true, currentMenu);
-                if (uidl.hasAttribute("style")) {
-                    for (String style : uidl.getStringAttribute("style").split(
-                            " ")) {
+                // this is the top-level style that also propagates to items -
+                // any item specific styles are set above in
+                // currentItem.updateFromUIDL(item, client)
+                if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE)) {
+                    for (String style : uidl.getStringAttribute(
+                            VAbstractPaintableWidget.ATTRIBUTE_STYLE)
+                            .split(" ")) {
                         currentMenu.addStyleDependentName(style);
                     }
                 }
index 27407c55aa630da075809c4d5d008f05db9867cc..1276c1612cbf7a3f04d961571cf139efb62002b7 100644 (file)
@@ -56,6 +56,13 @@ public class VNotification extends VOverlay {
     private ArrayList<EventListener> listeners;
     private static final int TOUCH_DEVICE_IDLE_DELAY = 1000;
 
+    public static final String ATTRIBUTE_NOTIFICATION_STYLE = VAbstractPaintableWidget.ATTRIBUTE_STYLE;
+    public static final String ATTRIBUTE_NOTIFICATION_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION;
+    public static final String ATTRIBUTE_NOTIFICATION_MESSAGE = "message";
+    public static final String ATTRIBUTE_NOTIFICATION_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON;
+    public static final String ATTRIBUTE_NOTIFICATION_POSITION = "position";
+    public static final String ATTRIBUTE_NOTIFICATION_DELAY = "delay";
+
     /**
      * Default constructor. You should use GWT.create instead.
      */
@@ -359,21 +366,23 @@ public class VNotification extends VOverlay {
         boolean onlyPlainText = notification
                 .hasAttribute(VView.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED);
         String html = "";
-        if (notification.hasAttribute("icon")) {
+        if (notification.hasAttribute(ATTRIBUTE_NOTIFICATION_ICON)) {
             final String parsedUri = client.translateVaadinUri(notification
-                    .getStringAttribute("icon"));
+                    .getStringAttribute(ATTRIBUTE_NOTIFICATION_ICON));
             html += "<img src=\"" + Util.escapeAttribute(parsedUri) + "\" />";
         }
-        if (notification.hasAttribute("caption")) {
-            String caption = notification.getStringAttribute("caption");
+        if (notification.hasAttribute(ATTRIBUTE_NOTIFICATION_CAPTION)) {
+            String caption = notification
+                    .getStringAttribute(ATTRIBUTE_NOTIFICATION_CAPTION);
             if (onlyPlainText) {
                 caption = Util.escapeHTML(caption);
                 caption = caption.replaceAll("\\n", "<br />");
             }
             html += "<h1>" + caption + "</h1>";
         }
-        if (notification.hasAttribute("message")) {
-            String message = notification.getStringAttribute("message");
+        if (notification.hasAttribute(ATTRIBUTE_NOTIFICATION_MESSAGE)) {
+            String message = notification
+                    .getStringAttribute(ATTRIBUTE_NOTIFICATION_MESSAGE);
             if (onlyPlainText) {
                 message = Util.escapeHTML(message);
                 message = message.replaceAll("\\n", "<br />");
@@ -381,10 +390,13 @@ public class VNotification extends VOverlay {
             html += "<p>" + message + "</p>";
         }
 
-        final String style = notification.hasAttribute("style") ? notification
-                .getStringAttribute("style") : null;
-        final int position = notification.getIntAttribute("position");
-        final int delay = notification.getIntAttribute("delay");
+        final String style = notification
+                .hasAttribute(ATTRIBUTE_NOTIFICATION_STYLE) ? notification
+                .getStringAttribute(ATTRIBUTE_NOTIFICATION_STYLE) : null;
+        final int position = notification
+                .getIntAttribute(ATTRIBUTE_NOTIFICATION_POSITION);
+        final int delay = notification
+                .getIntAttribute(ATTRIBUTE_NOTIFICATION_DELAY);
         createNotification(delay).show(html, position, style);
     }
 
index 9704c3898346b91e201a24ed680301d2dfca2df6..acb8f8b467d8d0fa193433da2ad0bc346f2f52fb 100644 (file)
@@ -14,6 +14,13 @@ import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode;
 
 public class VTreePaintable extends VAbstractPaintableWidget {
 
+    public static final String ATTRIBUTE_NODE_STYLE = VAbstractPaintableWidget.ATTRIBUTE_STYLE;
+    public static final String ATTRIBUTE_NODE_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION;
+    public static final String ATTRIBUTE_NODE_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON;
+
+    public static final String ATTRIBUTE_ACTION_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION;
+    public static final String ATTRIBUTE_ACTION_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON;
+
     @Override
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
         // Ensure correct implementation and let container manage caption
@@ -150,11 +157,12 @@ public class VTreePaintable extends VAbstractPaintableWidget {
         while (it.hasNext()) {
             final UIDL action = (UIDL) it.next();
             final String key = action.getStringAttribute("key");
-            final String caption = action.getStringAttribute("caption");
+            final String caption = action
+                    .getStringAttribute(ATTRIBUTE_ACTION_CAPTION);
             String iconUrl = null;
-            if (action.hasAttribute("icon")) {
+            if (action.hasAttribute(ATTRIBUTE_ACTION_ICON)) {
                 iconUrl = getConnection().translateVaadinUri(
-                        action.getStringAttribute("icon"));
+                        action.getStringAttribute(ATTRIBUTE_ACTION_ICON));
             }
             getWidgetForPaintable().registerAction(key, caption, iconUrl);
         }
@@ -163,7 +171,7 @@ public class VTreePaintable extends VAbstractPaintableWidget {
 
     public void updateNodeFromUIDL(TreeNode treeNode, UIDL uidl) {
         String nodeKey = uidl.getStringAttribute("key");
-        treeNode.setText(uidl.getStringAttribute("caption"));
+        treeNode.setText(uidl.getStringAttribute(ATTRIBUTE_NODE_CAPTION));
         treeNode.key = nodeKey;
 
         getWidgetForPaintable().registerNode(treeNode);
@@ -182,8 +190,9 @@ public class VTreePaintable extends VAbstractPaintableWidget {
         } else {
             treeNode.addStyleName(TreeNode.CLASSNAME + "-leaf");
         }
-        if (uidl.hasAttribute("style")) {
-            treeNode.setNodeStyleName(uidl.getStringAttribute("style"));
+        if (uidl.hasAttribute(ATTRIBUTE_NODE_STYLE)) {
+            treeNode.setNodeStyleName(uidl
+                    .getStringAttribute(ATTRIBUTE_NODE_STYLE));
         }
 
         String description = uidl.getStringAttribute("descr");
@@ -207,7 +216,7 @@ public class VTreePaintable extends VAbstractPaintableWidget {
             getWidgetForPaintable().selectedIds.add(nodeKey);
         }
 
-        treeNode.setIcon(uidl.getStringAttribute("icon"));
+        treeNode.setIcon(uidl.getStringAttribute(ATTRIBUTE_NODE_ICON));
     }
 
     void renderChildNodes(TreeNode containerNode, Iterator<UIDL> i) {
index 402b7fd42dca3f78c769513802cd3c16828a2f6c..b018554e0cf29b79857f8ea9ddb4eaecd74c8f9c 100644 (file)
@@ -75,9 +75,10 @@ public class VWindowPaintable extends VAbstractPaintableWidgetContainer
 
             // Caption must be set before required header size is measured. If
             // the caption attribute is missing the caption should be cleared.
-            getWidgetForPaintable().setCaption(
-                    uidl.getStringAttribute("caption"),
-                    uidl.getStringAttribute("icon"));
+            getWidgetForPaintable()
+                    .setCaption(
+                            uidl.getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_CAPTION),
+                            uidl.getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_ICON));
         }
 
         getWidgetForPaintable().visibilityChangesDisabled = true;
index 4a7b90c8edb7a3d690ca3314fd9cfec66891c06c..c9de432d7ed1214250b319f3cc9989eaf7c68d1d 100644 (file)
@@ -86,7 +86,8 @@ public class MenuBar extends AbstractComponent {
         target.addAttribute("id", item.getId());
 
         if (item.getStyleName() != null) {
-            target.addAttribute("style", item.getStyleName());
+            target.addAttribute(VMenuBar.ATTRIBUTE_ITEM_STYLE,
+                    item.getStyleName());
         }
 
         if (item.isSeparator()) {
index 7fd4a79458b6361e03081d6f30647cf04bc29977..47dcedd12ad497e46ea529b3dc841defff319a06 100644 (file)
@@ -30,6 +30,7 @@ import com.vaadin.terminal.Resource;
 import com.vaadin.terminal.WrappedRequest;
 import com.vaadin.terminal.WrappedRequest.BrowserDetails;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
+import com.vaadin.terminal.gwt.client.ui.VNotification;
 import com.vaadin.terminal.gwt.client.ui.VView;
 import com.vaadin.tools.ReflectTools;
 import com.vaadin.ui.Window.CloseListener;
@@ -512,22 +513,33 @@ public abstract class Root extends AbstractComponentContainer implements
                 final Notification n = it.next();
                 target.startTag("notification");
                 if (n.getCaption() != null) {
-                    target.addAttribute("caption", n.getCaption());
+                    target.addAttribute(
+                            VNotification.ATTRIBUTE_NOTIFICATION_CAPTION,
+                            n.getCaption());
                 }
                 if (n.getDescription() != null) {
-                    target.addAttribute("message", n.getDescription());
+                    target.addAttribute(
+                            VNotification.ATTRIBUTE_NOTIFICATION_MESSAGE,
+                            n.getDescription());
                 }
                 if (n.getIcon() != null) {
-                    target.addAttribute("icon", n.getIcon());
+                    target.addAttribute(
+                            VNotification.ATTRIBUTE_NOTIFICATION_ICON,
+                            n.getIcon());
                 }
                 if (!n.isHtmlContentAllowed()) {
                     target.addAttribute(
                             VView.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED, true);
                 }
-                target.addAttribute("position", n.getPosition());
-                target.addAttribute("delay", n.getDelayMsec());
+                target.addAttribute(
+                        VNotification.ATTRIBUTE_NOTIFICATION_POSITION,
+                        n.getPosition());
+                target.addAttribute(VNotification.ATTRIBUTE_NOTIFICATION_DELAY,
+                        n.getDelayMsec());
                 if (n.getStyleName() != null) {
-                    target.addAttribute("style", n.getStyleName());
+                    target.addAttribute(
+                            VNotification.ATTRIBUTE_NOTIFICATION_STYLE,
+                            n.getStyleName());
                 }
                 target.endTag("notification");
             }
index 6208c0ba1fc3063ff68a0e8d1a2f481608c0567e..b7067fb41f572a3b399ec7ad64b0204278fb26c6 100644 (file)
@@ -390,6 +390,8 @@ public class TabSheet extends AbstractComponentContainer {
                 target.addAttribute("closable", true);
             }
 
+            // tab icon, caption and description, but used via
+            // VCaption.updateCaption(uidl)
             final Resource icon = tab.getIcon();
             if (icon != null) {
                 target.addAttribute(VAbstractPaintableWidget.ATTRIBUTE_ICON,
index 4ea66cc6bf88a6fbb01d36f067ed1660ad5fc608..562e1ac53353a7486d962ad945755923a2440f84 100644 (file)
@@ -610,7 +610,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                 if (itemStyleGenerator != null) {
                     String stylename = itemStyleGenerator.getStyle(itemId);
                     if (stylename != null) {
-                        target.addAttribute("style", stylename);
+                        target.addAttribute(
+                                VTreePaintable.ATTRIBUTE_NODE_STYLE, stylename);
                     }
                 }
 
@@ -623,10 +624,12 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                 }
 
                 // Adds the attributes
-                target.addAttribute("caption", getItemCaption(itemId));
+                target.addAttribute(VTreePaintable.ATTRIBUTE_NODE_CAPTION,
+                        getItemCaption(itemId));
                 final Resource icon = getItemIcon(itemId);
                 if (icon != null) {
-                    target.addAttribute("icon", getItemIcon(itemId));
+                    target.addAttribute(VTreePaintable.ATTRIBUTE_NODE_ICON,
+                            getItemIcon(itemId));
                 }
                 final String key = itemIdMapper.key(itemId);
                 target.addAttribute("key", key);
@@ -683,10 +686,13 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                 final Action a = i.next();
                 target.startTag("action");
                 if (a.getCaption() != null) {
-                    target.addAttribute("caption", a.getCaption());
+                    target.addAttribute(
+                            VTreePaintable.ATTRIBUTE_ACTION_CAPTION,
+                            a.getCaption());
                 }
                 if (a.getIcon() != null) {
-                    target.addAttribute("icon", a.getIcon());
+                    target.addAttribute(VTreePaintable.ATTRIBUTE_ACTION_ICON,
+                            a.getIcon());
                 }
                 target.addAttribute("key", actionMapper.key(a));
                 target.endTag("action");