]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed tab index for Button and NativeButton (#9022)
authorArtur Signell <artur@vaadin.com>
Mon, 25 Jun 2012 09:04:22 +0000 (12:04 +0300)
committerArtur Signell <artur@vaadin.com>
Mon, 25 Jun 2012 09:05:06 +0000 (12:05 +0300)
src/com/vaadin/terminal/gwt/client/ui/button/ButtonState.java
src/com/vaadin/ui/Button.java
tests/testbench/com/vaadin/tests/components/button/ButtonTabIndex.java [new file with mode: 0644]

index fdc053b3aea1941892c94237dc9428255f6469c3..2daceea0e833c3a37f01cd2ab7ac53ae7e22e451 100644 (file)
@@ -5,6 +5,7 @@
 package com.vaadin.terminal.gwt.client.ui.button;
 
 import com.vaadin.terminal.gwt.client.ComponentState;
+import com.vaadin.terminal.gwt.client.ui.TabIndexState;
 import com.vaadin.ui.Button;
 
 /**
@@ -14,9 +15,13 @@ import com.vaadin.ui.Button;
  * 
  * @since 7.0
  */
-public class ButtonState extends ComponentState {
+public class ButtonState extends ComponentState implements TabIndexState {
     private boolean disableOnClick = false;
     private int clickShortcutKeyCode = 0;
+    /**
+     * The tab order number of this field.
+     */
+    private int tabIndex = 0;
     /**
      * If caption should be rendered in HTML
      */
@@ -92,4 +97,22 @@ public class ButtonState extends ComponentState {
         return htmlContentAllowed;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.vaadin.terminal.gwt.client.ui.TabIndexState#getTabIndex()
+     */
+    public int getTabIndex() {
+        return tabIndex;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.vaadin.terminal.gwt.client.ui.TabIndexState#setTabIndex(int)
+     */
+    public void setTabIndex(int tabIndex) {
+        this.tabIndex = tabIndex;
+    }
+
 }
index 8e504d828b05b2c6b7b8a7f38fa56612b5cb5699..0abc50f26f822c7fe744e4ff65f6215d6e16a5fe 100644 (file)
@@ -357,8 +357,6 @@ public class Button extends AbstractComponent implements
 
     protected ClickShortcut clickShortcut;
 
-    private int tabIndex = 0;
-
     /**
      * Makes it possible to invoke a click on this button by pressing the given
      * {@link KeyCode} and (optional) {@link ModifierKey}s.<br/>
@@ -471,13 +469,23 @@ public class Button extends AbstractComponent implements
         requestRepaint();
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.vaadin.ui.Component.Focusable#getTabIndex()
+     */
     public int getTabIndex() {
-        return tabIndex;
+        return getState().getTabIndex();
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.vaadin.ui.Component.Focusable#setTabIndex(int)
+     */
     public void setTabIndex(int tabIndex) {
-        this.tabIndex = tabIndex;
-
+        getState().setTabIndex(tabIndex);
+        requestRepaint();
     }
 
     @Override
diff --git a/tests/testbench/com/vaadin/tests/components/button/ButtonTabIndex.java b/tests/testbench/com/vaadin/tests/components/button/ButtonTabIndex.java
new file mode 100644 (file)
index 0000000..048e069
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.tests.components.button;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.TextField;
+
+public class ButtonTabIndex extends TestBase {
+
+    @Override
+    protected void setup() {
+        TextField tf1 = new TextField("Tab index 0");
+        tf1.setTabIndex(0);
+        TextField tf2 = new TextField("Tab index -1, focused initially");
+        tf2.setTabIndex(-1);
+        tf2.focus();
+        addComponent(tf1);
+        addComponent(tf2);
+
+        addComponent(createButton(1));
+        addComponent(createButton(5));
+        addComponent(createNativeButton(3));
+        addComponent(createButton(4));
+        addComponent(createNativeButton(2));
+
+    }
+
+    private Button createButton(int i) {
+        Button b = new Button("Button with tab index " + i);
+        b.setTabIndex(i);
+        return b;
+    }
+
+    private NativeButton createNativeButton(int i) {
+        NativeButton b = new NativeButton("NativeButton with tab index " + i);
+        b.setTabIndex(i);
+        return b;
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Test for tab indexes for Button and NativeButton";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 9022;
+    }
+
+}