Skip to content

Commit

Permalink
Eliminated redundant code in the new widget classes. ModelSingleForm …
Browse files Browse the repository at this point in the history
…and ModelGrid are effectively light-weight "decorators" for the ModelForm abstract class. ModelForm still retains code for all form types (single and list) - because any attempt to separate the functionality will result in an avalanche of code modifications.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1654683 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
adrian-crum committed Jan 25, 2015
1 parent 61f8142 commit 241aefe
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 1,298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import org.ofbiz.base.util.UtilURL;
import org.ofbiz.widget.artifact.ArtifactInfoContext;
import org.ofbiz.widget.artifact.ArtifactInfoGatherer;
import org.ofbiz.widget.model.*;
import org.ofbiz.widget.model.ModelForm;
import org.ofbiz.widget.model.ModelGrid;
import org.ofbiz.widget.model.ModelSingleForm;
import org.xml.sax.SAXException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@
import org.ofbiz.widget.model.AbstractModelAction.Script;
import org.ofbiz.widget.model.AbstractModelAction.Service;
import org.ofbiz.widget.model.AbstractModelAction.SetField;
import org.ofbiz.widget.model.*;
import org.ofbiz.widget.model.FieldInfo;
import org.ofbiz.widget.model.HtmlWidget;
import org.ofbiz.widget.model.HtmlWidget.HtmlTemplate;
import org.ofbiz.widget.model.HtmlWidget.HtmlTemplateDecorator;
import org.ofbiz.widget.model.HtmlWidget.HtmlTemplateDecoratorSection;
import org.ofbiz.widget.model.IterateSectionWidget;
import org.ofbiz.widget.model.ModelAction;
import org.ofbiz.widget.model.ModelActionVisitor;
import org.ofbiz.widget.model.ModelFieldVisitor;
import org.ofbiz.widget.model.ModelForm;
import org.ofbiz.widget.model.ModelForm.AltTarget;
import org.ofbiz.widget.model.ModelForm.AutoFieldsEntity;
import org.ofbiz.widget.model.ModelForm.AutoFieldsService;
import org.ofbiz.widget.model.ModelFormAction;
import org.ofbiz.widget.model.ModelFormAction.CallParentActions;
import org.ofbiz.widget.model.ModelFormField;
import org.ofbiz.widget.model.ModelFormField.CheckField;
import org.ofbiz.widget.model.ModelFormField.ContainerField;
import org.ofbiz.widget.model.ModelFormField.DateFindField;
Expand All @@ -63,6 +71,12 @@
import org.ofbiz.widget.model.ModelFormField.TextField;
import org.ofbiz.widget.model.ModelFormField.TextFindField;
import org.ofbiz.widget.model.ModelFormField.TextareaField;
import org.ofbiz.widget.model.ModelGrid;
import org.ofbiz.widget.model.ModelMenu;
import org.ofbiz.widget.model.ModelMenuAction;
import org.ofbiz.widget.model.ModelMenuItem;
import org.ofbiz.widget.model.ModelScreen;
import org.ofbiz.widget.model.ModelScreenWidget;
import org.ofbiz.widget.model.ModelScreenWidget.Column;
import org.ofbiz.widget.model.ModelScreenWidget.ColumnContainer;
import org.ofbiz.widget.model.ModelScreenWidget.Container;
Expand All @@ -83,8 +97,12 @@
import org.ofbiz.widget.model.ModelScreenWidget.Screenlet;
import org.ofbiz.widget.model.ModelScreenWidget.Section;
import org.ofbiz.widget.model.ModelScreenWidget.Tree;
import org.ofbiz.widget.model.ModelSingleForm;
import org.ofbiz.widget.model.ModelTree;
import org.ofbiz.widget.model.ModelTree.ModelNode;
import org.ofbiz.widget.model.ModelTree.ModelNode.ModelSubNode;
import org.ofbiz.widget.model.ModelTreeAction;
import org.ofbiz.widget.model.ModelWidgetVisitor;

/**
* An object that gathers artifact information from screen widgets.
Expand Down Expand Up @@ -225,86 +243,12 @@ public void visit(Menu menu) throws Exception {

@Override
public void visit(ModelSingleForm modelForm) throws Exception {
if (modelForm.getActions() != null) {
for (ModelAction action : modelForm.getActions()) {
action.accept(this);
}
}
if (modelForm.getRowActions() != null) {
for (ModelAction action : modelForm.getRowActions()) {
action.accept(this);
}
}
for (AutoFieldsEntity autoFieldsEntity : modelForm.getAutoFieldsEntities()) {
infoContext.addEntityName(autoFieldsEntity.entityName);
}
for (AutoFieldsService autoFieldsService : modelForm.getAutoFieldsServices()) {
infoContext.addServiceName(autoFieldsService.serviceName);
}
if (modelForm.getAltTargets() != null) {
for (AltTarget altTarget : modelForm.getAltTargets()) {
String target = altTarget.targetExdr.getOriginal();
String urlMode = "intra-app";
try {
Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target,
urlMode);
if (controllerLocAndRequestSet != null) {
for (String requestLocation : controllerLocAndRequestSet) {
infoContext.addTargetLocation(requestLocation);
}
}
} catch (GeneralException e) {
throw new RuntimeException(e);
}
}
}
if (!modelForm.getTarget().isEmpty()) {
String target = modelForm.getTarget();
String urlMode = UtilValidate.isNotEmpty(modelForm.getTargetType()) ? modelForm.getTargetType() : "intra-app";
if (target.indexOf("${") < 0) {
try {
Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target,
urlMode);
if (controllerLocAndRequestSet != null) {
for (String requestLocation : controllerLocAndRequestSet) {
infoContext.addTargetLocation(requestLocation);
}
}
} catch (GeneralException e) {
throw new RuntimeException(e);
}
}
}
FieldInfoGatherer fieldInfoGatherer = new FieldInfoGatherer();
for (ModelFormField modelFormField : modelForm.getFieldList()) {
if (UtilValidate.isNotEmpty(modelFormField.getEntityName())) {
infoContext.addEntityName(modelFormField.getEntityName());
}
if (modelFormField.getFieldInfo() instanceof ModelFormField.DisplayEntityField) {
infoContext.addEntityName(((ModelFormField.DisplayEntityField) modelFormField.getFieldInfo()).getEntityName());
}
if (modelFormField.getFieldInfo() instanceof FieldInfoWithOptions) {
for (ModelFormField.OptionSource optionSource : ((FieldInfoWithOptions) modelFormField
.getFieldInfo()).getOptionSources()) {
if (optionSource instanceof ModelFormField.EntityOptions) {
infoContext.addEntityName(((ModelFormField.EntityOptions) optionSource).getEntityName());
}
}
}
if (UtilValidate.isNotEmpty(modelFormField.getServiceName())) {
infoContext.addServiceName(modelFormField.getServiceName());
}
FieldInfo fieldInfo = modelFormField.getFieldInfo();
if (fieldInfo != null) {
fieldInfo.accept(fieldInfoGatherer);
}
}
visitModelForm(modelForm);
}

@Override
public void visit(ModelGrid modelGrid) throws Exception {
// TODO: Finish implementation

visitModelForm(modelGrid);
}

@Override
Expand Down Expand Up @@ -557,4 +501,81 @@ public void visit(TextField textField) {
public void visit(TextFindField textField) {
}
}

public void visitModelForm(ModelForm modelForm) throws Exception {
if (modelForm.getActions() != null) {
for (ModelAction action : modelForm.getActions()) {
action.accept(this);
}
}
if (modelForm.getRowActions() != null) {
for (ModelAction action : modelForm.getRowActions()) {
action.accept(this);
}
}
for (AutoFieldsEntity autoFieldsEntity : modelForm.getAutoFieldsEntities()) {
infoContext.addEntityName(autoFieldsEntity.entityName);
}
for (AutoFieldsService autoFieldsService : modelForm.getAutoFieldsServices()) {
infoContext.addServiceName(autoFieldsService.serviceName);
}
if (modelForm.getAltTargets() != null) {
for (AltTarget altTarget : modelForm.getAltTargets()) {
String target = altTarget.targetExdr.getOriginal();
String urlMode = "intra-app";
try {
Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target,
urlMode);
if (controllerLocAndRequestSet != null) {
for (String requestLocation : controllerLocAndRequestSet) {
infoContext.addTargetLocation(requestLocation);
}
}
} catch (GeneralException e) {
throw new RuntimeException(e);
}
}
}
if (!modelForm.getTarget().isEmpty()) {
String target = modelForm.getTarget();
String urlMode = UtilValidate.isNotEmpty(modelForm.getTargetType()) ? modelForm.getTargetType() : "intra-app";
if (target.indexOf("${") < 0) {
try {
Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target,
urlMode);
if (controllerLocAndRequestSet != null) {
for (String requestLocation : controllerLocAndRequestSet) {
infoContext.addTargetLocation(requestLocation);
}
}
} catch (GeneralException e) {
throw new RuntimeException(e);
}
}
}
FieldInfoGatherer fieldInfoGatherer = new FieldInfoGatherer();
for (ModelFormField modelFormField : modelForm.getFieldList()) {
if (UtilValidate.isNotEmpty(modelFormField.getEntityName())) {
infoContext.addEntityName(modelFormField.getEntityName());
}
if (modelFormField.getFieldInfo() instanceof ModelFormField.DisplayEntityField) {
infoContext.addEntityName(((ModelFormField.DisplayEntityField) modelFormField.getFieldInfo()).getEntityName());
}
if (modelFormField.getFieldInfo() instanceof FieldInfoWithOptions) {
for (ModelFormField.OptionSource optionSource : ((FieldInfoWithOptions) modelFormField
.getFieldInfo()).getOptionSources()) {
if (optionSource instanceof ModelFormField.EntityOptions) {
infoContext.addEntityName(((ModelFormField.EntityOptions) optionSource).getEntityName());
}
}
}
if (UtilValidate.isNotEmpty(modelFormField.getServiceName())) {
infoContext.addServiceName(modelFormField.getServiceName());
}
FieldInfo fieldInfo = modelFormField.getFieldInfo();
if (fieldInfo != null) {
fieldInfo.accept(fieldInfoGatherer);
}
}
}
}
2 changes: 1 addition & 1 deletion framework/widget/src/org/ofbiz/widget/model/ModelForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import bsh.Interpreter;

/**
* Models the &lt;form&gt; element.
* Abstract base class for the &lt;form&gt; and &lt;grid&gt; elements.
*
* @see <code>widget-form.xsd</code>
*/
Expand Down
Loading

0 comments on commit 241aefe

Please sign in to comment.