]> source.dussan.org Git - vaadin-framework.git/commitdiff
Restore column based width for compatibility selects
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 6 Mar 2017 14:19:51 +0000 (16:19 +0200)
committerHenri Sara <henri.sara@gmail.com>
Tue, 7 Mar 2017 10:36:54 +0000 (12:36 +0200)
compatibility-client/src/main/java/com/vaadin/v7/client/ui/VOptionGroupBase.java
compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTwinColSelect.java
compatibility-client/src/main/java/com/vaadin/v7/client/ui/optiongroup/OptionGroupBaseConnector.java
compatibility-server/src/main/java/com/vaadin/v7/ui/ListSelect.java
compatibility-server/src/main/java/com/vaadin/v7/ui/NativeSelect.java
compatibility-server/src/main/java/com/vaadin/v7/ui/TwinColSelect.java
uitest/src/main/java/com/vaadin/tests/components/listselect/ListSelects.java
uitest/src/main/java/com/vaadin/tests/components/select/TwinColSelectTest.java
uitest/src/main/java/com/vaadin/tests/components/twincolselect/TwinColSelects.java
uitest/src/main/java/com/vaadin/v7/tests/components/nativeselect/NativeSelects.java

index 239e6ff53aff680d7e26b903a5d4e613923013a1..2e5ed2319f8eb8c71f0dfa63c4b101b41e868ca4 100644 (file)
@@ -60,7 +60,8 @@ public abstract class VOptionGroupBase extends Composite implements Field,
 
     private boolean readonly;
 
-    // Intentional removal of cols in compatibility package
+    /** For internal use only. May be removed or replaced in the future. */
+    public int cols = 0;
 
     /** For internal use only. May be removed or replaced in the future. */
     public int rows = 0;
@@ -136,7 +137,14 @@ public abstract class VOptionGroupBase extends Composite implements Field,
         return nullSelectionItemAvailable;
     }
 
-    // Intentional removal of getColumns in compatibility package
+    /**
+     * For internal use only. May be removed or replaced in the future.
+     *
+     * @return "cols" specified in uidl, 0 if not specified
+     */
+    public int getColumns() {
+        return cols;
+    }
 
     /**
      * For internal use only. May be removed or replaced in the future.
index 2403750b034926df70c80c4d9238f7a98bb058ea..70e8d1892f942d1f7550249ab41c5cf9ec53f03f 100644 (file)
@@ -367,8 +367,12 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
 
     /** For internal use only. May be removed or replaced in the future. */
     public void clearInternalWidths() {
-        // Intentional removal of cols in compatibility package
-        int cols = DEFAULT_COLUMN_COUNT;
+        int cols = -1;
+        if (getColumns() > 0) {
+            cols = getColumns();
+        } else {
+            cols = DEFAULT_COLUMN_COUNT;
+        }
 
         if (cols >= 0) {
             String colWidth = cols + "em";
index 6fe94fa5a5bdb51cfc4946ad14d1d6d30225c954..1de28c832a3adb651d2382a94c5fa5f7af32bd55 100644 (file)
@@ -51,15 +51,21 @@ public abstract class OptionGroupBaseConnector extends AbstractFieldConnector
         getWidget().nullSelectionItemAvailable = uidl
                 .getBooleanAttribute("nullselectitem");
 
-        // Support for cols has been dropped.
-
+        if (uidl.hasAttribute("cols")) {
+            getWidget().cols = uidl.getIntAttribute("cols");
+        }
         if (uidl.hasAttribute("rows")) {
             getWidget().rows = uidl.getIntAttribute("rows");
         }
 
         final UIDL ops = uidl.getChildUIDL(0);
 
-        // Method getColumns has been removed
+        if (getWidget().getColumns() > 0) {
+            getWidget().container.setWidth(getWidget().getColumns() + "em");
+            if (getWidget().container != getWidget().optionsContainer) {
+                getWidget().optionsContainer.setWidth("100%");
+            }
+        }
 
         getWidget().buildOptions(ops);
 
index 91b3c8375dc3c9977d78fea84aa31edc043c35aa..4a741b293cf8f34d4419aeeedecb4a9eedc862eb 100644 (file)
@@ -33,6 +33,7 @@ import com.vaadin.v7.data.Container;
 @Deprecated
 public class ListSelect extends AbstractSelect {
 
+    private int columns = 0;
     private int rows = 0;
 
     public ListSelect() {
@@ -51,7 +52,45 @@ public class ListSelect extends AbstractSelect {
         super(caption);
     }
 
-    // Columns are no longer used for width.
+    /**
+     * Sets the width of the component so that it can display approximately the
+     * given number of letters.
+     * <p>
+     * Calling {@code setColumns(10);} is equivalent to calling
+     * {@code setWidth("10em");}
+     * </p>
+     *
+     * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+     *             characters that will be displayed. It is better to use
+     *             setWidth together with "em" to control the width of the
+     *             field.
+     * @param columns
+     *            the number of columns to set.
+     */
+    @Deprecated
+    public void setColumns(int columns) {
+        if (columns < 0) {
+            columns = 0;
+        }
+        if (this.columns != columns) {
+            this.columns = columns;
+            markAsDirty();
+        }
+    }
+
+    /**
+     * Gets the number of columns for the component.
+     *
+     * @see #setColumns(int)
+     * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+     *             characters that will be displayed. It is better to use
+     *             setWidth together with "em" to control the width of the
+     *             field.
+     */
+    @Deprecated
+    public int getColumns() {
+        return columns;
+    }
 
     public int getRows() {
         return rows;
@@ -78,6 +117,10 @@ public class ListSelect extends AbstractSelect {
     @Override
     public void paintContent(PaintTarget target) throws PaintException {
         target.addAttribute("type", "list");
+        // Adds the number of columns
+        if (columns != 0) {
+            target.addAttribute("cols", columns);
+        }
         // Adds the number of rows
         if (rows != 0) {
             target.addAttribute("rows", rows);
index 3f53969bc79d43fe34d9d2c934b559cb5bda94ce..e69f7c620b70e55fa1ec1db69ac54545bdace692 100644 (file)
@@ -42,6 +42,9 @@ import com.vaadin.v7.event.FieldEvents;
 public class NativeSelect extends AbstractSelect
         implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
 
+    // width in characters, mimics TextField
+    private int columns = 0;
+
     public NativeSelect() {
         super();
         registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
@@ -62,9 +65,53 @@ public class NativeSelect extends AbstractSelect
         registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
     }
 
+    /**
+     * Sets the width of the component so that it can display approximately the
+     * given number of letters.
+     * <p>
+     * Calling {@code setColumns(10);} is equivalent to calling
+     * {@code setWidth("10em");}
+     * </p>
+     *
+     * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+     *             characters that will be displayed. It is better to use
+     *             setWidth together with "em" to control the width of the
+     *             field.
+     * @param columns
+     *            the number of columns to set.
+     */
+    @Deprecated
+    public void setColumns(int columns) {
+        if (columns < 0) {
+            columns = 0;
+        }
+        if (this.columns != columns) {
+            this.columns = columns;
+            markAsDirty();
+        }
+    }
+
+    /**
+     * Gets the number of columns for the component.
+     *
+     * @see #setColumns(int)
+     * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+     *             characters that will be displayed. It is better to use
+     *             setWidth together with "em" to control the width of the
+     *             field.
+     */
+    @Deprecated
+    public int getColumns() {
+        return columns;
+    }
+
     @Override
     public void paintContent(PaintTarget target) throws PaintException {
         target.addAttribute("type", "native");
+        // Adds the number of columns
+        if (columns != 0) {
+            target.addAttribute("cols", columns);
+        }
 
         super.paintContent(target);
     }
index 965fe85e99482bd53c27e972fc9255d4b899a582..c90cddb595c690ca1d077857dfa111979092f127 100644 (file)
@@ -35,6 +35,7 @@ import com.vaadin.v7.shared.ui.twincolselect.TwinColSelectState;
 @Deprecated
 public class TwinColSelect extends AbstractSelect {
 
+    private int columns = 0;
     private int rows = 0;
 
     private String leftColumnCaption;
@@ -65,7 +66,45 @@ public class TwinColSelect extends AbstractSelect {
         setMultiSelect(true);
     }
 
-    // Columns are no longer used for width.
+    /**
+     * Sets the width of the component so that it displays approximately the
+     * given number of letters in each of the two selects.
+     * <p>
+     * Calling {@code setColumns(10);} is roughly equivalent to calling
+     * {@code setWidth((10*2+4)+"10em");}
+     * </p>
+     *
+     * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+     *             characters that will be displayed. It is better to use
+     *             setWidth together with "em" to control the width of the
+     *             field.
+     * @param columns
+     *            the number of columns to set.
+     */
+    @Deprecated
+    public void setColumns(int columns) {
+        if (columns < 0) {
+            columns = 0;
+        }
+        if (this.columns != columns) {
+            this.columns = columns;
+            markAsDirty();
+        }
+    }
+
+    /**
+     * Gets the number of columns for the component.
+     *
+     * @see #setColumns(int)
+     * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+     *             characters that will be displayed. It is better to use
+     *             setWidth together with "em" to control the width of the
+     *             field.
+     */
+    @Deprecated
+    public int getColumns() {
+        return columns;
+    }
 
     public int getRows() {
         return rows;
@@ -107,7 +146,10 @@ public class TwinColSelect extends AbstractSelect {
     @Override
     public void paintContent(PaintTarget target) throws PaintException {
         target.addAttribute("type", "twincol");
-        // Width is no longer based on columns
+        // Adds the number of columns
+        if (columns != 0) {
+            target.addAttribute("cols", columns);
+        }
         // Adds the number of rows
         if (rows != 0) {
             target.addAttribute("rows", rows);
index f42098eb885d00f6d97239ae3785206316ac5618..c98c64ccd0c357275061861c4cde3544b6052a7b 100644 (file)
@@ -7,6 +7,13 @@ import com.vaadin.v7.ui.ListSelect;
 
 public class ListSelects extends AbstractSelectTestCase<ListSelect> {
 
+    private Command<ListSelect, Integer> colsCommand = new Command<ListSelect, Integer>() {
+        @Override
+        public void execute(ListSelect c, Integer value, Object data) {
+            c.setColumns(value);
+        }
+    };
+
     private Command<ListSelect, Integer> rowsCommand = new Command<ListSelect, Integer>() {
         @Override
         public void execute(ListSelect c, Integer value, Object data) {
@@ -23,6 +30,7 @@ public class ListSelects extends AbstractSelectTestCase<ListSelect> {
     protected void createActions() {
         super.createActions();
         createRowsAction(CATEGORY_FEATURES);
+        createColsAction(CATEGORY_FEATURES);
     }
 
     private void createRowsAction(String category) {
@@ -30,4 +38,8 @@ public class ListSelects extends AbstractSelectTestCase<ListSelect> {
         createSelectAction("Rows", category, options, "0", rowsCommand);
     }
 
+    private void createColsAction(String category) {
+        LinkedHashMap<String, Integer> options = createIntegerOptions(20);
+        createSelectAction("Columns", category, options, "0", colsCommand);
+    }
 }
index 411cb361a3e86b7eb5bf3878d886699437c237af..ed36033c50c8c024968cfde0bf5b5a584e6e76bf 100644 (file)
@@ -13,6 +13,13 @@ public class TwinColSelectTest extends AbstractSelectTestCase<TwinColSelect> {
         }
     };
 
+    private Command<TwinColSelect, Integer> colsCommand = new Command<TwinColSelect, Integer>() {
+        @Override
+        public void execute(TwinColSelect c, Integer value, Object data) {
+            c.setColumns(value);
+        }
+    };
+
     private Command<TwinColSelect, String> leftColumnCaptionCommand = new Command<TwinColSelect, String>() {
 
         @Override
@@ -38,6 +45,7 @@ public class TwinColSelectTest extends AbstractSelectTestCase<TwinColSelect> {
     protected void createActions() {
         super.createActions();
         createRowsAction(CATEGORY_FEATURES);
+        createColsAction(CATEGORY_FEATURES);
         createCaptionActions(CATEGORY_FEATURES);
     }
 
@@ -46,6 +54,11 @@ public class TwinColSelectTest extends AbstractSelectTestCase<TwinColSelect> {
         createSelectAction("Rows", category, options, "0", rowsCommand);
     }
 
+    private void createColsAction(String category) {
+        LinkedHashMap<String, Integer> options = createIntegerOptions(20);
+        createSelectAction("Columns", category, options, "0", colsCommand);
+    }
+
     private void createCaptionActions(String category) {
         createSelectAction("Left column caption", category,
                 createCaptionOptions(), "-", leftColumnCaptionCommand);
index 230825d808e7ccf55e4a82d68485bbb769683878..602916d509015aee86879c1c0f674c1e3d9c6bc6 100644 (file)
@@ -16,6 +16,22 @@ public class TwinColSelects extends AbstractSelectTestCase<TwinColSelect> {
     protected void createActions() {
         super.createActions();
         createRowSelectAction();
+        createColumnSelectAction();
+    }
+
+    private void createColumnSelectAction() {
+        LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
+        options.put("-", 0);
+        for (int i = 1; i <= 10; i++) {
+            options.put(String.valueOf(i), i);
+        }
+        options.put("50", 50);
+        options.put("100", 100);
+        options.put("1000", 1000);
+
+        super.createSelectAction("Columns", CATEGORY_DATA_SOURCE, options, "-",
+                columnsAction);
+
     }
 
     private void createRowSelectAction() {
@@ -33,6 +49,14 @@ public class TwinColSelects extends AbstractSelectTestCase<TwinColSelect> {
 
     }
 
+    private Command<TwinColSelect, Integer> columnsAction = new Command<TwinColSelect, Integer>() {
+
+        @Override
+        public void execute(TwinColSelect c, Integer value, Object data) {
+            c.setColumns(value);
+        }
+    };
+
     private Command<TwinColSelect, Integer> rowsAction = new Command<TwinColSelect, Integer>() {
 
         @Override
index bb84e88d46390b2c872df2f330a01526e81d3747..56799576693652df8c408e14cb325095cf133321 100644 (file)
@@ -1,5 +1,7 @@
 package com.vaadin.v7.tests.components.nativeselect;
 
+import java.util.LinkedHashMap;
+
 import com.vaadin.tests.components.select.AbstractSelectTestCase;
 import com.vaadin.v7.ui.NativeSelect;
 
@@ -13,6 +15,29 @@ public class NativeSelects extends AbstractSelectTestCase<NativeSelect> {
     @Override
     protected void createActions() {
         super.createActions();
+        createColumnSelectAction();
+    }
+
+    private void createColumnSelectAction() {
+        LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
+        options.put("-", 0);
+        for (int i = 1; i <= 10; i++) {
+            options.put(String.valueOf(i), i);
+        }
+        options.put("50", 50);
+        options.put("100", 100);
+        options.put("1000", 1000);
+
+        super.createSelectAction("Columns", CATEGORY_DATA_SOURCE, options, "-",
+                columnsAction);
+
     }
 
+    private Command<NativeSelect, Integer> columnsAction = new Command<NativeSelect, Integer>() {
+
+        @Override
+        public void execute(NativeSelect c, Integer value, Object data) {
+            c.setColumns(value);
+        }
+    };
 }