]> source.dussan.org Git - vaadin-framework.git/commitdiff
Revert NativeSelect DOM structure change 8.0.0.alpha4
authorAleksi Hietanen <aleksi@vaadin.com>
Fri, 7 Oct 2016 06:41:33 +0000 (09:41 +0300)
committerAleksi Hietanen <aleksi@vaadin.com>
Fri, 7 Oct 2016 15:19:22 +0000 (15:19 +0000)
Change-Id: I11dcd769dd81a90b41cc74707ef8d6ef4ddc9be7

client/src/main/java/com/vaadin/client/ui/VNativeSelect.java
client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java
shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java
uitest-common/src/main/java/com/vaadin/testbench/customelements/NativeSelectElement.java

index 716450c82afd9a35d37d5bca6b57054cd87fa50b..efbba52efc2c5187c5331bed4a4296d96ea20798 100644 (file)
@@ -1,12 +1,12 @@
 /*
  * Copyright 2000-2016 Vaadin Ltd.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,41 +17,55 @@ package com.vaadin.client.ui;
 
 import java.util.Objects;
 
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.ListBox;
-import com.vaadin.shared.ui.nativeselect.NativeSelectState;
 
 /**
  * The client-side widget for the {@code NativeSelect} component.
- * 
+ *
  * @author Vaadin Ltd.
  */
-public class VNativeSelect extends ListBox {
+public class VNativeSelect extends Composite {
+
+    private final ListBox listBox = new ListBox();
 
     /**
      * Creates a new {@code VNativeSelect} instance.
      */
     public VNativeSelect() {
-        setStyleName(NativeSelectState.STYLE_NAME);
+        FlowPanel panel = new FlowPanel();
+        panel.add(listBox);
+        initWidget(panel);
     }
 
     /**
      * Sets the selected item by its value. If given {@code null}, removes
      * selection.
-     * 
+     *
      * @param value
      *            the value of the item to select or {@code null} to select
      *            nothing
      */
     public void setSelectedItem(String value) {
         if (value == null) {
-            setSelectedIndex(-1);
+            getListBox().setSelectedIndex(-1);
         } else {
-            for (int i = 0; i < getItemCount(); i++) {
-                if (Objects.equals(value, getValue(i))) {
-                    setSelectedIndex(i);
+            for (int i = 0; i < getListBox().getItemCount(); i++) {
+                if (Objects.equals(value, getListBox().getValue(i))) {
+                    getListBox().setSelectedIndex(i);
                     break;
                 }
             }
         }
     }
+
+    /**
+     * Gets the underlying ListBox widget that this widget wraps.
+     *
+     * @return the ListBox this widget wraps
+     */
+    public ListBox getListBox() {
+        return listBox;
+    }
 }
index ffda0166e3f5e4e47590c4657040bdecd0b519d2..93861b41dc94e6fa8340f3de6208c124f54306b8 100644 (file)
@@ -32,12 +32,12 @@ import elemental.json.JsonObject;
 
 /**
  * The client-side connector for the {@code NativeSelect} component.
- * 
+ *
  * @author Vaadin Ltd.
- * 
+ *
  * @see com.vaadin.ui.NativeSelect
  * @see com.vaadin.client.ui.VNativeSelect
- * 
+ *
  * @since 8.0
  */
 @Connect(com.vaadin.ui.NativeSelect.class)
@@ -53,9 +53,11 @@ public class NativeSelectConnector
     @Override
     protected void init() {
         super.init();
-
-        selectionChangeRegistration = getWidget().addChangeHandler(
-                e -> selectionRpc.select(getWidget().getSelectedValue()));
+        getWidget().getListBox()
+                .setStyleName(NativeSelectState.STYLE_NAME + "-select");
+        selectionChangeRegistration = getWidget().getListBox()
+                .addChangeHandler(e -> selectionRpc
+                        .select(getWidget().getListBox().getSelectedValue()));
     }
 
     @Override
@@ -83,7 +85,7 @@ public class NativeSelectConnector
     @OnStateChange("readOnly")
     @SuppressWarnings("deprecation")
     void updateWidgetReadOnly() {
-        getWidget().setEnabled(isEnabled() && !isReadOnly());
+        getWidget().getListBox().setEnabled(isEnabled() && !isReadOnly());
     }
 
     @OnStateChange("selectedItemKey")
@@ -100,7 +102,7 @@ public class NativeSelectConnector
      * A data change handler registered to the data source. Updates the data
      * items and selection status when the data source notifies of new changes
      * from the server side.
-     * 
+     *
      * @param range
      *            the new range of data items
      */
@@ -110,7 +112,7 @@ public class NativeSelectConnector
                         + range;
 
         final VNativeSelect select = getWidget();
-        final int itemCount = select.getItemCount();
+        final int itemCount = select.getListBox().getItemCount();
 
         for (int i = range.getStart(); i < range.getEnd(); i++) {
 
@@ -118,17 +120,19 @@ public class NativeSelectConnector
 
             if (i < itemCount) {
                 // Reuse and update an existing item
-                select.setItemText(i, getRowData(row).asString());
-                select.setValue(i, getRowKey(row));
+                select.getListBox().setItemText(i, getRowData(row).asString());
+                select.getListBox().setValue(i, getRowKey(row));
             } else {
                 // Add new items if the new dataset is larger than the old
-                select.addItem(getRowData(row).asString(), getRowKey(row));
+                select.getListBox().addItem(getRowData(row).asString(),
+                        getRowKey(row));
             }
         }
 
-        for (int i = select.getItemCount() - 1; i >= range.getEnd(); i--) {
+        for (int i = select.getListBox().getItemCount() - 1; i >= range
+                .getEnd(); i--) {
             // Remove extra items if the new dataset is smaller than the old
-            select.removeItem(i);
+            select.getListBox().removeItem(i);
         }
         updateSelectedItem();
     }
index f5a6248bfbf632638250f2c21aac0240963f7faf..e4ff336e4d8eb32bd795fb0676b6c300daeaf5f2 100644 (file)
@@ -1,12 +1,12 @@
 /*
  * Copyright 2000-2016 Vaadin Ltd.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -29,7 +29,7 @@ public class NativeSelectState extends AbstractSingleSelectState {
     /**
      * The default primary style name for {@code NativeSelect}.
      */
-    public static final String STYLE_NAME = "v-nativeselect";
+    public static final String STYLE_NAME = "v-select";
 
     {
         primaryStyleName = STYLE_NAME;
index 289162ee275b39ced779019514fbee18508c4910..a183951a291cbf4bef9332e9ae41d480a2178c38 100644 (file)
@@ -31,12 +31,7 @@ public class NativeSelectElement extends AbstractSelectElement {
     @Override
     protected void init() {
         super.init();
-        // FIXME: Newer NativeSelect has different DOM structure.
-        if (getTagName().equals("select")) {
-            selectElement = new Select(this);
-        } else {
-            selectElement = new Select(findElement(By.tagName("select")));
-        }
+        selectElement = new Select(findElement(By.tagName("select")));
     }
 
     public List<TestBenchElement> getOptions() {