From ea1d229c70fa2e9edc63b234c483c36ee6114a29 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 15 Dec 2014 22:48:50 +0200 Subject: Handle tab indexes in a generic way (#7749) Change-Id: I6e449ed7fd0acaf683da98ae3fcf55ff544c3b48 --- server/src/com/vaadin/ui/AbstractComponent.java | 21 ++++++++++++++++++++- server/src/com/vaadin/ui/AbstractField.java | 9 --------- server/src/com/vaadin/ui/Button.java | 9 --------- server/src/com/vaadin/ui/Panel.java | 9 --------- server/src/com/vaadin/ui/TabSheet.java | 16 +--------------- 5 files changed, 21 insertions(+), 43 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index 83833b75ce..4d4556d4d9 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -950,6 +950,13 @@ public abstract class AbstractComponent extends AbstractClientConnector ContentMode.HTML, ErrorLevel.ERROR); setComponentError(error); } + // Tab index when applicable + if (design.hasAttr("tabindex") && this instanceof Focusable) { + ((Focusable) this).setTabIndex(DesignAttributeHandler + .readAttribute("tabindex", design.attributes(), + Integer.class)); + } + // handle responsive setResponsive(attr.hasKey("responsive") && !attr.get("responsive").equalsIgnoreCase("false")); @@ -1188,7 +1195,12 @@ public abstract class AbstractComponent extends AbstractClientConnector * implementation */ protected Collection getCustomAttributes() { - return new ArrayList(Arrays.asList(customAttributes)); + ArrayList l = new ArrayList( + Arrays.asList(customAttributes)); + if (this instanceof Focusable) { + l.add("tab-index"); + } + return l; } private static final String[] customAttributes = new String[] { "width", @@ -1232,6 +1244,13 @@ public abstract class AbstractComponent extends AbstractClientConnector if (!SharedUtil.equals(errorMsg, defErrorMsg)) { attr.put("error", errorMsg); } + // handle tab index + if (this instanceof Focusable) { + DesignAttributeHandler.writeAttribute("tabindex", attr, + ((Focusable) this).getTabIndex(), + ((Focusable) def).getTabIndex(), Integer.class); + } + // handle responsive if (isResponsive()) { attr.put("responsive", ""); diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index e40bdbde68..b5f02e5b2a 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1772,11 +1772,6 @@ public abstract class AbstractField extends AbstractComponent implements setReadOnly(DesignAttributeHandler.readAttribute("readonly", attr, Boolean.class)); } - // tabindex - if (design.hasAttr("tabindex")) { - setTabIndex(DesignAttributeHandler.readAttribute("tabindex", attr, - Integer.class)); - } } /* @@ -1788,7 +1783,6 @@ public abstract class AbstractField extends AbstractComponent implements protected Collection getCustomAttributes() { Collection attributes = super.getCustomAttributes(); attributes.add("readonly"); - attributes.add("tabindex"); // must be handled by subclasses attributes.add("value"); return attributes; @@ -1808,9 +1802,6 @@ public abstract class AbstractField extends AbstractComponent implements // 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() { diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java index db78b04a28..c102157bf1 100644 --- a/server/src/com/vaadin/ui/Button.java +++ b/server/src/com/vaadin/ui/Button.java @@ -678,11 +678,6 @@ public class Button extends AbstractComponent implements Attributes attr = design.attributes(); String content = design.html(); setCaption(content); - // tabindex - if (attr.hasKey("tabindex")) { - setTabIndex(DesignAttributeHandler.readAttribute("tabindex", attr, - Integer.class)); - } // plain-text (default is html) Boolean plain = DesignAttributeHandler.readAttribute( DESIGN_ATTR_PLAIN_TEXT, attr, Boolean.class); @@ -710,7 +705,6 @@ public class Button extends AbstractComponent implements @Override protected Collection getCustomAttributes() { Collection result = super.getCustomAttributes(); - result.add("tabindex"); result.add(DESIGN_ATTR_PLAIN_TEXT); result.add("caption"); result.add("icon-alt"); @@ -735,9 +729,6 @@ public class Button extends AbstractComponent implements if (content != null) { design.html(content); } - // tabindex - DesignAttributeHandler.writeAttribute("tabindex", attr, getTabIndex(), - def.getTabIndex(), Integer.class); // plain-text (default is html) if (!isHtmlContentAllowed()) { design.attr(DESIGN_ATTR_PLAIN_TEXT, ""); diff --git a/server/src/com/vaadin/ui/Panel.java b/server/src/com/vaadin/ui/Panel.java index 0c2a3f580b..6458d5f57d 100644 --- a/server/src/com/vaadin/ui/Panel.java +++ b/server/src/com/vaadin/ui/Panel.java @@ -34,7 +34,6 @@ import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.panel.PanelServerRpc; import com.vaadin.shared.ui.panel.PanelState; import com.vaadin.ui.Component.Focusable; -import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; /** @@ -347,17 +346,11 @@ public class Panel extends AbstractSingleComponentContainer implements @Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); - // handle tabindex - int tabIndex = DesignAttributeHandler.readAttribute("tabindex", - design.attributes(), Integer.class); - setTabIndex(tabIndex); } @Override protected Collection getCustomAttributes() { Collection attributes = super.getCustomAttributes(); - attributes.add("tabindex"); - attributes.add("tab-index"); return attributes; } @@ -366,8 +359,6 @@ public class Panel extends AbstractSingleComponentContainer implements super.writeDesign(design, designContext); // handle tabindex Panel def = (Panel) designContext.getDefaultInstance(this); - DesignAttributeHandler.writeAttribute("tabindex", design.attributes(), - getTabIndex(), def.getTabIndex(), Integer.class); } } diff --git a/server/src/com/vaadin/ui/TabSheet.java b/server/src/com/vaadin/ui/TabSheet.java index 442be21825..ef3ef80960 100644 --- a/server/src/com/vaadin/ui/TabSheet.java +++ b/server/src/com/vaadin/ui/TabSheet.java @@ -1464,8 +1464,6 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, @Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); - // handle tab index - readTabIndex(design); // clear old tabs removeAllComponents(); // create new tabs @@ -1478,15 +1476,6 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, } } - private void readTabIndex(Element design) { - // Could be in AbstractComponent as if (this implements Focusable) - if (design.hasAttr("tabindex")) { - setTabIndex(DesignAttributeHandler.readAttribute("tabindex", - design.attributes(), Integer.class)); - } - - } - /** * Reads the given tab element from design * @@ -1609,7 +1598,6 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, @Override protected Collection getCustomAttributes() { Collection attributes = super.getCustomAttributes(); - attributes.add("tabindex"); // no need to list tab attributes since they are considered internal return attributes; } @@ -1625,9 +1613,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, super.writeDesign(design, designContext); TabSheet def = (TabSheet) designContext.getDefaultInstance(this); Attributes attr = design.attributes(); - // handle tab index - DesignAttributeHandler.writeAttribute("tabindex", attr, getTabIndex(), - def.getTabIndex(), Integer.class); + // write tabs for (Component component : this) { Tab tab = this.getTab(component); -- cgit v1.2.3