summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/AbstractComponent.java
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2014-11-28 16:03:11 +0200
committerMatti Hosio <mhosio@vaadin.com>2014-11-28 16:03:11 +0200
commitd54337ec3259fce95142227935e4471f3712ac68 (patch)
treeb5bb0a965e0a04c4dbcd1ebc65b49cabe0dcc81e /server/src/com/vaadin/ui/AbstractComponent.java
parent0545cb2999c83b11da55477211b87865bae98bba (diff)
downloadvaadin-framework-d54337ec3259fce95142227935e4471f3712ac68.tar.gz
vaadin-framework-d54337ec3259fce95142227935e4471f3712ac68.zip
support for declarative in AbstractComponent
Diffstat (limited to 'server/src/com/vaadin/ui/AbstractComponent.java')
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java66
1 files changed, 65 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index 5c4fba739d..78004d0eca 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -26,6 +26,9 @@ import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Node;
+
import com.vaadin.event.ActionManager;
import com.vaadin.event.ConnectorActionManager;
import com.vaadin.event.ShortcutListener;
@@ -39,6 +42,8 @@ import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.Field.ValueChangeEvent;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
import com.vaadin.util.ReflectTools;
/**
@@ -52,7 +57,7 @@ import com.vaadin.util.ReflectTools;
*/
@SuppressWarnings("serial")
public abstract class AbstractComponent extends AbstractClientConnector
- implements Component {
+ implements Component, DesignSynchronizable {
/* Private members */
@@ -897,6 +902,65 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
/*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.ui.DesignSynchronizable#synchronizeFromDesign(org.jsoup.nodes
+ * .Node, com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void synchronizeFromDesign(Node design, DesignContext designContext) {
+ Attributes attr = design.attributes();
+ DesignSynchronizable def = designContext.getDefaultInstance(this
+ .getClass());
+ // handle default attributes
+ for (String property : getDefaultAttributes()) {
+ String value = null;
+ if (attr.hasKey(property)) {
+ value = attr.get(property);
+ }
+ DesignAttributeHandler.assignAttribute(this, property, value, def);
+ }
+ // handle width and height
+ DesignAttributeHandler.assignWidth(this, attr, def);
+ DesignAttributeHandler.assignHeight(this, attr, def);
+ }
+
+ /**
+ * Returns the list of attributes that do not require custom handling when
+ * synchronizing from design. These are typically attributes of some
+ * primitive type. The default implementation searches setters with
+ * primitive values
+ *
+ * @since 7.4
+ * @return the list of attributes that can be synchronized from design using
+ * the default approach.
+ */
+ protected List<String> getDefaultAttributes() {
+ List<String> attributes = DesignAttributeHandler
+ .findSupportedAttributes(this.getClass());
+ // we want to handle width and height in a custom way
+ attributes.remove("width");
+ attributes.remove("height");
+ attributes.remove("debug-id");
+ return attributes;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.ui.DesignSynchronizable#synchronizeToDesign(org.jsoup.nodes
+ * .Node, com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void synchronizeToDesign(Node design, DesignContext designContext) {
+ AbstractComponent def = designContext.getDefaultInstance(this
+ .getClass());
+
+ }
+
+ /*
* Returns array with size in index 0 unit in index 1. Null or empty string
* will produce {-1,Unit#PIXELS}
*/