Skip to content

Commit

Permalink
Merge pull request #2 from vaadin-component-factory/feature/selection…
Browse files Browse the repository at this point in the history
…buttonEnabled

Bump the version and add enable selection + focus
  • Loading branch information
jcgueriaud1 authored Apr 7, 2021
2 parents bf5db7c + 38dd4ee commit 61fd2d5
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lookup-field-flow-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>lookup-field-flow-demo</artifactId>
<version>1.0.6</version>
<version>1.1.0</version>

<name>Lookup Field Demo</name>
<packaging>war</packaging>
Expand Down Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>com.vaadin.componentfactory</groupId>
<artifactId>lookup-field-flow</artifactId>
<version>1.0.6</version>
<version>1.1.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.vaadin.componentfactory.lookupfield;

import com.vaadin.componentfactory.lookupfield.bean.Person;
import com.vaadin.componentfactory.lookupfield.service.PersonService;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteAlias;

import java.util.List;

/**
* Selection button enabled by default
*/
@Route(value = "enable-selection", layout = MainLayout.class)
public class EnableSelectButtonView extends Div {


public EnableSelectButtonView() {
LookupField<Person> lookupField = new LookupField<>(Person.class);
List<Person> items = getItems();
lookupField.setDataProvider(DataProvider.ofCollection(items));
lookupField.setGridWidth("900px");
lookupField.setHeader("Person Search");
lookupField.setSelectionDisabledIfEmpty(false);
add(lookupField);
}

private List<Person> getItems() {
PersonService personService = new PersonService();
return personService.fetchAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public MainLayout() {
final RouterLink i18nView = new RouterLink("I18n example", I18nView.class);
final RouterLink binderView = new RouterLink("Binder example", BinderView.class);
final RouterLink customHeader = new RouterLink("Custom Header", CustomHeaderView.class);
final VerticalLayout menuLayout = new VerticalLayout(personLookupField, simple, personLabelLookupField, i18nView, binderView, customHeader);
final RouterLink enableSelectButtonView = new RouterLink("Selection Button enabled", EnableSelectButtonView.class);
final VerticalLayout menuLayout = new VerticalLayout(personLookupField, simple, personLabelLookupField, i18nView,
binderView, customHeader, enableSelectButtonView);
addToDrawer(menuLayout);
addToNavbar(drawerToggle);
}
Expand Down
4 changes: 2 additions & 2 deletions lookup-field-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>lookup-field-flow</artifactId>
<version>1.0.6</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>Lookup Field</name>
Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-dialog</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.HasFilterableDataProvider;
import com.vaadin.flow.data.provider.ConfigurableFilterDataProvider;
Expand Down Expand Up @@ -74,7 +75,7 @@
@Uses(value = EnhancedDialog.class)
@Tag("vcf-lookup-field")
@JsModule("@vaadin-component-factory/vcf-lookup-field")
@NpmPackage(value = "@vaadin-component-factory/vcf-lookup-field", version = "1.0.8")
@NpmPackage(value = "@vaadin-component-factory/vcf-lookup-field", version = "1.1.1")
public class LookupField<T> extends Div implements HasFilterableDataProvider<T, String>,
HasValueAndElement<AbstractField.ComponentValueChangeEvent<LookupField<T>, T>, T>, HasValidation, HasHelper, HasSize, HasTheme {

Expand All @@ -90,6 +91,7 @@ public class LookupField<T> extends Div implements HasFilterableDataProvider<T,
private ConfigurableFilterDataProvider<T, Void, String> gridDataProvider;
private Component header;
private Component footer;
private Runnable notificationWhenEmptySelection;

public LookupField() {
this(new Grid<>(), new ComboBox<>());
Expand Down Expand Up @@ -379,6 +381,28 @@ public boolean isResizable() {
return getElement().getProperty("resizable", false);
}

/**
* Sets whether the select button is disabled or send an error when the selection is empty or not.
*
* @param defaultselectdisabled
* {@code true} to disabled the button if no item is disabled,
* {@code false} otherwise.
*/
public void setSelectionDisabledIfEmpty(boolean defaultselectdisabled) {
getElement().setProperty("defaultselectdisabled", defaultselectdisabled);
}

/**
* Gets whether the select button is disabled or send an error when the selection is empty or not.
*
* @return
* {@code true} if resizing is enabled,
* {@code false} otherwiser (default).
*/
public boolean getSelectionDisabledIfEmpty() {
return getElement().getProperty("defaultselectdisabled", true);
}

/**
* Gets the internationalization object previously set for this component.
* <p>
Expand Down Expand Up @@ -548,6 +572,32 @@ public void footerCloseAction() {
getElement().executeJs("$0.__close()", getElement());
}

/**
* Copy the selected value of the field into the grid
*/
@ClientCallable
private void openErrorNotification() {
getNotificationWhenEmptySelection().run();
}

private Runnable getNotificationWhenEmptySelection() {
if (notificationWhenEmptySelection == null) {
return () -> {
String emptySelection = (getI18n() == null)? "Please select an item.":getI18n().getEmptyselection();
new Notification(emptySelection, 2000, Notification.Position.TOP_CENTER).open();
};
}
return notificationWhenEmptySelection;
}

/**
* Replace the default notification to an action
*
* @param notificationWhenEmptySelection action to run when the selection is empty and the select button is clicked
*/
public void addEmptySelectionListener(Runnable notificationWhenEmptySelection) {
this.notificationWhenEmptySelection = notificationWhenEmptySelection;
}

/**
* The internationalization properties for {@link LookupField}.
Expand All @@ -559,6 +609,7 @@ public static class LookupFieldI18n implements Serializable {
private String headerprefix;
private String headerpostfix;
private String search;
private String emptyselection;

public String getSearch() {
return search;
Expand Down Expand Up @@ -613,5 +664,14 @@ public LookupFieldI18n setHeaderpostfix(String headerpostfix) {
this.headerpostfix = headerpostfix;
return this;
}

public String getEmptyselection() {
return emptyselection;
}

public LookupFieldI18n setEmptyselection(String emptyselection) {
this.emptyselection = emptyselection;
return this;
}
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>lookup-field-flow-root</artifactId>
<version>1.0.6</version>
<version>1.1.0</version>
<packaging>pom</packaging>
<modules>
<module>lookup-field-flow</module>
Expand All @@ -18,7 +18,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<lookup-field-flow.version>1.0.6</lookup-field-flow.version>
<lookup-field-flow.version>1.1.0</lookup-field-flow.version>
</properties>
<inceptionYear>2020</inceptionYear>

Expand Down

0 comments on commit 61fd2d5

Please sign in to comment.