summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/AbstractComponent.java
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2014-12-08 10:06:17 +0200
committerMika Murtojärvi <mika@vaadin.com>2014-12-08 09:15:21 +0000
commitbd78a4c8b2eb84cbba3bc686bcb40b19fd847640 (patch)
tree65fa99b11b65c7a5f8a0c4b29c21ae0f64d58a55 /server/src/com/vaadin/ui/AbstractComponent.java
parent117bf2b791b70d4e85916acf5e43a5c3b2ba66ca (diff)
downloadvaadin-framework-bd78a4c8b2eb84cbba3bc686bcb40b19fd847640.tar.gz
vaadin-framework-bd78a4c8b2eb84cbba3bc686bcb40b19fd847640.zip
Declarative support for Responsive (#7749)
Change-Id: I5b5b4ec966d4206e3fe4d31adf6674cd247dfbd2
Diffstat (limited to 'server/src/com/vaadin/ui/AbstractComponent.java')
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java51
1 files changed, 50 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index 8ee3f722ab..8349dcfa25 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -43,7 +43,9 @@ import com.vaadin.server.AbstractErrorMessage.ContentMode;
import com.vaadin.server.ComponentSizeValidator;
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.ErrorMessage.ErrorLevel;
+import com.vaadin.server.Extension;
import com.vaadin.server.Resource;
+import com.vaadin.server.Responsive;
import com.vaadin.server.Sizeable;
import com.vaadin.server.UserError;
import com.vaadin.server.VaadinSession;
@@ -938,6 +940,9 @@ public abstract class AbstractComponent extends AbstractClientConnector
} else {
setComponentError(def.getComponentError());
}
+ // handle responsive
+ setResponsive(attr.hasKey("responsive")
+ && !attr.get("responsive").equalsIgnoreCase("false"));
// check for unsupported attributes
Set<String> supported = new HashSet<String>();
supported.addAll(getDefaultAttributes());
@@ -952,6 +957,46 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
/**
+ * Toggles responsiveness of this component.
+ *
+ * @since 7.4
+ * @param responsive
+ * boolean enables responsiveness, false disables
+ */
+ private void setResponsive(boolean responsive) {
+ if (responsive) {
+ // make responsive if necessary
+ if (!isResponsive()) {
+ Responsive.makeResponsive(this);
+ }
+ } else {
+ // remove responsive extensions
+ List<Extension> extensions = new ArrayList<Extension>(
+ getExtensions());
+ for (Extension e : extensions) {
+ if (e instanceof Responsive) {
+ removeExtension(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns true if the component is responsive
+ *
+ * @since 7.4
+ * @return true if the component is responsive
+ */
+ private boolean isResponsive() {
+ for (Extension e : getExtensions()) {
+ if (e instanceof Responsive) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Synchronizes the size of this component from the given design attributes.
* If the attributes do not contain relevant size information, defaults is
* consulted.
@@ -1117,7 +1162,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" };
+ "width-full", "height-full", "size-auto", "size-full", "responsive" };
/*
* (non-Javadoc)
@@ -1147,6 +1192,10 @@ public abstract class AbstractComponent extends AbstractClientConnector
if (!SharedUtil.equals(errorMsg, defErrorMsg)) {
attr.put("error", errorMsg);
}
+ // handle responsive
+ if (isResponsive()) {
+ attr.put("responsive", "");
+ }
}
/*