diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java index b15760ad20..51c176b649 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopLookupField.java @@ -76,6 +76,8 @@ public class DesktopLookupField extends DesktopAbstractOptionsField protected String inputPrompt; protected boolean textInputAllowed = true; + protected boolean nullOptionVisible = true; + protected List userSelectionListeners = null; // lazy initialized list public DesktopLookupField() { @@ -300,7 +302,7 @@ public class DesktopLookupField extends DesktopAbstractOptionsField items.clear(); - if (!isRequired() && nullOption == null) { + if (!isRequired() && nullOption == null && nullOptionVisible) { items.add(new ObjectWrapper(null)); } @@ -414,6 +416,16 @@ public class DesktopLookupField extends DesktopAbstractOptionsField // do nothing } + @Override + public void setNullOptionVisible(boolean nullOptionVisible) { + this.nullOptionVisible = nullOptionVisible; + } + + @Override + public boolean isNullOptionVisible() { + return nullOptionVisible; + } + @Override public String getInputPrompt() { return inputPrompt; diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java index f68362f6b6..1133e51665 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSearchField.java @@ -75,6 +75,8 @@ public class DesktopSearchField extends DesktopAbstractOptionsField protected int minSearchStringLength = 0; + protected boolean nullOptionVisible = true; + protected Frame.NotificationType defaultNotificationType = Frame.NotificationType.TRAY; protected Color searchEditBgColor = (Color) UIManager.get("cubaSearchEditBackground"); @@ -450,6 +452,16 @@ public class DesktopSearchField extends DesktopAbstractOptionsField // do nothing } + @Override + public void setNullOptionVisible(boolean nullOptionVisible) { + this.nullOptionVisible = nullOptionVisible; + } + + @Override + public boolean isNullOptionVisible() { + return nullOptionVisible; + } + @Override public String getInputPrompt() { return inputPrompt; diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionField.java index d4680146d9..93a1636b76 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopSuggestionField.java @@ -90,6 +90,7 @@ public class DesktopSuggestionField extends DesktopAbstractOptionsField + @@ -832,6 +833,7 @@ + diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java index e568436dad..909e96b055 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/LookupFieldLoader.java @@ -64,6 +64,15 @@ public class LookupFieldLoader extends AbstractFieldLoader { loadFilterMode(resultComponent, element); loadNewOptionHandler(resultComponent, element); + + loadNullOptionVisible(resultComponent, element); + } + + protected void loadNullOptionVisible(LookupField resultComponent, Element element) { + String nullOptionVisible = element.attributeValue("nullOptionVisible"); + if (StringUtils.isNotEmpty(nullOptionVisible)) { + resultComponent.setNullOptionVisible(Boolean.parseBoolean(nullOptionVisible)); + } } protected void loadTextInputAllowed() { diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java index 4694ce779f..ea9df5c4d2 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java @@ -60,6 +60,8 @@ public class WebLookupField extends WebAbstractOptionsField implem protected Messages messages = AppBeans.get(Messages.NAME); + protected boolean nullOptionVisible = true; + public WebLookupField() { createComponent(); @@ -175,7 +177,8 @@ public class WebLookupField extends WebAbstractOptionsField implem @Override public void setRequired(boolean required) { super.setRequired(required); - component.setNullSelectionAllowed(!required); + + component.setNullSelectionAllowed(!required && nullOptionVisible); } @Override @@ -342,6 +345,17 @@ public class WebLookupField extends WebAbstractOptionsField implem component.setPageLength(pageLength); } + @Override + public void setNullOptionVisible(boolean nullOptionVisible) { + this.nullOptionVisible = nullOptionVisible; + component.setNullSelectionAllowed(!isRequired() && nullOptionVisible); + } + + @Override + public boolean isNullOptionVisible() { + return nullOptionVisible; + } + @Override public String getInputPrompt() { return component.getInputPrompt();