summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2014-12-12 13:04:31 +0200
committerMatti Hosio <mhosio@vaadin.com>2014-12-12 16:18:20 +0200
commita025d511bfe4e81993d33fc424a9bed754586a52 (patch)
tree46598f43edf5182fc0f867edc2fbcd01e50ecaea
parentc4aab1fe917b3cae5a41c8acc1e7cbea07700106 (diff)
downloadvaadin-framework-a025d511bfe4e81993d33fc424a9bed754586a52.tar.gz
vaadin-framework-a025d511bfe4e81993d33fc424a9bed754586a52.zip
Embed DesignSynchronizable methods to Component interface (#7749)
Change-Id: I06de4d2065dee107da40c2a4941e7d9e22f0832b
-rw-r--r--server/src/com/vaadin/ui/AbsoluteLayout.java8
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java14
-rw-r--r--server/src/com/vaadin/ui/AbstractOrderedLayout.java73
-rw-r--r--server/src/com/vaadin/ui/AbstractSingleComponentContainer.java5
-rw-r--r--server/src/com/vaadin/ui/Button.java6
-rw-r--r--server/src/com/vaadin/ui/Component.java37
-rw-r--r--server/src/com/vaadin/ui/CssLayout.java6
-rw-r--r--server/src/com/vaadin/ui/DesignSynchronizable.java63
-rw-r--r--server/src/com/vaadin/ui/Label.java6
-rw-r--r--server/src/com/vaadin/ui/TabSheet.java5
-rw-r--r--server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java12
-rw-r--r--server/src/com/vaadin/ui/declarative/DesignContext.java82
-rw-r--r--server/src/com/vaadin/ui/declarative/LayoutHandler.java16
-rw-r--r--server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java4
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java3
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java4
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java4
17 files changed, 149 insertions, 199 deletions
diff --git a/server/src/com/vaadin/ui/AbsoluteLayout.java b/server/src/com/vaadin/ui/AbsoluteLayout.java
index c4c0de764f..7af22ba5c6 100644
--- a/server/src/com/vaadin/ui/AbsoluteLayout.java
+++ b/server/src/com/vaadin/ui/AbsoluteLayout.java
@@ -691,8 +691,7 @@ public class AbsoluteLayout extends AbstractLayout implements
// handle children
for (Element childComponent : design.children()) {
Attributes attr = childComponent.attributes();
- DesignSynchronizable newChild = designContext
- .createChild(childComponent);
+ Component newChild = designContext.createChild(childComponent);
StringBuilder css = new StringBuilder();
if (attr.hasKey(ATTR_TOP)) {
css.append("top:").append(attr.get(ATTR_TOP)).append(";");
@@ -727,10 +726,9 @@ public class AbsoluteLayout extends AbstractLayout implements
// handle children
Element designElement = design;
for (Component child : this) {
- DesignSynchronizable childComponent = (DesignSynchronizable) child;
- Element childNode = designContext.createNode(childComponent);
+ Element childNode = designContext.createNode(child);
designElement.appendChild(childNode);
- childComponent.synchronizeToDesign(childNode, designContext);
+ child.synchronizeToDesign(childNode, designContext);
// handle position
ComponentPosition position = getPosition(child);
writePositionAttribute(childNode, ATTR_TOP, position.getTopUnits()
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index adbb6d7fe7..18cd1f5fa4 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -69,7 +69,7 @@ import com.vaadin.util.ReflectTools;
*/
@SuppressWarnings("serial")
public abstract class AbstractComponent extends AbstractClientConnector
- implements DesignSynchronizable {
+ implements Component {
/* Private members */
@@ -917,8 +917,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
* (non-Javadoc)
*
* @see
- * com.vaadin.ui.DesignSynchronizable#synchronizeFromDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * com.vaadin.ui.Component#synchronizeFromDesign(org.jsoup.nodes.Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
public void synchronizeFromDesign(Element design,
@@ -1090,8 +1090,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
* the default instance of the class for fetching the default
* values
*/
- private void writeSize(Attributes attributes,
- DesignSynchronizable defaultInstance) {
+ private void writeSize(Attributes attributes, Component defaultInstance) {
if (hasEqualSize(defaultInstance)) {
// we have default values -> ignore
return;
@@ -1211,9 +1210,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.DesignSynchronizable#synchronizeToDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * @see com.vaadin.ui.Component#synchronizeToDesign(org.jsoup.nodes.Element,
+ * com.vaadin.ui.declarative.DesignContext)
*/
@Override
public void synchronizeToDesign(Element design, DesignContext designContext) {
diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java
index afe7a65d67..d2a302cff5 100644
--- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java
+++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java
@@ -23,7 +23,6 @@ import java.util.logging.Logger;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
-import org.jsoup.nodes.Node;
import com.vaadin.event.LayoutEvents.LayoutClickEvent;
import com.vaadin.event.LayoutEvents.LayoutClickListener;
@@ -494,43 +493,40 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
setMargin(def.getMargin().getBitMask() != 0);
}
// handle children
- for (Node childComponent : design.childNodes()) {
- if (childComponent instanceof Element) {
- Attributes attr = childComponent.attributes();
- DesignSynchronizable newChild = designContext
- .createChild((Element) childComponent);
- addComponent(newChild);
- // handle alignment
- int bitMask = 0;
- if (attr.hasKey(":middle")) {
- bitMask += AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER;
- } else if (attr.hasKey(":bottom")) {
- bitMask += AlignmentInfo.Bits.ALIGNMENT_BOTTOM;
- } else {
- bitMask += AlignmentInfo.Bits.ALIGNMENT_TOP;
- }
- if (attr.hasKey(":center")) {
- bitMask += AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER;
- } else if (attr.hasKey(":right")) {
- bitMask += AlignmentInfo.Bits.ALIGNMENT_RIGHT;
- } else {
- bitMask += AlignmentInfo.Bits.ALIGNMENT_LEFT;
- }
- setComponentAlignment(newChild, new Alignment(bitMask));
- // handle expand ratio
- if (attr.hasKey(":expand")) {
- String value = attr.get(":expand");
- if (value.length() > 0) {
- try {
- float ratio = Float.valueOf(value);
- setExpandRatio(newChild, ratio);
- } catch (NumberFormatException nfe) {
- getLogger().info(
- "Failed to parse expand ratio " + value);
- }
- } else {
- setExpandRatio(newChild, 1.0f);
+ for (Element childComponent : design.children()) {
+ Attributes attr = childComponent.attributes();
+ Component newChild = designContext.createChild(childComponent);
+ addComponent(newChild);
+ // handle alignment
+ int bitMask = 0;
+ if (attr.hasKey(":middle")) {
+ bitMask += AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER;
+ } else if (attr.hasKey(":bottom")) {
+ bitMask += AlignmentInfo.Bits.ALIGNMENT_BOTTOM;
+ } else {
+ bitMask += AlignmentInfo.Bits.ALIGNMENT_TOP;
+ }
+ if (attr.hasKey(":center")) {
+ bitMask += AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER;
+ } else if (attr.hasKey(":right")) {
+ bitMask += AlignmentInfo.Bits.ALIGNMENT_RIGHT;
+ } else {
+ bitMask += AlignmentInfo.Bits.ALIGNMENT_LEFT;
+ }
+ setComponentAlignment(newChild, new Alignment(bitMask));
+ // handle expand ratio
+ if (attr.hasKey(":expand")) {
+ String value = attr.get(":expand");
+ if (value.length() > 0) {
+ try {
+ float ratio = Float.valueOf(value);
+ setExpandRatio(newChild, ratio);
+ } catch (NumberFormatException nfe) {
+ getLogger().info(
+ "Failed to parse expand ratio " + value);
}
+ } else {
+ setExpandRatio(newChild, 1.0f);
}
}
}
@@ -556,8 +552,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
// handle children
Element designElement = design;
for (Component child : this) {
- DesignSynchronizable childComponent = (DesignSynchronizable) child;
- Element childNode = designContext.createNode(childComponent);
+ Element childNode = designContext.createNode(child);
designElement.appendChild(childNode);
// handle alignment
Alignment alignment = getComponentAlignment(child);
diff --git a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
index c6e78447d5..6c8d4fcde2 100644
--- a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
+++ b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
@@ -299,8 +299,7 @@ public abstract class AbstractSingleComponentContainer extends
+ " can have only one child component.");
} else if (childCount == 1) {
Element childElement = design.children().get(0);
- DesignSynchronizable newChild = designContext
- .createChild(childElement);
+ Component newChild = designContext.createChild(childElement);
setContent(newChild);
} else {
setContent(null);
@@ -319,7 +318,7 @@ public abstract class AbstractSingleComponentContainer extends
// synchronize default attributes (also clears children and attributes)
super.synchronizeToDesign(design, designContext);
// handle child component
- DesignSynchronizable child = (DesignSynchronizable) getContent();
+ Component child = getContent();
if (child != null) {
Element childNode = designContext.createNode(child);
design.appendChild(childNode);
diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java
index 46366eda8c..82666613bb 100644
--- a/server/src/com/vaadin/ui/Button.java
+++ b/server/src/com/vaadin/ui/Button.java
@@ -670,7 +670,7 @@ public class Button extends AbstractComponent implements
* (non-Javadoc)
*
* @see
- * com.vaadin.ui.DesignSynchronizable#synchronizeFromDesign(org.jsoup.nodes
+ * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
* .Element, com.vaadin.ui.declarative.DesignContext)
*/
@Override
@@ -719,8 +719,8 @@ public class Button extends AbstractComponent implements
* (non-Javadoc)
*
* @see
- * com.vaadin.ui.DesignSynchronizable#synchronizeToDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * , com.vaadin.ui.declarative.DesignContext)
*/
@Override
public void synchronizeToDesign(Element design, DesignContext designContext) {
diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java
index e10b5e1cd9..024c3eb433 100644
--- a/server/src/com/vaadin/ui/Component.java
+++ b/server/src/com/vaadin/ui/Component.java
@@ -19,6 +19,8 @@ package com.vaadin.ui;
import java.io.Serializable;
import java.util.Locale;
+import org.jsoup.nodes.Element;
+
import com.vaadin.event.ConnectorEvent;
import com.vaadin.event.ConnectorEventListener;
import com.vaadin.event.FieldEvents;
@@ -27,6 +29,7 @@ import com.vaadin.server.ErrorMessage;
import com.vaadin.server.Resource;
import com.vaadin.server.Sizeable;
import com.vaadin.server.VariableOwner;
+import com.vaadin.ui.declarative.DesignContext;
/**
* {@code Component} is the top-level interface that is and must be implemented
@@ -726,6 +729,40 @@ public interface Component extends ClientConnector, Sizeable, Serializable {
*/
public String getDescription();
+ /* Declarative support */
+
+ /**
+ * Update the component state based on the given design. The component is
+ * responsible not only for updating itself but also ensuring that its
+ * children update their state based on the design.
+ * <p>
+ * This method must not modify the design.
+ *
+ * @since 7.4
+ * @param design
+ * The design as HTML to obtain the state from
+ * @param designContext
+ * The DesignContext instance used for parsing the design
+ */
+ public void synchronizeFromDesign(Element design,
+ DesignContext designContext);
+
+ /**
+ * Update the given design based on the component state. The component is
+ * responsible not only for updating itself but also for ensuring its
+ * children update themselves in the correct position in the design. The
+ * caller of this method should not assume that contents of the
+ * <code>design</code> parameter are presented.
+ * <p>
+ * This method must not modify the component state.
+ *
+ * @since 7.4
+ * @param design
+ * The design as HTML to update with the current state
+ * @param designContext
+ */
+ public void synchronizeToDesign(Element design, DesignContext designContext);
+
/* Component event framework */
/**
diff --git a/server/src/com/vaadin/ui/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java
index 33b8c9fcbc..0b4e9cda7b 100644
--- a/server/src/com/vaadin/ui/CssLayout.java
+++ b/server/src/com/vaadin/ui/CssLayout.java
@@ -377,8 +377,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
removeAllComponents();
// handle children
for (Element childComponent : design.children()) {
- DesignSynchronizable newChild = designContext
- .createChild(childComponent);
+ Component newChild = designContext.createChild(childComponent);
addComponent(newChild);
}
}
@@ -397,8 +396,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
// handle children
Element designElement = design;
for (Component child : this) {
- DesignSynchronizable childComponent = (DesignSynchronizable) child;
- Element childNode = designContext.createNode(childComponent);
+ Element childNode = designContext.createNode(child);
designElement.appendChild(childNode);
}
}
diff --git a/server/src/com/vaadin/ui/DesignSynchronizable.java b/server/src/com/vaadin/ui/DesignSynchronizable.java
deleted file mode 100644
index 91533cc93b..0000000000
--- a/server/src/com/vaadin/ui/DesignSynchronizable.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2000-2014 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.ui;
-
-import org.jsoup.nodes.Element;
-
-import com.vaadin.ui.declarative.DesignContext;
-
-/**
- * Interface to be implemented by all the components that can be read from or
- * written to HTML design representation. TODO: add reference to VisualDesigner
- *
- * @since 7.4
- *
- * @author Vaadin Ltd
- */
-public interface DesignSynchronizable extends Component {
-
- /**
- * Update the component state based on the given design. The component is
- * responsible not only for updating itself but also ensuring that its
- * children update their state based on the design.
- * <p>
- * This method must not modify the design.
- *
- * @since 7.4
- * @param design
- * The design as HTML to obtain the state from
- * @param designContext
- * The DesignContext instance used for parsing the design
- */
- public void synchronizeFromDesign(Element design,
- DesignContext designContext);
-
- /**
- * Update the given design based on the component state. The component is
- * responsible not only for updating itself but also for ensuring its
- * children update themselves in the correct position in the design. The
- * caller of this method should not assume that contents of the
- * <code>design</code> parameter are presented.
- * <p>
- * This method must not modify the component state.
- *
- * @since 7.4
- * @param design
- * The design as HTML to update with the current state
- * @param designContext
- */
- public void synchronizeToDesign(Element design, DesignContext designContext);
-}
diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java
index 6001e30446..a4d9da752d 100644
--- a/server/src/com/vaadin/ui/Label.java
+++ b/server/src/com/vaadin/ui/Label.java
@@ -579,7 +579,7 @@ public class Label extends AbstractComponent implements Property<String>,
* (non-Javadoc)
*
* @see
- * com.vaadin.ui.DesignSynchronizable#synchronizeFromDesign(org.jsoup.nodes
+ * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
* .Element, com.vaadin.ui.declarative.DesignContext)
*/
@Override
@@ -608,8 +608,8 @@ public class Label extends AbstractComponent implements Property<String>,
* (non-Javadoc)
*
* @see
- * com.vaadin.ui.DesignSynchronizable#synchronizeToDesign(org.jsoup.nodes
- * .Element, com.vaadin.ui.declarative.DesignContext)
+ * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * , com.vaadin.ui.declarative.DesignContext)
*/
@Override
public void synchronizeToDesign(Element design, DesignContext designContext) {
diff --git a/server/src/com/vaadin/ui/TabSheet.java b/server/src/com/vaadin/ui/TabSheet.java
index dd9beb07f0..121ba89e06 100644
--- a/server/src/com/vaadin/ui/TabSheet.java
+++ b/server/src/com/vaadin/ui/TabSheet.java
@@ -1503,7 +1503,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
}
// create the component that is in tab content
Element content = tabElement.child(0);
- DesignSynchronizable child = designContext.createChild(content);
+ Component child = designContext.createChild(content);
Tab tab = this.addTab(child);
tab.setVisible(DesignAttributeHandler.readAttribute("visible", attr,
tab.isVisible(), Boolean.class));
@@ -1548,8 +1548,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
// create element for tab
Element tabElement = design.appendElement("tab");
// add tab content
- tabElement.appendChild(designContext
- .createNode((DesignSynchronizable) tab.getComponent()));
+ tabElement.appendChild(designContext.createNode(tab.getComponent()));
Attributes attr = tabElement.attributes();
// write attributes
DesignAttributeHandler.writeAttribute("visible", attr, tab.isVisible(),
diff --git a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
index f70a79447f..b410fd0001 100644
--- a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
+++ b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
@@ -49,7 +49,7 @@ import com.vaadin.server.FontAwesome;
import com.vaadin.server.Resource;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.util.SharedUtil;
-import com.vaadin.ui.DesignSynchronizable;
+import com.vaadin.ui.Component;
/**
* Default attribute handler implementation used when parsing designs to
@@ -104,9 +104,8 @@ public class DesignAttributeHandler implements Serializable {
* values
* @return true on success
*/
- public static boolean readAttribute(DesignSynchronizable component,
- String attribute, Attributes attributes,
- DesignSynchronizable defaultInstance) {
+ public static boolean readAttribute(Component component, String attribute,
+ Attributes attributes, Component defaultInstance) {
String value = null;
if (component == null || attribute == null || attributes == null
|| defaultInstance == null) {
@@ -213,9 +212,8 @@ public class DesignAttributeHandler implements Serializable {
* @param defaultInstance
* the default instance for comparing default values
*/
- public static void writeAttribute(DesignSynchronizable component,
- String attribute, Attributes attr,
- DesignSynchronizable defaultInstance) {
+ public static void writeAttribute(Component component, String attribute,
+ Attributes attr, Component defaultInstance) {
Method getter = findGetterForAttribute(component.getClass(), attribute);
if (getter == null) {
getLogger().warning(
diff --git a/server/src/com/vaadin/ui/declarative/DesignContext.java b/server/src/com/vaadin/ui/declarative/DesignContext.java
index 988dc7654e..753a2d87ba 100644
--- a/server/src/com/vaadin/ui/declarative/DesignContext.java
+++ b/server/src/com/vaadin/ui/declarative/DesignContext.java
@@ -29,7 +29,6 @@ import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import com.vaadin.ui.Component;
-import com.vaadin.ui.DesignSynchronizable;
/**
* This class contains contextual information that is collected when a component
@@ -47,19 +46,19 @@ public class DesignContext implements Serializable {
.synchronizedMap(new HashMap<Class<?>, Object>());
// The root component of the component hierarchy
- private DesignSynchronizable componentRoot = null;
+ private Component componentRoot = null;
// Attribute names for global id and caption and the prefix name for a local
// id
public static final String ID_ATTRIBUTE = "id";
public static final String CAPTION_ATTRIBUTE = "caption";
public static final String LOCAL_ID_ATTRIBUTE = "_id";
// Mappings from ids to components. Modified when synchronizing from design.
- private Map<String, DesignSynchronizable> idToComponent = new HashMap<String, DesignSynchronizable>();
- private Map<String, DesignSynchronizable> localIdToComponent = new HashMap<String, DesignSynchronizable>();
- private Map<String, DesignSynchronizable> captionToComponent = new HashMap<String, DesignSynchronizable>();
+ private Map<String, Component> idToComponent = new HashMap<String, Component>();
+ private Map<String, Component> localIdToComponent = new HashMap<String, Component>();
+ private Map<String, Component> captionToComponent = new HashMap<String, Component>();
// Mapping from components to local ids. Accessed when synchronizing to
// design. Modified when synchronizing from design.
- private Map<DesignSynchronizable, String> componentToLocalId = new HashMap<DesignSynchronizable, String>();
+ private Map<Component, String> componentToLocalId = new HashMap<Component, String>();
private Document doc; // required for calling createElement(String)
// namespace mappings
private Map<String, String> packageToPrefix = new HashMap<String, String>();
@@ -94,7 +93,7 @@ public class DesignContext implements Serializable {
* The local id of the component
* @return a component whose local id equals localId
*/
- public DesignSynchronizable getComponentByLocalId(String localId) {
+ public Component getComponentByLocalId(String localId) {
return localIdToComponent.get(localId);
}
@@ -106,7 +105,7 @@ public class DesignContext implements Serializable {
* The global id of the component
* @return a component whose global id equals globalId
*/
- public DesignSynchronizable getComponentById(String globalId) {
+ public Component getComponentById(String globalId) {
return idToComponent.get(globalId);
}
@@ -118,7 +117,7 @@ public class DesignContext implements Serializable {
* The caption of the component
* @return a component whose caption equals the caption given as a parameter
*/
- public DesignSynchronizable getComponentByCaption(String caption) {
+ public Component getComponentByCaption(String caption) {
return captionToComponent.get(caption);
}
@@ -142,8 +141,8 @@ public class DesignContext implements Serializable {
* @return true, if there already was a global id mapping from the string to
* some component.
*/
- private boolean mapId(String globalId, DesignSynchronizable component) {
- DesignSynchronizable oldComponent = idToComponent.get(globalId);
+ private boolean mapId(String globalId, Component component) {
+ Component oldComponent = idToComponent.get(globalId);
if (oldComponent != null && !oldComponent.equals(component)) {
oldComponent.setId(null);
}
@@ -174,7 +173,7 @@ public class DesignContext implements Serializable {
* some component or from the component to some string. Otherwise
* returns false.
*/
- private boolean mapLocalId(String localId, DesignSynchronizable component) {
+ private boolean mapLocalId(String localId, Component component) {
return twoWayMap(localId, component, localIdToComponent,
componentToLocalId);
}
@@ -196,7 +195,7 @@ public class DesignContext implements Serializable {
* @return true, if there already was a caption mapping from the string to
* some component.
*/
- private boolean mapCaption(String caption, DesignSynchronizable component) {
+ private boolean mapCaption(String caption, Component component) {
return captionToComponent.put(caption, component) != null;
}
@@ -337,12 +336,12 @@ public class DesignContext implements Serializable {
* rooted at the returned Node.
*
* @param childComponent
- * A component implementing the DesignSynchronizable interface.
+ * The component with state that is synchronized in to the node
* @return An html tree node corresponding to the given component. The tag
* name of the created node is derived from the class name of
* childComponent.
*/
- public Element createNode(DesignSynchronizable childComponent) {
+ public Element createNode(Component childComponent) {
Class<?> componentClass = childComponent.getClass();
String packageName = componentClass.getPackage().getName();
String prefix = packageToPrefix.get(packageName);
@@ -391,18 +390,18 @@ public class DesignContext implements Serializable {
}
/**
- * Creates a DesignSynchronizable object corresponding to the given html
- * node. Also calls synchronizeFromDesign() for the created node, in effect
- * creating the entire component hierarchy rooted at the returned component.
+ * Creates a Component corresponding to the given html node. Also calls
+ * synchronizeFromDesign() for the created node, in effect creating the
+ * entire component hierarchy rooted at the returned component.
*
* @param componentDesign
* The html tree node containing the description of the component
* to be created.
- * @return a DesignSynchronizable object corresponding to componentDesign
+ * @return a Component corresponding to componentDesign
*/
- public DesignSynchronizable createChild(Element componentDesign) {
+ public Component createChild(Element componentDesign) {
// Create the component.
- DesignSynchronizable component = instantiateComponent(componentDesign);
+ Component component = instantiateComponent(componentDesign);
synchronizeAndRegister(component, componentDesign);
fireComponentCreatedEvent(componentToLocalId.get(component), component);
return component;
@@ -421,7 +420,7 @@ public class DesignContext implements Serializable {
* @param componentDesign
* The html tree node containing the description of the component
*/
- public void synchronizeAndRegister(DesignSynchronizable component,
+ public void synchronizeAndRegister(Component component,
Element componentDesign) {
component.synchronizeFromDesign(componentDesign, this);
// Get the ids and the caption of the component and store them in the
@@ -451,20 +450,19 @@ public class DesignContext implements Serializable {
}
/**
- * Creates a DesignSynchronizable component corresponding to the given node.
- * Does not set the attributes for the created object.
+ * Creates a Component corresponding to the given node. Does not set the
+ * attributes for the created object.
*
* @param node
* a node of an html tree
- * @return a DesignSynchronizable object corresponding to node, with no
- * attributes set.
+ * @return a Component corresponding to node, with no attributes set.
*/
- private DesignSynchronizable instantiateComponent(Node node) {
+ private Component instantiateComponent(Node node) {
// Extract the package and class names.
String qualifiedClassName = tagNameToClassName(node);
try {
- Class<? extends DesignSynchronizable> componentClass = resolveComponentClass(qualifiedClassName);
- DesignSynchronizable newComponent = componentClass.newInstance();
+ Class<? extends Component> componentClass = resolveComponentClass(qualifiedClassName);
+ Component newComponent = componentClass.newInstance();
return newComponent;
} catch (Exception e) {
throw new DesignException("No component class could be found for "
@@ -519,14 +517,14 @@ public class DesignContext implements Serializable {
}
@SuppressWarnings("unchecked")
- private Class<? extends DesignSynchronizable> resolveComponentClass(
+ private Class<? extends Component> resolveComponentClass(
String qualifiedClassName) throws ClassNotFoundException {
Class<?> componentClass = null;
componentClass = Class.forName(qualifiedClassName);
- // Check that we're dealing with a DesignSynchronizable component.
- if (isDesignSynchronizable(componentClass)) {
- return (Class<? extends DesignSynchronizable>) componentClass;
+ // Check that we're dealing with a Component.
+ if (isComponent(componentClass)) {
+ return (Class<? extends Component>) componentClass;
} else {
throw new IllegalArgumentException(String.format(
"Resolved class %s is not a %s.", componentClass.getName(),
@@ -543,9 +541,9 @@ public class DesignContext implements Serializable {
* @return {@code true} if the given {@link Class} is a {@link Component},
* {@code false} otherwise.
*/
- private static boolean isDesignSynchronizable(Class<?> componentClass) {
+ private static boolean isComponent(Class<?> componentClass) {
if (componentClass != null) {
- return DesignSynchronizable.class.isAssignableFrom(componentClass);
+ return Component.class.isAssignableFrom(componentClass);
} else {
return false;
}
@@ -556,14 +554,14 @@ public class DesignContext implements Serializable {
*
* @return
*/
- public DesignSynchronizable getComponentRoot() {
+ public Component getComponentRoot() {
return componentRoot;
}
/**
* Sets the root component of a created component hierarchy.
*/
- public void setComponentRoot(DesignSynchronizable componentRoot) {
+ public void setComponentRoot(Component componentRoot) {
this.componentRoot = componentRoot;
}
@@ -597,8 +595,7 @@ public class DesignContext implements Serializable {
* @param component
* the component that was created
*/
- private void fireComponentCreatedEvent(String localId,
- DesignSynchronizable component) {
+ private void fireComponentCreatedEvent(String localId, Component component) {
ComponentCreatedEvent event = new ComponentCreatedEvent(localId,
component);
for (ComponentCreationListener listener : listeners) {
@@ -631,7 +628,7 @@ public class DesignContext implements Serializable {
*/
public class ComponentCreatedEvent implements Serializable {
private String localId;
- private DesignSynchronizable component;
+ private Component component;
private DesignContext context;
/**
@@ -642,8 +639,7 @@ public class DesignContext implements Serializable {
* @param component
* the created component
*/
- private ComponentCreatedEvent(String localId,
- DesignSynchronizable component) {
+ private ComponentCreatedEvent(String localId, Component component) {
this.localId = localId;
this.component = component;
context = DesignContext.this;
@@ -663,7 +659,7 @@ public class DesignContext implements Serializable {
*
* @return the component
*/
- public DesignSynchronizable getComponent() {
+ public Component getComponent() {
return component;
}
}
diff --git a/server/src/com/vaadin/ui/declarative/LayoutHandler.java b/server/src/com/vaadin/ui/declarative/LayoutHandler.java
index 862e93e8ff..b3ef2f15c7 100644
--- a/server/src/com/vaadin/ui/declarative/LayoutHandler.java
+++ b/server/src/com/vaadin/ui/declarative/LayoutHandler.java
@@ -30,7 +30,7 @@ import org.jsoup.nodes.Node;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;
-import com.vaadin.ui.DesignSynchronizable;
+import com.vaadin.ui.Component;
import com.vaadin.ui.declarative.DesignContext.ComponentCreatedEvent;
import com.vaadin.ui.declarative.DesignContext.ComponentCreationListener;
@@ -91,8 +91,7 @@ public class LayoutHandler implements Serializable {
* object returned by this method.
* @throws IOException
*/
- public static DesignContext parse(InputStream html,
- DesignSynchronizable rootInstance) {
+ public static DesignContext parse(InputStream html, Component rootInstance) {
Document doc;
try {
doc = Jsoup.parse(html, "UTF-8", "", Parser.htmlParser());
@@ -143,8 +142,7 @@ public class LayoutHandler implements Serializable {
* object returned by this method.
* @throws IOException
*/
- public static DesignContext parse(String html,
- DesignSynchronizable rootInstance) {
+ public static DesignContext parse(String html, Component rootInstance) {
Document doc = Jsoup.parse(html);
return parse(doc, rootInstance);
}
@@ -161,12 +159,10 @@ public class LayoutHandler implements Serializable {
* optional component root instance with some member fields. The
* type must match the type of the root element in the design.
* The member fields whose type is assignable from
- * {@link DesignSynchronizable} are set when parsing the
- * component tree
+ * {@link Component} are set when parsing the component tree
*
*/
- private static DesignContext parse(Document doc,
- DesignSynchronizable componentRoot) {
+ private static DesignContext parse(Document doc, Component componentRoot) {
DesignContext designContext = new DesignContext(doc);
designContext.getPrefixes(doc);
// No special handling for a document without a body element - should be
@@ -243,7 +239,7 @@ public class LayoutHandler implements Serializable {
// Append the design under <body> in the html tree. createNode
// creates the entire component hierarchy rooted at the
// given root node.
- DesignSynchronizable root = designContext.getComponentRoot();
+ Component root = designContext.getComponentRoot();
Node rootNode = designContext.createNode(root);
body.appendChild(rootNode);
return doc;
diff --git a/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java b/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java
index 1c4d50cc55..0c7ac50601 100644
--- a/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java
+++ b/server/tests/src/com/vaadin/tests/layoutparser/ParseLayoutTest.java
@@ -28,7 +28,7 @@ import org.jsoup.nodes.Node;
import org.junit.Test;
import com.vaadin.ui.Button;
-import com.vaadin.ui.DesignSynchronizable;
+import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.NativeButton;
@@ -149,7 +149,7 @@ public class ParseLayoutTest extends TestCase {
* component hierarchy rooted at context.getComponentRoot().
*/
private void checkHierarchy(DesignContext context) {
- DesignSynchronizable root = context.getComponentRoot();
+ Component root = context.getComponentRoot();
VerticalLayout vlayout = (VerticalLayout) root;
int numComponents = vlayout.getComponentCount();
assertEquals("Wrong number of child components", 3, numComponents);
diff --git a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java
index 12c3a60451..ce054007a6 100644
--- a/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/absolutelayout/TestSynchronizeFromDesign.java
@@ -27,7 +27,6 @@ import com.vaadin.server.Sizeable;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
import com.vaadin.ui.Component;
-import com.vaadin.ui.DesignSynchronizable;
import com.vaadin.ui.declarative.DesignContext;
/**
@@ -79,7 +78,7 @@ public class TestSynchronizeFromDesign extends TestCase {
private AbsoluteLayout createLayout() {
DesignContext ctx = new DesignContext();
Element design = createDesign();
- DesignSynchronizable child = ctx.createChild(design);
+ Component child = ctx.createChild(design);
return (AbsoluteLayout) child;
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java
index 6e57aac95b..2b3d4cbdac 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java
@@ -22,7 +22,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.parser.Tag;
import com.vaadin.ui.Alignment;
-import com.vaadin.ui.DesignSynchronizable;
+import com.vaadin.ui.Component;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.declarative.DesignContext;
@@ -80,7 +80,7 @@ public class TestSynchronizeFromDesign extends TestCase {
String... alignments) {
DesignContext ctx = new DesignContext();
Element design = createDesign(expandRatio, margin, alignments);
- DesignSynchronizable child = ctx.createChild(design);
+ Component child = ctx.createChild(design);
return (VerticalLayout) child;
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java
index 0e1b964b2e..e9694f0170 100644
--- a/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/csslayout/TestSynchronizeFromDesign.java
@@ -21,8 +21,8 @@ import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Tag;
+import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
-import com.vaadin.ui.DesignSynchronizable;
import com.vaadin.ui.declarative.DesignContext;
/**
@@ -47,7 +47,7 @@ public class TestSynchronizeFromDesign extends TestCase {
private CssLayout createLayout() {
DesignContext ctx = new DesignContext();
Element design = createDesign();
- DesignSynchronizable child = ctx.createChild(design);
+ Component child = ctx.createChild(design);
return (CssLayout) child;
}