PL-10109 Implement include attribute for BulkEditor

This commit is contained in:
Roman Pinyazhin 2018-01-16 18:11:45 +04:00
parent 7091253693
commit b0d5b2fe8c
7 changed files with 92 additions and 17 deletions

View File

@ -31,6 +31,7 @@ import java.util.Map;
public class DesktopBulkEditor extends DesktopButton implements BulkEditor { public class DesktopBulkEditor extends DesktopButton implements BulkEditor {
protected String exclude; protected String exclude;
protected List<String> includeProperties = Collections.emptyList();
protected WindowManager.OpenType openType = WindowManager.OpenType.DIALOG; protected WindowManager.OpenType openType = WindowManager.OpenType.DIALOG;
protected BulkEditAction bulkEditAction; protected BulkEditAction bulkEditAction;
protected ListComponent listComponent; 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 @Override
public ListComponent getListComponent() { public ListComponent getListComponent() {
return listComponent; return listComponent;
@ -97,6 +111,10 @@ public class DesktopBulkEditor extends DesktopButton implements BulkEditor {
bulkEditAction.setExcludePropertyRegex(exclude); bulkEditAction.setExcludePropertyRegex(exclude);
} }
if (includeProperties != null) {
bulkEditAction.setIncludeProperties(includeProperties);
}
if (fieldValidators != null) { if (fieldValidators != null) {
bulkEditAction.setFieldValidators(fieldValidators); bulkEditAction.setFieldValidators(fieldValidators);
} }

View File

@ -100,6 +100,9 @@ public class BulkEditorWindow extends AbstractWindow {
@WindowParam @WindowParam
protected String exclude; protected String exclude;
@WindowParam
protected List<String> includeProperties;
@WindowParam @WindowParam
protected boolean loadDynamicAttributes = true; protected boolean loadDynamicAttributes = true;
@ -465,6 +468,10 @@ public class BulkEditorWindow extends AbstractWindow {
return false; return false;
} }
if (includeProperties != null && !includeProperties.isEmpty()) {
return includeProperties.contains(metaProperty.getName());
}
return !(excludeRegex != null && excludeRegex.matcher(metaProperty.getName()).matches()); return !(excludeRegex != null && excludeRegex.matcher(metaProperty.getName()).matches());
} }

View File

@ -35,6 +35,19 @@ public interface BulkEditor extends Component, Component.HasCaption, Component.B
String getExcludePropertiesRegex(); String getExcludePropertiesRegex();
void setExcludePropertiesRegex(String excludeRegex); 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(); ListComponent getListComponent();
void setListComponent(ListComponent listComponent); void setListComponent(ListComponent listComponent);

View File

@ -29,8 +29,7 @@ import com.haulmont.cuba.gui.theme.ThemeConstantsManager;
import com.haulmont.cuba.security.entity.ConstraintOperationType; import com.haulmont.cuba.security.entity.ConstraintOperationType;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import java.util.List; import java.util.*;
import java.util.Map;
/** /**
* Action used in {@link BulkEditor} visual component. * 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 OpenType openType = OpenType.DIALOG;
protected String exclude; protected String exclude;
protected List<String> includeProperties = Collections.emptyList();
protected Map<String, Field.Validator> fieldValidators; protected Map<String, Field.Validator> fieldValidators;
protected List<Field.Validator> modelValidators; protected List<Field.Validator> modelValidators;
protected Boolean loadDynamicAttributes; protected Boolean loadDynamicAttributes;
@ -90,6 +90,14 @@ public class BulkEditAction extends ItemTrackingAction implements Action.HasBefo
this.exclude = exclude; this.exclude = exclude;
} }
public List<String> getIncludeProperties() {
return includeProperties;
}
public void setIncludeProperties(List<String> includeProperties) {
this.includeProperties = includeProperties;
}
public List<Field.Validator> getModelValidators() { public List<Field.Validator> getModelValidators() {
return modelValidators; return modelValidators;
} }
@ -142,14 +150,15 @@ public class BulkEditAction extends ItemTrackingAction implements Action.HasBefo
.setResizable(true); .setResizable(true);
} }
Map<String, Object> params = ParamsMap.of( Map<String, Object> params = ParamsMap.of()
"metaClass", target.getDatasource().getMetaClass(), .pair("metaClass", target.getDatasource().getMetaClass())
"selected", target.getSelected(), .pair("selected", target.getSelected())
"exclude", exclude, .pair("exclude", exclude)
"fieldValidators", fieldValidators, .pair("includeProperties", includeProperties != null ? includeProperties : Collections.EMPTY_LIST)
"modelValidators", modelValidators, .pair("fieldValidators", fieldValidators)
"loadDynamicAttributes", loadDynamicAttributes .pair("modelValidators", modelValidators)
); .pair("loadDynamicAttributes", loadDynamicAttributes)
.create();
Window bulkEditor = target.getFrame().openWindow("bulkEditor", openType, params); Window bulkEditor = target.getFrame().openWindow("bulkEditor", openType, params);
bulkEditor.addCloseListener(actionId -> { bulkEditor.addCloseListener(actionId -> {

View File

@ -2599,6 +2599,7 @@
<xs:attribute name="openType" type="openType"/> <xs:attribute name="openType" type="openType"/>
<xs:attribute name="for" type="xs:string" use="required"/> <xs:attribute name="for" type="xs:string" use="required"/>
<xs:attribute name="exclude" type="xs:string"/> <xs:attribute name="exclude" type="xs:string"/>
<xs:attribute name="includeProperties" type="xs:string"/>
<xs:attribute name="focusable" type="xs:boolean"/> <xs:attribute name="focusable" type="xs:boolean"/>
<xs:attribute name="loadDynamicAttributes" type="xs:boolean"/> <xs:attribute name="loadDynamicAttributes" type="xs:boolean"/>

View File

@ -17,6 +17,7 @@
package com.haulmont.cuba.gui.xml.layout.loaders; package com.haulmont.cuba.gui.xml.layout.loaders;
import com.google.common.base.Splitter;
import com.haulmont.bali.util.Dom4j; import com.haulmont.bali.util.Dom4j;
import com.haulmont.cuba.gui.GuiDevelopmentException; import com.haulmont.cuba.gui.GuiDevelopmentException;
import com.haulmont.cuba.gui.WindowManager; 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.apache.commons.lang.StringUtils;
import org.dom4j.Element; import org.dom4j.Element;
import java.util.ArrayList; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class BulkEditorLoader extends AbstractComponentLoader<BulkEditor> { public class BulkEditorLoader extends AbstractComponentLoader<BulkEditor> {
@ -97,10 +95,23 @@ public class BulkEditorLoader extends AbstractComponentLoader<BulkEditor> {
} }
String exclude = element.attributeValue("exclude"); 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)) { if (StringUtils.isNotBlank(exclude)) {
resultComponent.setExcludePropertiesRegex(exclude.replace(" ", "")); resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
} }
if (StringUtils.isNotBlank(includeProperties)) {
resultComponent.setIncludeProperties(
Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties)
);
}
String listComponent = element.attributeValue("for"); String listComponent = element.attributeValue("for");
if (StringUtils.isEmpty(listComponent)) { if (StringUtils.isEmpty(listComponent)) {
throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified", throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified",

View File

@ -24,13 +24,12 @@ import com.haulmont.cuba.gui.components.ListComponent;
import com.haulmont.cuba.gui.components.actions.BulkEditAction; import com.haulmont.cuba.gui.components.actions.BulkEditAction;
import com.haulmont.cuba.security.entity.ConstraintOperationType; import com.haulmont.cuba.security.entity.ConstraintOperationType;
import java.util.Collections; import java.util.*;
import java.util.List;
import java.util.Map;
public class WebBulkEditor extends WebButton implements BulkEditor { public class WebBulkEditor extends WebButton implements BulkEditor {
protected String exclude; protected String exclude;
protected List<String> includeProperties = Collections.emptyList();
protected WindowManager.OpenType openType = WindowManager.OpenType.DIALOG; protected WindowManager.OpenType openType = WindowManager.OpenType.DIALOG;
protected BulkEditAction bulkEditAction; protected BulkEditAction bulkEditAction;
protected ListComponent listComponent; 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 @Override
public ListComponent getListComponent() { public ListComponent getListComponent() {
return listComponent; return listComponent;
@ -93,6 +105,10 @@ public class WebBulkEditor extends WebButton implements BulkEditor {
bulkEditAction.setExcludePropertyRegex(exclude); bulkEditAction.setExcludePropertyRegex(exclude);
} }
if (includeProperties != null) {
bulkEditAction.setIncludeProperties(includeProperties);
}
if (fieldValidators != null) { if (fieldValidators != null) {
bulkEditAction.setFieldValidators(fieldValidators); bulkEditAction.setFieldValidators(fieldValidators);
} }