mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
support lookupField captionProperty
This commit is contained in:
parent
e5a5351af8
commit
787e0470ff
@ -13,5 +13,16 @@ import com.haulmont.cuba.gui.data.Datasource;
|
|||||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||||
|
|
||||||
public interface LookupField extends Field {
|
public interface LookupField extends Field {
|
||||||
|
enum CaptionMode {
|
||||||
|
ITEM,
|
||||||
|
PROPERTY
|
||||||
|
}
|
||||||
|
|
||||||
|
CaptionMode getCaptionMode();
|
||||||
|
void setCaptionMode(CaptionMode captionMode);
|
||||||
|
|
||||||
|
String getCaptionProperty();
|
||||||
|
void setCaptionProperty(String captionProperty);
|
||||||
|
|
||||||
void setLookupDatasource(CollectionDatasource datasource);
|
void setLookupDatasource(CollectionDatasource datasource);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
|||||||
|
|
||||||
import com.haulmont.cuba.gui.components.Field;
|
import com.haulmont.cuba.gui.components.Field;
|
||||||
import com.haulmont.cuba.gui.components.LookupField;
|
import com.haulmont.cuba.gui.components.LookupField;
|
||||||
|
import com.haulmont.cuba.gui.components.Component;
|
||||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||||
import com.haulmont.cuba.gui.data.Datasource;
|
import com.haulmont.cuba.gui.data.Datasource;
|
||||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||||
@ -23,6 +24,19 @@ public class LookupFieldLoader extends AbstractFieldLoader {
|
|||||||
super(context, config, factory);
|
super(context, config, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||||
|
final LookupField component = (LookupField) super.loadComponent(factory, element);
|
||||||
|
|
||||||
|
String captionProperty = element.attributeValue("captionProperty");
|
||||||
|
if (!StringUtils.isEmpty(captionProperty)) {
|
||||||
|
component.setCaptionMode(LookupField.CaptionMode.PROPERTY);
|
||||||
|
component.setCaptionProperty(captionProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadDatasource(Field component, Element element) {
|
protected void loadDatasource(Field component, Element element) {
|
||||||
final String datasource = element.attributeValue("lookupDatasource");
|
final String datasource = element.attributeValue("lookupDatasource");
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<label value="Group"/>
|
<label value="Group"/>
|
||||||
<lookupField id="group" datasource="user" property="group" lookupDatasource="groups"/>
|
<lookupField id="group" datasource="user" property="group" lookupDatasource="groups" captionProperty="name"/>
|
||||||
</row>
|
</row>
|
||||||
</rows>
|
</rows>
|
||||||
</grid>
|
</grid>
|
||||||
|
@ -27,6 +27,8 @@ public class LookupField
|
|||||||
implements
|
implements
|
||||||
com.haulmont.cuba.gui.components.LookupField, Component.Wrapper {
|
com.haulmont.cuba.gui.components.LookupField, Component.Wrapper {
|
||||||
private CollectionDatasource lookupDatasource;
|
private CollectionDatasource lookupDatasource;
|
||||||
|
private CaptionMode captionMode = CaptionMode.ITEM;
|
||||||
|
private String captionProperty;
|
||||||
|
|
||||||
public LookupField() {
|
public LookupField() {
|
||||||
this.component = new Select();
|
this.component = new Select();
|
||||||
@ -76,9 +78,45 @@ public class LookupField
|
|||||||
setRequired(metaProperty.isMandatory());
|
setRequired(metaProperty.isMandatory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CaptionMode getCaptionMode() {
|
||||||
|
return captionMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCaptionMode(CaptionMode captionMode) {
|
||||||
|
this.captionMode = captionMode;
|
||||||
|
switch (captionMode) {
|
||||||
|
case ITEM: {
|
||||||
|
component.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_ITEM);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROPERTY: {
|
||||||
|
component.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default :{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCaptionProperty() {
|
||||||
|
return captionProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCaptionProperty(String captionProperty) {
|
||||||
|
this.captionProperty = captionProperty;
|
||||||
|
if (lookupDatasource != null) {
|
||||||
|
component.setItemCaptionPropertyId(lookupDatasource.getMetaClass().getProperty(captionProperty));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setLookupDatasource(CollectionDatasource datasource) {
|
public void setLookupDatasource(CollectionDatasource datasource) {
|
||||||
lookupDatasource = datasource;
|
lookupDatasource = datasource;
|
||||||
component.setContainerDataSource(new CollectionDatasourceWrapper(datasource, true));
|
component.setContainerDataSource(new CollectionDatasourceWrapper(datasource, true));
|
||||||
|
|
||||||
|
if (captionProperty != null) {
|
||||||
|
component.setItemCaptionPropertyId(lookupDatasource.getMetaClass().getProperty(captionProperty));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user