mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-01 18:57:39 +08:00
PL-7324 Add an ability to disable null option for components with lookup action
This commit is contained in:
parent
36f7848996
commit
682c373bff
@ -76,6 +76,8 @@ public class DesktopLookupField extends DesktopAbstractOptionsField<JComponent>
|
|||||||
protected String inputPrompt;
|
protected String inputPrompt;
|
||||||
protected boolean textInputAllowed = true;
|
protected boolean textInputAllowed = true;
|
||||||
|
|
||||||
|
protected boolean nullOptionVisible = true;
|
||||||
|
|
||||||
protected List<UserSelectionListener> userSelectionListeners = null; // lazy initialized list
|
protected List<UserSelectionListener> userSelectionListeners = null; // lazy initialized list
|
||||||
|
|
||||||
public DesktopLookupField() {
|
public DesktopLookupField() {
|
||||||
@ -300,7 +302,7 @@ public class DesktopLookupField extends DesktopAbstractOptionsField<JComponent>
|
|||||||
|
|
||||||
items.clear();
|
items.clear();
|
||||||
|
|
||||||
if (!isRequired() && nullOption == null) {
|
if (!isRequired() && nullOption == null && nullOptionVisible) {
|
||||||
items.add(new ObjectWrapper(null));
|
items.add(new ObjectWrapper(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,6 +416,16 @@ public class DesktopLookupField extends DesktopAbstractOptionsField<JComponent>
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNullOptionVisible(boolean nullOptionVisible) {
|
||||||
|
this.nullOptionVisible = nullOptionVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNullOptionVisible() {
|
||||||
|
return nullOptionVisible;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInputPrompt() {
|
public String getInputPrompt() {
|
||||||
return inputPrompt;
|
return inputPrompt;
|
||||||
|
@ -75,6 +75,8 @@ public class DesktopSearchField extends DesktopAbstractOptionsField<JComponent>
|
|||||||
|
|
||||||
protected int minSearchStringLength = 0;
|
protected int minSearchStringLength = 0;
|
||||||
|
|
||||||
|
protected boolean nullOptionVisible = true;
|
||||||
|
|
||||||
protected Frame.NotificationType defaultNotificationType = Frame.NotificationType.TRAY;
|
protected Frame.NotificationType defaultNotificationType = Frame.NotificationType.TRAY;
|
||||||
|
|
||||||
protected Color searchEditBgColor = (Color) UIManager.get("cubaSearchEditBackground");
|
protected Color searchEditBgColor = (Color) UIManager.get("cubaSearchEditBackground");
|
||||||
@ -450,6 +452,16 @@ public class DesktopSearchField extends DesktopAbstractOptionsField<JComponent>
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNullOptionVisible(boolean nullOptionVisible) {
|
||||||
|
this.nullOptionVisible = nullOptionVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNullOptionVisible() {
|
||||||
|
return nullOptionVisible;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInputPrompt() {
|
public String getInputPrompt() {
|
||||||
return inputPrompt;
|
return inputPrompt;
|
||||||
|
@ -90,6 +90,7 @@ public class DesktopSuggestionField extends DesktopAbstractOptionsField<JCompone
|
|||||||
|
|
||||||
protected String inputPrompt;
|
protected String inputPrompt;
|
||||||
protected String currentSearchComponentText;
|
protected String currentSearchComponentText;
|
||||||
|
protected boolean nullOptionVisible = true;
|
||||||
private ArrowDownActionHandler arrowDownActionHandler;
|
private ArrowDownActionHandler arrowDownActionHandler;
|
||||||
|
|
||||||
public DesktopSuggestionField() {
|
public DesktopSuggestionField() {
|
||||||
@ -532,6 +533,16 @@ public class DesktopSuggestionField extends DesktopAbstractOptionsField<JCompone
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNullOptionVisible(boolean nullOptionVisible) {
|
||||||
|
this.nullOptionVisible = nullOptionVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNullOptionVisible() {
|
||||||
|
return nullOptionVisible;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInputPrompt() {
|
public String getInputPrompt() {
|
||||||
return inputPrompt;
|
return inputPrompt;
|
||||||
|
@ -70,6 +70,15 @@ public interface LookupField extends OptionsField, Component.HasInputPrompt {
|
|||||||
*/
|
*/
|
||||||
void setPageLength(int pageLength);
|
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 {
|
enum FilterMode {
|
||||||
NO,
|
NO,
|
||||||
STARTS_WITH,
|
STARTS_WITH,
|
||||||
|
@ -777,6 +777,7 @@
|
|||||||
|
|
||||||
<xs:attribute name="newOptionAllowed" type="xs:boolean"/>
|
<xs:attribute name="newOptionAllowed" type="xs:boolean"/>
|
||||||
<xs:attribute name="textInputAllowed" 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="newOptionHandler" type="xs:string"/>
|
||||||
<xs:attribute name="inputPrompt" type="resourceString"/>
|
<xs:attribute name="inputPrompt" type="resourceString"/>
|
||||||
</xs:extension>
|
</xs:extension>
|
||||||
@ -832,6 +833,7 @@
|
|||||||
<xs:attributeGroup ref="hasOptions"/>
|
<xs:attributeGroup ref="hasOptions"/>
|
||||||
<xs:attributeGroup ref="hasCaptionSource"/>
|
<xs:attributeGroup ref="hasCaptionSource"/>
|
||||||
|
|
||||||
|
<xs:attribute name="nullOptionVisible" type="xs:boolean"/>
|
||||||
<xs:attribute name="filterMode" type="filterMode"/>
|
<xs:attribute name="filterMode" type="filterMode"/>
|
||||||
<xs:attribute name="nullName" type="resourceString"/>
|
<xs:attribute name="nullName" type="resourceString"/>
|
||||||
<xs:attribute name="metaClass" type="xs:string"/>
|
<xs:attribute name="metaClass" type="xs:string"/>
|
||||||
|
@ -64,6 +64,15 @@ public class LookupFieldLoader extends AbstractFieldLoader<LookupField> {
|
|||||||
|
|
||||||
loadFilterMode(resultComponent, element);
|
loadFilterMode(resultComponent, element);
|
||||||
loadNewOptionHandler(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() {
|
protected void loadTextInputAllowed() {
|
||||||
|
@ -60,6 +60,8 @@ public class WebLookupField extends WebAbstractOptionsField<CubaComboBox> implem
|
|||||||
|
|
||||||
protected Messages messages = AppBeans.get(Messages.NAME);
|
protected Messages messages = AppBeans.get(Messages.NAME);
|
||||||
|
|
||||||
|
protected boolean nullOptionVisible = true;
|
||||||
|
|
||||||
public WebLookupField() {
|
public WebLookupField() {
|
||||||
createComponent();
|
createComponent();
|
||||||
|
|
||||||
@ -175,7 +177,8 @@ public class WebLookupField extends WebAbstractOptionsField<CubaComboBox> implem
|
|||||||
@Override
|
@Override
|
||||||
public void setRequired(boolean required) {
|
public void setRequired(boolean required) {
|
||||||
super.setRequired(required);
|
super.setRequired(required);
|
||||||
component.setNullSelectionAllowed(!required);
|
|
||||||
|
component.setNullSelectionAllowed(!required && nullOptionVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -342,6 +345,17 @@ public class WebLookupField extends WebAbstractOptionsField<CubaComboBox> implem
|
|||||||
component.setPageLength(pageLength);
|
component.setPageLength(pageLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNullOptionVisible(boolean nullOptionVisible) {
|
||||||
|
this.nullOptionVisible = nullOptionVisible;
|
||||||
|
component.setNullSelectionAllowed(!isRequired() && nullOptionVisible);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNullOptionVisible() {
|
||||||
|
return nullOptionVisible;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInputPrompt() {
|
public String getInputPrompt() {
|
||||||
return component.getInputPrompt();
|
return component.getInputPrompt();
|
||||||
|
Loading…
Reference in New Issue
Block a user