PL-7324 Add an ability to disable null option for components with lookup action

This commit is contained in:
Nikita Petunin 2016-06-07 17:05:09 +04:00
parent 36f7848996
commit 682c373bff
7 changed files with 71 additions and 2 deletions

View File

@ -76,6 +76,8 @@ public class DesktopLookupField extends DesktopAbstractOptionsField<JComponent>
protected String inputPrompt;
protected boolean textInputAllowed = true;
protected boolean nullOptionVisible = true;
protected List<UserSelectionListener> userSelectionListeners = null; // lazy initialized list
public DesktopLookupField() {
@ -300,7 +302,7 @@ public class DesktopLookupField extends DesktopAbstractOptionsField<JComponent>
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<JComponent>
// do nothing
}
@Override
public void setNullOptionVisible(boolean nullOptionVisible) {
this.nullOptionVisible = nullOptionVisible;
}
@Override
public boolean isNullOptionVisible() {
return nullOptionVisible;
}
@Override
public String getInputPrompt() {
return inputPrompt;

View File

@ -75,6 +75,8 @@ public class DesktopSearchField extends DesktopAbstractOptionsField<JComponent>
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<JComponent>
// do nothing
}
@Override
public void setNullOptionVisible(boolean nullOptionVisible) {
this.nullOptionVisible = nullOptionVisible;
}
@Override
public boolean isNullOptionVisible() {
return nullOptionVisible;
}
@Override
public String getInputPrompt() {
return inputPrompt;

View File

@ -90,6 +90,7 @@ public class DesktopSuggestionField extends DesktopAbstractOptionsField<JCompone
protected String inputPrompt;
protected String currentSearchComponentText;
protected boolean nullOptionVisible = true;
private ArrowDownActionHandler arrowDownActionHandler;
public DesktopSuggestionField() {
@ -532,6 +533,16 @@ public class DesktopSuggestionField extends DesktopAbstractOptionsField<JCompone
// do nothing
}
@Override
public void setNullOptionVisible(boolean nullOptionVisible) {
this.nullOptionVisible = nullOptionVisible;
}
@Override
public boolean isNullOptionVisible() {
return nullOptionVisible;
}
@Override
public String getInputPrompt() {
return inputPrompt;

View File

@ -70,6 +70,15 @@ public interface LookupField extends OptionsField, Component.HasInputPrompt {
*/
void setPageLength(int pageLength);
/**
* Sets visibility for first null element in suggestion popup.
*/
void setNullOptionVisible(boolean nullOptionVisible);
/**
* @return true if first null element is visible.
*/
boolean isNullOptionVisible();
enum FilterMode {
NO,
STARTS_WITH,

View File

@ -777,6 +777,7 @@
<xs:attribute name="newOptionAllowed" type="xs:boolean"/>
<xs:attribute name="textInputAllowed" type="xs:boolean"/>
<xs:attribute name="nullOptionVisible" type="xs:boolean"/>
<xs:attribute name="newOptionHandler" type="xs:string"/>
<xs:attribute name="inputPrompt" type="resourceString"/>
</xs:extension>
@ -832,6 +833,7 @@
<xs:attributeGroup ref="hasOptions"/>
<xs:attributeGroup ref="hasCaptionSource"/>
<xs:attribute name="nullOptionVisible" type="xs:boolean"/>
<xs:attribute name="filterMode" type="filterMode"/>
<xs:attribute name="nullName" type="resourceString"/>
<xs:attribute name="metaClass" type="xs:string"/>

View File

@ -64,6 +64,15 @@ public class LookupFieldLoader extends AbstractFieldLoader<LookupField> {
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() {

View File

@ -60,6 +60,8 @@ public class WebLookupField extends WebAbstractOptionsField<CubaComboBox> implem
protected Messages messages = AppBeans.get(Messages.NAME);
protected boolean nullOptionVisible = true;
public WebLookupField() {
createComponent();
@ -175,7 +177,8 @@ public class WebLookupField extends WebAbstractOptionsField<CubaComboBox> 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<CubaComboBox> 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();