From e1907d68db5c3301560f542c2a00450550c20219 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Wed, 22 Feb 2012 14:36:23 +0200 Subject: [PATCH] Use constants for some more UIDL attribute names. --- .../terminal/gwt/client/ui/VFilterSelect.java | 6 ++-- .../terminal/gwt/client/ui/VMenuBar.java | 6 ++-- .../gwt/client/ui/VMenuBarPaintable.java | 10 ++++-- .../terminal/gwt/client/ui/VNotification.java | 32 +++++++++++++------ .../gwt/client/ui/VTreePaintable.java | 23 +++++++++---- .../gwt/client/ui/VWindowPaintable.java | 7 ++-- src/com/vaadin/ui/MenuBar.java | 3 +- src/com/vaadin/ui/Root.java | 24 ++++++++++---- src/com/vaadin/ui/TabSheet.java | 2 ++ src/com/vaadin/ui/Tree.java | 16 +++++++--- 10 files changed, 89 insertions(+), 40 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index 5e061175c0..f205162769 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -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]); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java index 3bd90e17e6..a6bc1f2c4e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java @@ -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); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java index 690dd5692c..ee86ef4e52 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java @@ -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); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java index 27407c55aa..1276c1612c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java @@ -56,6 +56,13 @@ public class VNotification extends VOverlay { private ArrayList 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 += ""; } - 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", "
"); } html += "

" + caption + "

"; } - 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", "
"); @@ -381,10 +390,13 @@ public class VNotification extends VOverlay { html += "

" + message + "

"; } - 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); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java index 9704c38983..acb8f8b467 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java @@ -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 i) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java index 402b7fd42d..b018554e0c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java @@ -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; diff --git a/src/com/vaadin/ui/MenuBar.java b/src/com/vaadin/ui/MenuBar.java index 4a7b90c8ed..c9de432d7e 100644 --- a/src/com/vaadin/ui/MenuBar.java +++ b/src/com/vaadin/ui/MenuBar.java @@ -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()) { diff --git a/src/com/vaadin/ui/Root.java b/src/com/vaadin/ui/Root.java index 7fd4a79458..47dcedd12a 100644 --- a/src/com/vaadin/ui/Root.java +++ b/src/com/vaadin/ui/Root.java @@ -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"); } diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index 6208c0ba1f..b7067fb41f 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -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, diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 4ea66cc6bf..562e1ac533 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -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"); -- 2.39.5