]> source.dussan.org Git - vaadin-framework.git/commitdiff
#5402 Support html in OptionGroup items
authorLeif Åstrand <leif@vaadin.com>
Tue, 9 Aug 2011 11:02:22 +0000 (11:02 +0000)
committerLeif Åstrand <leif@vaadin.com>
Tue, 9 Aug 2011 11:02:22 +0000 (11:02 +0000)
svn changeset:20217/svn branch:6.7

src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
src/com/vaadin/ui/OptionGroup.java
tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.html [new file with mode: 0644]
tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.java [new file with mode: 0644]
tests/src/com/vaadin/tests/components/optiongroup/OptionGroups.java

index 51702cdf8a9c8859c0098eb58221f53c00e3ff64..eb3da571834e39c6c83f51ff1110edf4842134e4 100644 (file)
@@ -31,6 +31,8 @@ import com.vaadin.terminal.gwt.client.UIDL;
 public class VOptionGroup extends VOptionGroupBase implements FocusHandler,\r
         BlurHandler {\r
 \r
+    public static final String HTML_CONTENT_ALLOWED = "htmlcontentallowed";\r
+\r
     public static final String CLASSNAME = "v-select-optiongroup";\r
 \r
     private final Panel panel;\r
@@ -51,6 +53,8 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
      */\r
     private boolean blurOccured = false;\r
 \r
+    private boolean htmlItems = false;\r
+\r
     public VOptionGroup() {\r
         super(CLASSNAME);\r
         panel = (Panel) optionsContainer;\r
@@ -59,6 +63,12 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
 \r
     @Override\r
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        if (uidl.hasAttribute(HTML_CONTENT_ALLOWED)\r
+                && uidl.getBooleanAttribute(HTML_CONTENT_ALLOWED)) {\r
+            htmlItems = true;\r
+        } else {\r
+            htmlItems = false;\r
+        }\r
         super.updateFromUIDL(uidl, client);\r
 \r
         sendFocusEvents = client.hasEventListeners(this, EventId.FOCUS);\r
@@ -101,11 +111,16 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
         for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {\r
             final UIDL opUidl = (UIDL) it.next();\r
             CheckBox op;\r
+            String caption = opUidl.getStringAttribute("caption");\r
             if (isMultiselect()) {\r
                 op = new VCheckBox();\r
-                op.setText(opUidl.getStringAttribute("caption"));\r
+                if (htmlItems) {\r
+                    op.setHTML(caption);\r
+                } else {\r
+                    op.setText(caption);\r
+                }\r
             } else {\r
-                op = new RadioButton(id, opUidl.getStringAttribute("caption"));\r
+                op = new RadioButton(id, caption, htmlItems);\r
                 op.setStyleName("v-radiobutton");\r
             }\r
             op.addStyleName(CLASSNAME_OPTION);\r
index c1b52c4a82c5bf8774a39b5cd74c063cdc00de8e..ba300131bb3d747c60131153cd92b978a46f4735 100644 (file)
@@ -28,6 +28,7 @@ public class OptionGroup extends AbstractSelect implements
         FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
 
     private Set<Object> disabledItemIds = new HashSet<Object>();
+    private boolean htmlContentAllowed = false;
 
     public OptionGroup() {
         super();
@@ -48,6 +49,8 @@ public class OptionGroup extends AbstractSelect implements
     @Override
     public void paintContent(PaintTarget target) throws PaintException {
         target.addAttribute("type", "optiongroup");
+        target.addAttribute(VOptionGroup.HTML_CONTENT_ALLOWED,
+                htmlContentAllowed);
         super.paintContent(target);
     }
 
@@ -167,4 +170,13 @@ public class OptionGroup extends AbstractSelect implements
         }
         return true;
     }
+
+    public void setHtmlContentAllowed(boolean htmlContentAllowed) {
+        this.htmlContentAllowed = htmlContentAllowed;
+        requestRepaint();
+    }
+
+    public boolean isHtmlContentAllowed() {
+        return htmlContentAllowed;
+    }
 }
diff --git a/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.html b/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.html
new file mode 100644 (file)
index 0000000..af6f74b
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.optiongroup.HtmlOptionGroupItems?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsoptiongroupHtmlOptionGroupItems::PID_Sbuttonaction-Toggle html mode/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>html-and-text</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsoptiongroupHtmlOptionGroupItems::PID_Sbuttonaction-Toggle html mode/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>text-and-html</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.java b/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.java
new file mode 100644 (file)
index 0000000..e90fe10
--- /dev/null
@@ -0,0 +1,105 @@
+package com.vaadin.tests.components.optiongroup;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.tests.components.ComponentTestCase;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.OptionGroup;
+
+public class HtmlOptionGroupItems extends ComponentTestCase<OptionGroup> {
+
+    private static final List<String> cities = Arrays.asList(new String[] {
+            "<i>Berlin</i>", "<b>Brussels</b>", "<u>H</u>elsinki",
+            "<span style='font-size: 20px'>Madrid</span>",
+            "<pre><i>Oslo</i>\nNorway</pre>", "<button>Paris</button>",
+            "<input type='text' value='Stockholm' />" });
+
+    private static final String NULL_SELECTION_ID = cities.get(0);
+
+    @Override
+    protected Class<OptionGroup> getTestClass() {
+        return OptionGroup.class;
+    }
+
+    @Override
+    protected void initializeComponents() {
+
+        OptionGroup og = createOptionGroup("");
+        og.setItemEnabled(cities.get(2), false);
+        og.setItemEnabled(cities.get(5), false);
+        og.setValue(Arrays.asList(cities.get(2)));
+        og.setNullSelectionAllowed(true);
+        og.setNullSelectionItemId(NULL_SELECTION_ID);
+        addTestComponent(og);
+
+        og = createOptionGroup("");
+        og.setMultiSelect(true);
+        og.setHtmlContentAllowed(true);
+        og.setValue(Arrays.asList(cities.get(2)));
+        og.setNullSelectionAllowed(true);
+        og.setItemEnabled(cities.get(2), false);
+        og.setItemEnabled(cities.get(5), false);
+        addTestComponent(og);
+
+    }
+
+    @Override
+    protected void createCustomActions(List<Component> actions) {
+        actions.add(createInvertDisabledItemsAction());
+        actions.add(createToggleSelectionModeAction());
+        actions.add(createInvertHtmlItemsAction());
+    }
+
+    private Component createInvertHtmlItemsAction() {
+        return createButtonAction("Toggle html mode",
+                new Command<OptionGroup, Boolean>() {
+                    @Override
+                    public void execute(OptionGroup og, Boolean value,
+                            Object data) {
+                        og.setHtmlContentAllowed(!og.isHtmlContentAllowed());
+                    }
+                });
+    }
+
+    private Component createToggleSelectionModeAction() {
+        return createButtonAction("Toggle selection mode",
+                new Command<OptionGroup, Boolean>() {
+
+                    public void execute(OptionGroup og, Boolean value,
+                            Object data) {
+                        if (og.isMultiSelect()) {
+                            og.setMultiSelect(false);
+                            og.setNullSelectionItemId(NULL_SELECTION_ID);
+                        } else {
+                            og.setNullSelectionItemId(null);
+                            og.setMultiSelect(true);
+                        }
+                    }
+                });
+    }
+
+    private Component createInvertDisabledItemsAction() {
+        return createButtonAction("Invert disabled items",
+                new Command<OptionGroup, Boolean>() {
+
+                    public void execute(OptionGroup c, Boolean value,
+                            Object data) {
+                        for (Object itemId : c.getItemIds()) {
+                            c.setItemEnabled(itemId, !c.isItemEnabled(itemId));
+                        }
+                    }
+                });
+    }
+
+    private OptionGroup createOptionGroup(String caption) {
+        OptionGroup og = new OptionGroup(caption, cities);
+        og.setImmediate(true);
+        return og;
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Test case for html items in an OptionGroup";
+    }
+}
index 8e9766f42162dfe06170cffc83371755d34cbc30..56967445296c3746fb2fab1e7fdd82d90ddad270 100644 (file)
@@ -15,6 +15,14 @@ public class OptionGroups extends AbstractSelectTestCase<OptionGroup> {
         super.createActions();\r
 \r
         createDisabledItemsMultiToggle("Disabled items");\r
+        createBooleanAction("HTML content allowed", CATEGORY_STATE, false,\r
+                new Command<OptionGroup, Boolean>() {\r
+                    @Override\r
+                    public void execute(OptionGroup og, Boolean value,\r
+                            Object data) {\r
+                        og.setHtmlContentAllowed(value.booleanValue());\r
+                    }\r
+                });\r
     }\r
 \r
     private void createDisabledItemsMultiToggle(String category) {\r