Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Backport of HasLabel interface to v14. #3768

Merged
merged 7 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vaadin.flow.component.checkbox;

import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.HasLabel;
import com.vaadin.flow.component.HasSize;

/**
Expand All @@ -30,7 +31,7 @@
* @author Vaadin Ltd
*/
public class Checkbox extends GeneratedVaadinCheckbox<Checkbox, Boolean>
implements HasSize {
implements HasSize, HasLabel {

/**
* Default constructor.
Expand Down Expand Up @@ -106,6 +107,7 @@ public Checkbox(String label,
*
* @return the current label text
*/
@Override
public String getLabel() {
return getElement().getText();
}
Expand All @@ -116,6 +118,7 @@ public String getLabel() {
* @param label
* the label text to set
*/
@Override
public void setLabel(String label) {
getElement().setText(label);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasHelper;
import com.vaadin.flow.component.HasLabel;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.component.ItemLabelGenerator;
Expand Down Expand Up @@ -56,7 +57,8 @@
public class CheckboxGroup<T>
extends GeneratedVaadinCheckboxGroup<CheckboxGroup<T>, Set<T>>
implements HasItemsAndComponents<T>, HasSize, HasValidation,
MultiSelect<CheckboxGroup<T>, T>, HasDataProvider<T>, HasHelper {
MultiSelect<CheckboxGroup<T>, T>, HasDataProvider<T>, HasHelper,
HasLabel {

private static final String VALUE = "value";

Expand Down Expand Up @@ -257,6 +259,12 @@ public ItemLabelGenerator<T> getItemLabelGenerator() {
return itemLabelGenerator;
}

/**
* Sets the label for the checkbox group.
*
* @param label
* value for the {@code label} property in the checkbox group
*/
@Override
public void setLabel(String label) {
super.setLabel(label);
Expand All @@ -267,6 +275,7 @@ public void setLabel(String label) {
*
* @return the {@code label} property of the checkbox group
*/
@Override
public String getLabel() {
return super.getLabelString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2000-2022 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
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow.component.checkbox.tests;

import org.junit.Assert;
import org.junit.Test;

import com.vaadin.flow.component.HasLabel;
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.checkbox.CheckboxGroup;

public class HasLabelTest {

@Test
public void checkbox() {
Checkbox c = new Checkbox();
Assert.assertTrue(c instanceof HasLabel);
}

@Test
public void checkboxGroup() {
CheckboxGroup<String> c = new CheckboxGroup<>();
Assert.assertTrue(c instanceof HasLabel);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ClientCallable;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.HasHelper;
import com.vaadin.flow.component.DetachEvent;
import com.vaadin.flow.component.HasHelper;
import com.vaadin.flow.component.HasLabel;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.component.ItemLabelGenerator;
Expand Down Expand Up @@ -91,7 +92,7 @@
@JsModule("./comboBoxConnector-es6.js")
public class ComboBox<T> extends GeneratedVaadinComboBox<ComboBox<T>, T>
implements HasSize, HasValidation, HasFilterableDataProvider<T, String>,
HasHelper {
HasHelper, HasLabel {

private static final String PROP_SELECTED_ITEM = "selectedItem";
private static final String PROP_VALUE = "value";
Expand Down Expand Up @@ -643,7 +644,8 @@ public void setDataProvider(ListDataProvider<T> listDataProvider) {
* size callback.
* <p>
* This method is a shorthand for making a {@link CallbackDataProvider} that
* handles a partial {@link com.vaadin.data.provider.Query Query} object.
* handles a partial {@link com.vaadin.flow.data.provider.Query Query}
* object.
* <p>
* Changing the combo box's data provider resets its current value to
* {@code null}.
Expand Down Expand Up @@ -952,6 +954,12 @@ public boolean isRequired() {
return isRequiredBoolean();
}

/**
* Sets the label for the combobox.
*
* @param label
* value for the {@code label} property in the combobox
*/
@Override
public void setLabel(String label) {
super.setLabel(label);
Expand All @@ -962,6 +970,7 @@ public void setLabel(String label) {
*
* @return the {@code label} property of the combobox
*/
@Override
public String getLabel() {
return getLabelString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2000-2022 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
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow.component.combobox;

import org.junit.Assert;
import org.junit.Test;

import com.vaadin.flow.component.HasLabel;

public class HasLabelTest {

@Test
public void comboBox() {
ComboBox c = new ComboBox();
Assert.assertTrue(c instanceof HasLabel);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@

import java.util.Objects;

import com.vaadin.flow.component.HasHelper;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import org.slf4j.LoggerFactory;

import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Focusable;
import com.vaadin.flow.component.HasHelper;
import com.vaadin.flow.component.HasLabel;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.Synchronize;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.HtmlImport;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.dom.Element;

/**
Expand All @@ -55,7 +56,8 @@
@JsModule("@vaadin/vaadin-custom-field/src/vaadin-custom-field.js")
@HtmlImport("frontend://bower_components/vaadin-custom-field/src/vaadin-custom-field.html")
public abstract class CustomField<T> extends AbstractField<CustomField<T>, T>
implements HasSize, HasValidation, Focusable<CustomField>, HasHelper {
implements HasSize, HasValidation, Focusable<CustomField>, HasHelper,
HasLabel {

/**
* Default constructor.
Expand Down Expand Up @@ -210,6 +212,7 @@ public String getErrorMessage() {
*
* @return the {@code label} property from the webcomponent
*/
@Override
public String getLabel() {
return getElement().getProperty("label", null);
}
Expand All @@ -220,6 +223,7 @@ public String getLabel() {
* @param label
* value for the {@code label} property in the webcomponent
*/
@Override
public void setLabel(String label) {
getElement().setProperty("label", label);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2000-2022 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
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow.component.customfield;

import org.junit.Assert;
import org.junit.Test;

import com.vaadin.flow.component.HasLabel;

public class HasLabelTest {

@Test
public void customField() {
CustomField<String> c = new CustomField<String>() {
@Override
protected String generateModelValue() {
return null;
}

@Override
protected void setPresentationValue(String newPresentationValue) {

}
};
Assert.assertTrue(c instanceof HasLabel);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
import java.io.Serializable;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.HasHelper;
import com.vaadin.flow.component.HasLabel;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.component.HasValue;
Expand Down Expand Up @@ -56,7 +57,7 @@
@JavaScript("frontend://date-picker-datefns.js")
@JavaScript("frontend://datepickerConnector.js")
public class DatePicker extends GeneratedVaadinDatePicker<DatePicker, LocalDate>
implements HasSize, HasValidation, HasHelper {
implements HasSize, HasValidation, HasHelper, HasLabel {

private static final String PROP_AUTO_OPEN_DISABLED = "autoOpenDisabled";

Expand Down Expand Up @@ -482,6 +483,12 @@ public boolean isClearButtonVisible() {
return super.isClearButtonVisibleBoolean();
}

/**
* Sets the label for the datepicker.
*
* @param label
* value for the {@code label} property in the datepicker
*/
@Override
public void setLabel(String label) {
super.setLabel(label);
Expand All @@ -492,6 +499,7 @@ public void setLabel(String label) {
*
* @return the {@code label} property of the datePicker
*/
@Override
public String getLabel() {
return getLabelString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2000-2022 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
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow.component.datepicker;

import org.junit.Assert;
import org.junit.Test;

import com.vaadin.flow.component.HasLabel;

public class HasLabelTest {

@Test
public void datePicker() {
DatePicker d = new DatePicker();
Assert.assertTrue(d instanceof HasLabel);
}

}
Loading