aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java2
-rw-r--r--server/src/com/vaadin/ui/AbstractField.java65
-rw-r--r--server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java64
3 files changed, 130 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index 1b7eeadd87..434fb114df 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -1206,7 +1206,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
private static final String[] customAttributes = new String[] { "width",
"height", "debug-id", "error", "width-auto", "height-auto",
"width-full", "height-full", "size-auto", "size-full",
- "responsive", "immediate", "locale" };
+ "responsive", "immediate", "locale", "read-only" };
/*
* (non-Javadoc)
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java
index 369ad1253c..3728696233 100644
--- a/server/src/com/vaadin/ui/AbstractField.java
+++ b/server/src/com/vaadin/ui/AbstractField.java
@@ -25,6 +25,10 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
+import java.util.logging.Logger;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
import com.vaadin.data.Buffered;
import com.vaadin.data.Property;
@@ -43,6 +47,8 @@ import com.vaadin.server.CompositeErrorMessage;
import com.vaadin.server.ErrorMessage;
import com.vaadin.shared.AbstractFieldState;
import com.vaadin.shared.util.SharedUtil;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
/**
* <p>
@@ -1751,4 +1757,63 @@ public abstract class AbstractField<T> extends AbstractComponent implements
isListeningToPropertyEvents = false;
}
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes
+ * .Element, com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void synchronizeFromDesign(Element design,
+ DesignContext designContext) {
+ super.synchronizeFromDesign(design, designContext);
+ AbstractField def = designContext.getDefaultInstance(this.getClass());
+ Attributes attr = design.attributes();
+ boolean readOnly = DesignAttributeHandler.readAttribute("readonly",
+ attr, def.isReadOnly(), Boolean.class);
+ setReadOnly(readOnly);
+ // tabindex
+ int tabIndex = DesignAttributeHandler.readAttribute("tabindex", attr,
+ def.getTabIndex(), Integer.class);
+ setTabIndex(tabIndex);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractComponent#getCustomAttributes()
+ */
+ @Override
+ protected Collection<String> getCustomAttributes() {
+ Collection<String> attributes = super.getCustomAttributes();
+ attributes.add("readonly");
+ attributes.add("tabindex");
+ return attributes;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element
+ * , com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void synchronizeToDesign(Element design, DesignContext designContext) {
+ super.synchronizeToDesign(design, designContext);
+ AbstractField def = designContext.getDefaultInstance(this.getClass());
+ Attributes attr = design.attributes();
+ // handle readonly
+ DesignAttributeHandler.writeAttribute("readonly", attr,
+ super.isReadOnly(), def.isReadOnly(), Boolean.class);
+ // handle tab index
+ DesignAttributeHandler.writeAttribute("tabindex", attr, getTabIndex(),
+ def.getTabIndex(), Integer.class);
+ }
+
+ private static final Logger getLogger() {
+ return Logger.getLogger(AbstractField.class.getName());
+ }
}
diff --git a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
index f71b36f66c..1beddf57de 100644
--- a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
+++ b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
@@ -99,6 +99,7 @@ public class DesignAttributeHandler implements Serializable {
* @param defaultInstance
* the default instance of the class for fetching the default
* values
+ * @return true on success
*/
public static boolean readAttribute(DesignSynchronizable component,
String attribute, Attributes attributes,
@@ -237,6 +238,69 @@ public class DesignAttributeHandler implements Serializable {
}
/**
+ * Reads the given attribute from attributes. If the attribute is not found,
+ * the provided default value is returned
+ *
+ * @param attribute
+ * the attribute key
+ * @param attributes
+ * the set of attributes to read from
+ * @param defaultValue
+ * the default value that is returned if the attribute is not
+ * found
+ * @param outputType
+ * the output type for the attribute
+ * @return the attribute value or the default value if the attribute is not
+ * found
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T readAttribute(String attribute, Attributes attributes,
+ T defaultValue, Class<T> outputType) {
+ if (!isSupported(outputType)) {
+ throw new IllegalArgumentException("output type: "
+ + outputType.getName() + " not supported");
+ }
+ if (!attributes.hasKey(attribute)) {
+ return defaultValue;
+ } else {
+ try {
+ String value = attributes.get(attribute);
+ return (T) fromAttributeValue(outputType, value);
+ } catch (Exception e) {
+ throw new DesignException("Failed to read attribute "
+ + attribute, e);
+ }
+ }
+ }
+
+ /**
+ * Writes the given attribute value to attributes if it differs from the
+ * default attribute value
+ *
+ * @param attribute
+ * the attribute key
+ * @param attributes
+ * the set of attributes where the new attribute is written
+ * @param value
+ * the attribute value
+ * @param defaultValue
+ * the default attribute value
+ * @param the
+ * type of the input value
+ */
+ public static <T> void writeAttribute(String attribute,
+ Attributes attributes, T value, T defaultValue, Class<T> inputType) {
+ if (!isSupported(inputType)) {
+ throw new IllegalArgumentException("input type: "
+ + inputType.getName() + " not supported");
+ }
+ if (!SharedUtil.equals(value, defaultValue)) {
+ String attributeValue = toAttributeValue(value.getClass(), value);
+ attributes.put(attribute, attributeValue);
+ }
+ }
+
+ /**
* Formats the given design attribute value. The method is provided to
* ensure consistent number formatting for design attribute values
*