diff options
author | Aleksi Hietanen <aleksi@vaadin.com> | 2016-10-07 09:41:33 +0300 |
---|---|---|
committer | Aleksi Hietanen <aleksi@vaadin.com> | 2016-10-07 15:19:22 +0000 |
commit | 0fa0160eb992ca68cf3bddffdfc838099c26e5f4 (patch) | |
tree | fbf1fd5f28f2b6838d85a2df8cd88398e46edfda | |
parent | cef3c7e5ec6156af9d4b9686047bc04c2c7b1c3f (diff) | |
download | vaadin-framework-0fa0160eb992ca68cf3bddffdfc838099c26e5f4.tar.gz vaadin-framework-0fa0160eb992ca68cf3bddffdfc838099c26e5f4.zip |
Revert NativeSelect DOM structure change8.0.0.alpha4
Change-Id: I11dcd769dd81a90b41cc74707ef8d6ef4ddc9be7
4 files changed, 49 insertions, 36 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java b/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java index 716450c82a..efbba52efc 100644 --- a/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java +++ b/client/src/main/java/com/vaadin/client/ui/VNativeSelect.java @@ -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; + } } diff --git a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java index ffda0166e3..93861b41dc 100644 --- a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java @@ -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(); } diff --git a/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java b/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java index f5a6248bfb..e4ff336e4d 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/nativeselect/NativeSelectState.java @@ -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; diff --git a/uitest-common/src/main/java/com/vaadin/testbench/customelements/NativeSelectElement.java b/uitest-common/src/main/java/com/vaadin/testbench/customelements/NativeSelectElement.java index 289162ee27..a183951a29 100644 --- a/uitest-common/src/main/java/com/vaadin/testbench/customelements/NativeSelectElement.java +++ b/uitest-common/src/main/java/com/vaadin/testbench/customelements/NativeSelectElement.java @@ -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() { |