]> source.dussan.org Git - vaadin-framework.git/commitdiff
API refactoring (#7749) declarative
authorArtur Signell <artur@vaadin.com>
Wed, 17 Dec 2014 20:35:51 +0000 (22:35 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 17 Dec 2014 21:08:57 +0000 (23:08 +0200)
Change-Id: I835756b240bc9ece885acdc8f43ec6a1599bb7c5

18 files changed:
server/src/com/vaadin/ui/AbsoluteLayout.java
server/src/com/vaadin/ui/AbstractComponent.java
server/src/com/vaadin/ui/AbstractOrderedLayout.java
server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
server/src/com/vaadin/ui/AbstractSplitPanel.java
server/src/com/vaadin/ui/CssLayout.java
server/src/com/vaadin/ui/TabSheet.java
server/src/com/vaadin/ui/declarative/Design.java
server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
server/src/com/vaadin/ui/declarative/DesignContext.java
server/tests/src/com/vaadin/tests/design/TestLocale.java
server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestReadDesign.java
server/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestReadDesign.java
server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestReadDesign.java
server/tests/src/com/vaadin/tests/server/component/button/TestReadDesign.java
server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java
server/tests/src/com/vaadin/tests/server/component/csslayout/TestReadDesign.java
server/tests/src/com/vaadin/tests/server/component/label/TestReadDesign.java

index 39f00901fca41122b79421ef35f4f34d83c758d0..12aa8ea9a62b88da9ff40db8572486d3d9adab81 100644 (file)
@@ -685,7 +685,7 @@ public class AbsoluteLayout extends AbstractLayout implements
         // handle children
         for (Element childComponent : design.children()) {
             Attributes attr = childComponent.attributes();
-            Component newChild = designContext.createChild(childComponent);
+            Component newChild = designContext.readDesign(childComponent);
             StringBuilder css = new StringBuilder();
             if (attr.hasKey(ATTR_TOP)) {
                 css.append("top:").append(attr.get(ATTR_TOP)).append(";");
index 8517c216e3088a5d522ae26168c3bd9dd9776211..a41d1b405670262ba7f2e7d39e76116880fb207a 100644 (file)
@@ -930,7 +930,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
         }
         // handle immediate
         if (attr.hasKey("immediate")) {
-            setImmediate(DesignAttributeHandler.getBoolean(attr
+            setImmediate(DesignAttributeHandler.parseBoolean(attr
                     .get("immediate")));
         }
 
@@ -955,7 +955,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
 
         // handle responsive
         if (attr.hasKey("responsive")) {
-            setResponsive(DesignAttributeHandler.getBoolean(attr
+            setResponsive(DesignAttributeHandler.parseBoolean(attr
                     .get("responsive")));
         }
         // check for unsupported attributes
index 77c7e3c8263081e615481f50622738955e77612a..67bcfc904c8a6845f67336e3f14af6e309230df7 100644 (file)
@@ -485,7 +485,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
         // handle children
         for (Element childComponent : design.children()) {
             Attributes attr = childComponent.attributes();
-            Component newChild = designContext.createChild(childComponent);
+            Component newChild = designContext.readDesign(childComponent);
             addComponent(newChild);
             // handle alignment
             int bitMask = 0;
index 24c36fd0cf6e8d76c8d36e1cfb77d4d74acbb50b..244feb3bb983228c028a91464e0c6274285b71e1 100644 (file)
@@ -297,7 +297,7 @@ public abstract class AbstractSingleComponentContainer extends
                     + " can have only one child component.");
         } else if (childCount == 1) {
             Element childElement = design.children().get(0);
-            Component newChild = designContext.createChild(childElement);
+            Component newChild = designContext.readDesign(childElement);
             setContent(newChild);
         }
     }
index e366c33593805371e909cd04fd62cbb3207d3afd..62e4d9ec110765b48ad85730a0b3eadd714ba792 100644 (file)
@@ -610,7 +610,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer {
                     "A split panel can contain at most two components.");
         }
         for (Element childElement : design.children()) {
-            Component childComponent = designContext.createChild(childElement);
+            Component childComponent = designContext.readDesign(childElement);
             if (childElement.hasAttr(":second")) {
                 setSecondComponent(childComponent);
             } else {
index 528b34a28f499e040168616ce5bc602efb244639..dbedfa53ff0fa205dd97d613ee0727044338b6e5 100644 (file)
@@ -369,7 +369,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
         super.readDesign(design, designContext);
         // handle children
         for (Element childComponent : design.children()) {
-            Component newChild = designContext.createChild(childComponent);
+            Component newChild = designContext.readDesign(childComponent);
             addComponent(newChild);
         }
     }
index 5528ea2ee9d4ad46545a1f0e39bc826fb5129019..aa9b0cc455c7b9a487fd35cd3018ead69938ff6f 100644 (file)
@@ -1492,7 +1492,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
         }
         // create the component that is in tab content
         Element content = tabElement.child(0);
-        Component child = designContext.createChild(content);
+        Component child = designContext.readDesign(content);
         Tab tab = this.addTab(child);
         if (attr.hasKey("visible")) {
             tab.setVisible(DesignAttributeHandler.readAttribute("visible",
index cd9a21bc15644f79539089d024cc90c451da8af6..59393a781598a567c468a4e4d825f379d5b91905 100644 (file)
@@ -177,9 +177,9 @@ public class Design implements Serializable {
      *            id/local id/caption
      */
     private static DesignContext designToComponentTree(Document doc,
-            Component componentRoot, Class<? extends Component> classWithFields) {
+            Component componentRoot, Class<?> classWithFields) {
         DesignContext designContext = new DesignContext(doc);
-        designContext.getPrefixes(doc);
+        designContext.readPackageMappings(doc);
         // No special handling for a document without a body element - should be
         // taken care of by jsoup.
         Element root = doc.body();
@@ -210,7 +210,7 @@ public class Design implements Serializable {
             };
             designContext.addComponentCreationListener(creationListener);
             // create subtree
-            designContext.synchronizeAndRegister(componentRoot, element);
+            designContext.readDesign(element, componentRoot);
             // make sure that all the member fields are bound
             Collection<String> unboundFields = binder.getUnboundFields();
             if (!unboundFields.isEmpty()) {
@@ -222,7 +222,7 @@ public class Design implements Serializable {
             designContext.removeComponentCreationListener(creationListener);
         } else {
             // createChild creates the entire component hierarchy
-            componentRoot = designContext.createChild(element);
+            componentRoot = designContext.readDesign(element);
         }
         designContext.setRootComponent(componentRoot);
         return designContext;
@@ -257,7 +257,7 @@ public class Design implements Serializable {
         Component root = designContext.getRootComponent();
         Node rootNode = designContext.createElement(root);
         body.appendChild(rootNode);
-        designContext.storePrefixes(doc);
+        designContext.writePackageMappings(doc);
         return doc;
     }
 
index fbfe024c00c0ea39796b03c4eadbfc0876f10297..1fc89c965dfdda08f8d8df2292440827b4c4e227 100644 (file)
@@ -61,7 +61,7 @@ import com.vaadin.ui.Component;
  */
 public class DesignAttributeHandler implements Serializable {
 
-    protected static Logger getLogger() {
+    private static Logger getLogger() {
         return Logger.getLogger(DesignAttributeHandler.class.getName());
     }
 
@@ -423,7 +423,7 @@ public class DesignAttributeHandler implements Serializable {
         // it is present and the value is not "false" or "FALSE". Thus empty
         // value evaluates to true.
         if (targetType == Boolean.TYPE || targetType == Boolean.class) {
-            return !value.equalsIgnoreCase("false");
+            return parseBoolean(value);
         }
         if (targetType == Integer.TYPE || targetType == Integer.class) {
             return Integer.valueOf(value);
@@ -716,15 +716,14 @@ public class DesignAttributeHandler implements Serializable {
      * Converts the given string attribute value to its corresponding boolean.
      * 
      * An empty string and "true" are considered to represent a true value and
-     * "false" to represent a false value. All other input will throw an
-     * exception
+     * "false" to represent a false value.
      * 
      * @param booleanValue
      *            the boolean value from an attribute
      * @return the parsed boolean
      */
-    public static boolean getBoolean(String booleanValue) {
-        return "".equals(booleanValue) ? true : Boolean.valueOf(booleanValue);
+    public static boolean parseBoolean(String booleanValue) {
+        return !booleanValue.equalsIgnoreCase("false");
     }
 
 }
\ No newline at end of file
index 0ce269261bb87a93be970ac6c1cb4713fcb18d3f..ade249463816fb14dfe233bd97e5b0456d13a5a4 100644 (file)
@@ -29,7 +29,6 @@ import org.jsoup.nodes.Element;
 import org.jsoup.nodes.Node;
 
 import com.vaadin.annotations.DesignRoot;
-import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.HasComponents;
 
@@ -261,19 +260,18 @@ public class DesignContext implements Serializable {
      * @return the default instance for the given class. The return value must
      *         not be modified by the caller
      */
-    public <T> T getDefaultInstance(AbstractComponent abstractComponent) {
+    public <T> T getDefaultInstance(Component component) {
         // If the root is a @DesignRoot component, it can't use itself as a
         // reference or the written design will be empty
 
         // If the root component in some other way initializes itself in the
         // constructor
-        if (getRootComponent() == abstractComponent
-                && abstractComponent.getClass().isAnnotationPresent(
-                        DesignRoot.class)) {
-            return (T) getDefaultInstance((Class<? extends Component>) abstractComponent
+        if (getRootComponent() == component
+                && component.getClass().isAnnotationPresent(DesignRoot.class)) {
+            return (T) getDefaultInstance((Class<? extends Component>) component
                     .getClass().getSuperclass());
         }
-        return (T) getDefaultInstance(abstractComponent.getClass());
+        return (T) getDefaultInstance(component.getClass());
     }
 
     private Component getDefaultInstance(
@@ -295,11 +293,10 @@ public class DesignContext implements Serializable {
     }
 
     /**
-     * Get and store the mappings from prefixes to package names from meta tags
-     * located under <head> in the html document.
-     * 
+     * Reads and stores the mappings from prefixes to package names from meta
+     * tags located under <head> in the html document.
      */
-    protected void getPrefixes(Document doc) {
+    protected void readPackageMappings(Document doc) {
         Element head = doc.head();
         if (head == null) {
             return;
@@ -329,14 +326,15 @@ public class DesignContext implements Serializable {
     }
 
     /**
-     * Stores the package mappings (prefix -> package name) of this object to
-     * the specified document. The prefixes are stored as <meta> tags under
-     * <head> in the document.
+     * Writes the package mappings (prefix -> package name) of this object to
+     * the specified document.
+     * <p>
+     * The prefixes are stored as <meta> tags under <head> in the document.
      * 
      * @param doc
-     *            the Jsoup document tree where the package mappings are stored
+     *            the Jsoup document tree where the package mappings are written
      */
-    public void storePrefixes(Document doc) {
+    public void writePackageMappings(Document doc) {
         Element head = doc.head();
         for (String prefix : prefixToPackage.keySet()) {
             // Only store the prefix-name mapping if it is not a default mapping
@@ -348,7 +346,6 @@ public class DesignContext implements Serializable {
                         + prefixToPackage.get(prefix);
                 newNode.attr("content", prefixToPackageName);
                 head.appendChild(newNode);
-
             }
         }
     }
@@ -414,38 +411,36 @@ public class DesignContext implements Serializable {
     }
 
     /**
-     * Creates a Component corresponding to the given html node. Also calls
-     * readDesign() for the created node, in effect creating the entire
-     * component hierarchy rooted at the returned component.
+     * Reads the given design node and creates the corresponding component tree
      * 
      * @param componentDesign
-     *            The html tree node containing the description of the component
-     *            to be created.
-     * @return a Component corresponding to componentDesign
+     *            The design element containing the description of the component
+     *            to be created
+     * @return the root component of component tree
      */
-    public Component createChild(Element componentDesign) {
+    public Component readDesign(Element componentDesign) {
         // Create the component.
         Component component = instantiateComponent(componentDesign);
-        synchronizeAndRegister(component, componentDesign);
+        readDesign(componentDesign, component);
         fireComponentCreatedEvent(componentToLocalId.get(component), component);
         return component;
     }
 
     /**
-     * Calls readDesign() for the given component and passes the given component
-     * design as a parameter. This creates the entire component hierarchy rooted
-     * at the given component. Also registers the componentid, localId and
-     * caption of the given component and all its children to the context
      * 
-     * @param component
-     *            The component to be synchronized from design
+     * Reads the given design node and populates the given component with the
+     * corresponding component tree
+     * <p>
+     * Additionally registers the component id, local id and caption of the
+     * given component and all its children in the context
+     * 
      * @param componentDesign
-     *            The html tree node containing the description of the component
-     * @throws DesignException
-     *             if the design contains duplicate local or global ids
+     *            The design element containing the description of the component
+     *            to be created
+     * @param component
+     *            The component which corresponds to the design element
      */
-    public void synchronizeAndRegister(Component component,
-            Element componentDesign) {
+    public void readDesign(Element componentDesign, Component component) {
         component.readDesign(componentDesign, this);
         // Get the ids and the caption of the component and store them in the
         // maps of this design context.
index 273e611dcfb87c0bf41876f6c18acd97262a7598..a4100f7d718e78641b9e9bf60cc35fbc0eb96676 100644 (file)
@@ -114,7 +114,7 @@ public class TestLocale extends TestCase {
         html.appendChild(doc.createElement("head"));
         Element body = doc.createElement("body");
         html.appendChild(body);
-        dc.storePrefixes(doc);
+        dc.writePackageMappings(doc);
 
         // Append the design under <body> in the html tree. createNode
         // creates the entire component hierarchy rooted at the
index 5f9674e554e0bd067f188ec0817e09e1b724de5d..f8af0a992e8c6c94dc81e3cc68256e005a0e1084 100644 (file)
@@ -78,7 +78,7 @@ public class TestReadDesign extends TestCase {
     private AbsoluteLayout createLayout() {
         DesignContext ctx = new DesignContext();
         Element design = createDesign();
-        Component child = ctx.createChild(design);
+        Component child = ctx.readDesign(design);
         return (AbsoluteLayout) child;
     }
 
index 8fe4d9c220007f8ef6edef373a0dfb192daf8580..43a050ba80e11d2bb8ea8f99428f2f16d0bb2a87 100644 (file)
@@ -110,6 +110,7 @@ public class TestReadDesign extends TestCase {
         // Synchronize with a design having no immediate attribute -
         // explicitImmediate should then be null.
         design = createDesign("description", "test-description");
+        component = getComponent();
         component.readDesign(design, ctx);
         // Synchronize with a design having immediate = false
         design = createDesign("immediate", "false");
index f52a04496aa2f952db88de0211544b66d94bcc6f..874fbd83b280225e9f7d57cfb9337bc526e53fce 100644 (file)
@@ -80,7 +80,7 @@ public class TestReadDesign extends TestCase {
             String... alignments) {
         DesignContext ctx = new DesignContext();
         Element design = createDesign(expandRatio, margin, alignments);
-        Component child = ctx.createChild(design);
+        Component child = ctx.readDesign(design);
         return (VerticalLayout) child;
     }
 
index 48b228a35a3e0a563c0cd5f852a8eeb7f79655d7..e194232742602d78acbfe9dbc86090355bde872c 100644 (file)
@@ -76,7 +76,7 @@ public class TestReadDesign extends TestCase {
         attributes.put("icon-alt", "OK");
         attributes.put("click-shortcut", "ctrl-shift-o");
         Button button = (Button) ctx
-                .createChild(createButtonWithAttributes(attributes));
+                .readDesign(createButtonWithAttributes(attributes));
         assertEquals(3, button.getTabIndex());
         assertEquals(false, button.isHtmlContentAllowed());
         assertEquals("OK", button.getIconAlternateText());
@@ -94,9 +94,9 @@ public class TestReadDesign extends TestCase {
      */
     private void createAndTestButtons(String content, String caption) {
         Element e1 = createElement("v-button", content, caption);
-        Button b1 = (Button) ctx.createChild(e1);
+        Button b1 = (Button) ctx.readDesign(e1);
         Element e2 = createElement("v-native-button", content, caption);
-        NativeButton b2 = (NativeButton) ctx.createChild(e2);
+        NativeButton b2 = (NativeButton) ctx.readDesign(e2);
         if (content != null) {
             assertEquals("The button has the wrong text content.", content,
                     b1.getCaption());
index 529dd911e9181fa99aa085db61bd4c61a4748f04..c58b3b6bdd17ca3bb70074f22d1da1047dcdcfa3 100644 (file)
@@ -43,7 +43,7 @@ public class TestReadDesign extends TestCase {
     @Test
     public void testChecked() {
         Element e = createElement(true);
-        CheckBox box = (CheckBox) ctx.createChild(e);
+        CheckBox box = (CheckBox) ctx.readDesign(e);
         assertEquals("The checkbox must be checked", Boolean.TRUE,
                 box.getValue());
     }
@@ -51,7 +51,7 @@ public class TestReadDesign extends TestCase {
     @Test
     public void testUnchecked() {
         Element e = createElement(false);
-        CheckBox box = (CheckBox) ctx.createChild(e);
+        CheckBox box = (CheckBox) ctx.readDesign(e);
         assertEquals("The checkbox must be unchecked", Boolean.FALSE,
                 box.getValue());
     }
index 51f763bf14accffbe75c8020b03dd548ce21f6e3..bac3dc70eb903e27e45f3becc6551afd5edb005a 100644 (file)
@@ -47,7 +47,7 @@ public class TestReadDesign extends TestCase {
     private CssLayout createLayout() {
         DesignContext ctx = new DesignContext();
         Element design = createDesign();
-        Component child = ctx.createChild(design);
+        Component child = ctx.readDesign(design);
         return (CssLayout) child;
     }
 
index 1a02ed98ccc93cef6d154c012b11a9378475a2df..3e577b55780a0145dd852ec8b2cc064c03f44520 100644 (file)
@@ -70,7 +70,7 @@ public class TestReadDesign extends TestCase {
      */
     private void createAndTestLabel(String content, String caption) {
         Element e = createElement("v-label", content, caption);
-        Label l = (Label) ctx.createChild(e);
+        Label l = (Label) ctx.readDesign(e);
         if (content != null) {
             assertEquals("The label has wrong text content.", content,
                     l.getValue());