mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
PL-10109 Implement include attribute for BulkEditor
This commit is contained in:
parent
7091253693
commit
b0d5b2fe8c
@ -31,6 +31,7 @@ import java.util.Map;
|
||||
public class DesktopBulkEditor extends DesktopButton implements BulkEditor {
|
||||
|
||||
protected String exclude;
|
||||
protected List<String> includeProperties = Collections.emptyList();
|
||||
protected WindowManager.OpenType openType = WindowManager.OpenType.DIALOG;
|
||||
protected BulkEditAction bulkEditAction;
|
||||
protected ListComponent listComponent;
|
||||
@ -69,6 +70,19 @@ public class DesktopBulkEditor extends DesktopButton implements BulkEditor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getIncludeProperties() {
|
||||
return includeProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIncludeProperties(List<String> includeProperties) {
|
||||
this.includeProperties = includeProperties;
|
||||
if (bulkEditAction != null) {
|
||||
bulkEditAction.setIncludeProperties(includeProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListComponent getListComponent() {
|
||||
return listComponent;
|
||||
@ -97,6 +111,10 @@ public class DesktopBulkEditor extends DesktopButton implements BulkEditor {
|
||||
bulkEditAction.setExcludePropertyRegex(exclude);
|
||||
}
|
||||
|
||||
if (includeProperties != null) {
|
||||
bulkEditAction.setIncludeProperties(includeProperties);
|
||||
}
|
||||
|
||||
if (fieldValidators != null) {
|
||||
bulkEditAction.setFieldValidators(fieldValidators);
|
||||
}
|
||||
|
@ -100,6 +100,9 @@ public class BulkEditorWindow extends AbstractWindow {
|
||||
@WindowParam
|
||||
protected String exclude;
|
||||
|
||||
@WindowParam
|
||||
protected List<String> includeProperties;
|
||||
|
||||
@WindowParam
|
||||
protected boolean loadDynamicAttributes = true;
|
||||
|
||||
@ -465,6 +468,10 @@ public class BulkEditorWindow extends AbstractWindow {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (includeProperties != null && !includeProperties.isEmpty()) {
|
||||
return includeProperties.contains(metaProperty.getName());
|
||||
}
|
||||
|
||||
return !(excludeRegex != null && excludeRegex.matcher(metaProperty.getName()).matches());
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,19 @@ public interface BulkEditor extends Component, Component.HasCaption, Component.B
|
||||
String getExcludePropertiesRegex();
|
||||
void setExcludePropertiesRegex(String excludeRegex);
|
||||
|
||||
/**
|
||||
* @return list of entity's attributes
|
||||
*/
|
||||
List<String> getIncludeProperties();
|
||||
|
||||
/**
|
||||
* Sets entity's attributes to the bulk editor dialog.
|
||||
* Unspecified attributes will are not shown.
|
||||
*
|
||||
* @param includeProperties list of entity's attributes
|
||||
*/
|
||||
void setIncludeProperties(List<String> includeProperties);
|
||||
|
||||
ListComponent getListComponent();
|
||||
void setListComponent(ListComponent listComponent);
|
||||
|
||||
|
@ -29,8 +29,7 @@ import com.haulmont.cuba.gui.theme.ThemeConstantsManager;
|
||||
import com.haulmont.cuba.security.entity.ConstraintOperationType;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Action used in {@link BulkEditor} visual component.
|
||||
@ -47,6 +46,7 @@ public class BulkEditAction extends ItemTrackingAction implements Action.HasBefo
|
||||
|
||||
protected OpenType openType = OpenType.DIALOG;
|
||||
protected String exclude;
|
||||
protected List<String> includeProperties = Collections.emptyList();
|
||||
protected Map<String, Field.Validator> fieldValidators;
|
||||
protected List<Field.Validator> modelValidators;
|
||||
protected Boolean loadDynamicAttributes;
|
||||
@ -90,6 +90,14 @@ public class BulkEditAction extends ItemTrackingAction implements Action.HasBefo
|
||||
this.exclude = exclude;
|
||||
}
|
||||
|
||||
public List<String> getIncludeProperties() {
|
||||
return includeProperties;
|
||||
}
|
||||
|
||||
public void setIncludeProperties(List<String> includeProperties) {
|
||||
this.includeProperties = includeProperties;
|
||||
}
|
||||
|
||||
public List<Field.Validator> getModelValidators() {
|
||||
return modelValidators;
|
||||
}
|
||||
@ -142,14 +150,15 @@ public class BulkEditAction extends ItemTrackingAction implements Action.HasBefo
|
||||
.setResizable(true);
|
||||
}
|
||||
|
||||
Map<String, Object> params = ParamsMap.of(
|
||||
"metaClass", target.getDatasource().getMetaClass(),
|
||||
"selected", target.getSelected(),
|
||||
"exclude", exclude,
|
||||
"fieldValidators", fieldValidators,
|
||||
"modelValidators", modelValidators,
|
||||
"loadDynamicAttributes", loadDynamicAttributes
|
||||
);
|
||||
Map<String, Object> params = ParamsMap.of()
|
||||
.pair("metaClass", target.getDatasource().getMetaClass())
|
||||
.pair("selected", target.getSelected())
|
||||
.pair("exclude", exclude)
|
||||
.pair("includeProperties", includeProperties != null ? includeProperties : Collections.EMPTY_LIST)
|
||||
.pair("fieldValidators", fieldValidators)
|
||||
.pair("modelValidators", modelValidators)
|
||||
.pair("loadDynamicAttributes", loadDynamicAttributes)
|
||||
.create();
|
||||
|
||||
Window bulkEditor = target.getFrame().openWindow("bulkEditor", openType, params);
|
||||
bulkEditor.addCloseListener(actionId -> {
|
||||
|
@ -2599,6 +2599,7 @@
|
||||
<xs:attribute name="openType" type="openType"/>
|
||||
<xs:attribute name="for" type="xs:string" use="required"/>
|
||||
<xs:attribute name="exclude" type="xs:string"/>
|
||||
<xs:attribute name="includeProperties" type="xs:string"/>
|
||||
<xs:attribute name="focusable" type="xs:boolean"/>
|
||||
<xs:attribute name="loadDynamicAttributes" type="xs:boolean"/>
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.haulmont.bali.util.Dom4j;
|
||||
import com.haulmont.cuba.gui.GuiDevelopmentException;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
@ -27,10 +28,7 @@ import com.haulmont.cuba.gui.components.ListComponent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class BulkEditorLoader extends AbstractComponentLoader<BulkEditor> {
|
||||
|
||||
@ -97,10 +95,23 @@ public class BulkEditorLoader extends AbstractComponentLoader<BulkEditor> {
|
||||
}
|
||||
|
||||
String exclude = element.attributeValue("exclude");
|
||||
String includeProperties = element.attributeValue("includeProperties");
|
||||
|
||||
if (StringUtils.isNotBlank(exclude) && StringUtils.isNotBlank(includeProperties)) {
|
||||
throw new GuiDevelopmentException("BulkEditor cannot define simultaneously exclude and includeProperties attributes",
|
||||
getContext().getCurrentFrameId());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(exclude)) {
|
||||
resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(includeProperties)) {
|
||||
resultComponent.setIncludeProperties(
|
||||
Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties)
|
||||
);
|
||||
}
|
||||
|
||||
String listComponent = element.attributeValue("for");
|
||||
if (StringUtils.isEmpty(listComponent)) {
|
||||
throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified",
|
||||
|
@ -24,13 +24,12 @@ import com.haulmont.cuba.gui.components.ListComponent;
|
||||
import com.haulmont.cuba.gui.components.actions.BulkEditAction;
|
||||
import com.haulmont.cuba.security.entity.ConstraintOperationType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class WebBulkEditor extends WebButton implements BulkEditor {
|
||||
|
||||
protected String exclude;
|
||||
protected List<String> includeProperties = Collections.emptyList();
|
||||
protected WindowManager.OpenType openType = WindowManager.OpenType.DIALOG;
|
||||
protected BulkEditAction bulkEditAction;
|
||||
protected ListComponent listComponent;
|
||||
@ -65,6 +64,19 @@ public class WebBulkEditor extends WebButton implements BulkEditor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getIncludeProperties() {
|
||||
return includeProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIncludeProperties(List<String> includeProperties) {
|
||||
this.includeProperties = includeProperties;
|
||||
if (bulkEditAction != null) {
|
||||
bulkEditAction.setIncludeProperties(includeProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListComponent getListComponent() {
|
||||
return listComponent;
|
||||
@ -93,6 +105,10 @@ public class WebBulkEditor extends WebButton implements BulkEditor {
|
||||
bulkEditAction.setExcludePropertyRegex(exclude);
|
||||
}
|
||||
|
||||
if (includeProperties != null) {
|
||||
bulkEditAction.setIncludeProperties(includeProperties);
|
||||
}
|
||||
|
||||
if (fieldValidators != null) {
|
||||
bulkEditAction.setFieldValidators(fieldValidators);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user