Skip to content

Commit

Permalink
EUU-117
Browse files Browse the repository at this point in the history
  • Loading branch information
seed-master committed Aug 14, 2022
1 parent 1d3211b commit fabc2af
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 58 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/seed/core/form/AbstractFormAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;

import org.seed.Seed;
import org.seed.core.application.AbstractOrderedTransferableObject;
import org.seed.core.entity.EntityFunction;
import org.seed.core.util.NameUtils;

@MappedSuperclass
public abstract class AbstractFormAction extends AbstractOrderedTransferableObject {
Expand Down Expand Up @@ -78,6 +80,11 @@ public void setType(FormActionType type) {
this.type = type;
}

public String getTestClass() {
return NameUtils.getInternalName(Seed.getLabel("button." + type.name().toLowerCase()))
.replace('_','-').toLowerCase() + "-button";
}

public boolean isCustom() {
return type == FormActionType.CUSTOM;
}
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/org/seed/core/form/layout/AutolayoutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.seed.core.form.layout;

import static org.seed.core.form.layout.LayoutElementAttributes.*;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -32,6 +34,7 @@
import org.seed.core.form.Form;
import org.seed.core.form.SubForm;
import org.seed.core.util.Assert;
import org.seed.core.util.NameUtils;

class AutolayoutBuilder extends LayoutUtils {

Expand Down Expand Up @@ -112,9 +115,9 @@ private LayoutElement buildSubForms(LayoutElement elemMainGrid) {
elemLayout.addChild(createBorderLayoutArea(BorderLayoutArea.NORTH)).addChild(elemMainGrid);
// tabs
final LayoutElement elemTabbox = new LayoutElement(LayoutElement.TABBOX);
elemTabbox.setAttribute(LayoutElementAttributes.A_HFLEX, LayoutElementAttributes.V_1);
elemTabbox.setAttribute(LayoutElementAttributes.A_VFLEX, LayoutElementAttributes.V_1);
elemTabbox.setClass(LayoutElementClass.TABBOX);
elemTabbox.setAttribute(A_HFLEX, V_1)
.setAttribute(A_VFLEX, V_1)
.setClass(LayoutElementClass.TABBOX);
elemLayout.addChild(createBorderLayoutArea(BorderLayoutArea.CENTER)).addChild(elemTabbox);
final LayoutElement elemTabs = elemTabbox.addChild(createTabs());
final LayoutElement elemPanels = elemTabbox.addChild(createTabpanels());
Expand All @@ -141,14 +144,14 @@ private LayoutElement createSingleColumnLayout(int numFieldGroups) {
// fields without group
if (!fieldsWithoutGroup.isEmpty()) {
grid.getGridCell(0, row++)
.setValign(LayoutElementAttributes.V_TOP)
.setValign(V_TOP)
.addChild(buildFieldGrid(fieldsWithoutGroup, entity.getName()));
}
// field groups
if (!fieldGroups.isEmpty()) {
for (EntityFieldGroup fieldGroup : fieldGroups) {
grid.getGridCell(0, row++)
.setValign(LayoutElementAttributes.V_TOP)
.setValign(V_TOP)
.addChild(buildFieldGrid(entity.getAllFieldsByGroup(fieldGroup),
fieldGroup.getName()));
}
Expand All @@ -164,14 +167,14 @@ private LayoutElement createHorizontalLayout(int columns, int numFieldGroups) {
// fields without group
if (!fieldsWithoutGroup.isEmpty()) {
grid.getGridCell(col++, 0)
.setValign(LayoutElementAttributes.V_TOP)
.setValign(V_TOP)
.addChild(buildFieldGrid(fieldsWithoutGroup, entity.getName()));
}
// field groups
if (!fieldGroups.isEmpty()) {
for (EntityFieldGroup fieldGroup : fieldGroups) {
grid.getGridCell(col, row)
.setValign(LayoutElementAttributes.V_TOP)
.setValign(V_TOP)
.addChild(buildFieldGrid(entity.getAllFieldsByGroup(fieldGroup),
fieldGroup.getName()));
if (++col == columns) {
Expand All @@ -193,18 +196,18 @@ private LayoutElement createVerticalLayout(int columns, int numFieldGroups) {
for (int col = 0; col < columns; col++) {
final LayoutElement colGrid = createGrid(1, numColumnGroups, null);
mainGrid.getGridCell(col, 0)
.setValign(LayoutElementAttributes.V_TOP)
.setValign(V_TOP)
.addChild(colGrid);
int row = 0;
if (col == 0 && !fieldsWithoutGroup.isEmpty()) {
colGrid.getGridCell(0, row++)
.setValign(LayoutElementAttributes.V_TOP)
.setValign(V_TOP)
.addChild(buildFieldGrid(fieldsWithoutGroup, entity.getName()));
}
while (idx < fieldGroups.size() && row < numColumnGroups) {
final EntityFieldGroup fieldGroup = fieldGroups.get(idx);
colGrid.getGridCell(0, row++)
.setValign(LayoutElementAttributes.V_TOP)
.setValign(V_TOP)
.addChild(buildFieldGrid(entity.getAllFieldsByGroup(fieldGroup),
fieldGroup.getName()));
idx++;
Expand All @@ -220,21 +223,25 @@ private static LayoutElement buildFieldGrid(List<EntityField> fields, String nam
final LayoutElement elemGrid = new LayoutElement(LayoutElement.GRID);
final LayoutElement elemRows = elemGrid.addChild(createRows());
final LayoutElement elemColumns = createColumns(2);
elemColumns.getChildAt(0).setAttribute(LayoutElementAttributes.A_HFLEX, LayoutElementAttributes.V_MIN);
elemColumns.getChildAt(0).setAttribute(A_HFLEX, V_MIN);
elemGrid.setClass(LayoutElementClass.NO_BORDER).addChild(elemColumns);
for (EntityField entityField : fields) {
if (entityField.getType().isBinary()) {
continue;
}
final LayoutElement elemRow = elemRows.addChild(new LayoutElement(LayoutElement.ROW));
final String testClass = NameUtils.getInternalName(entityField.getName().trim())
.replace('_', '-').toLowerCase();
// label column
LayoutElement elemCell = elemRow.addChild(createCell());
elemCell.setAlign(LayoutElementAttributes.V_RIGHT)
.setValign(LayoutElementAttributes.V_TOP)
.addChild(LayoutUtils.createLabel(entityField.getName()));
elemCell.setAlign(V_RIGHT)
.setValign(V_TOP)
.setAttribute(A_SCLASS, testClass + "-labelcell")
.addChild(createLabel(entityField.getName()));
// field column
elemCell = elemRow.addChild(createCell());
elemCell.addChild(createFormField(entityField));
elemCell.setAttribute(A_SCLASS, testClass + "-fieldcell")
.addChild(createFormField(entityField));
}
return createGroupbox(name, elemGrid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class LayoutElementAttributes {
public static final String A_PRE = "pre";
public static final String A_READONLY = "readonly";
public static final String A_ROWS = "rows";
public static final String A_SCLASS = "sclass";
public static final String A_SELECTEDITEM = "selectedItem";
public static final String A_SIZABLE = "sizable";
public static final String A_SIZE = "size";
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/seed/core/form/layout/LayoutServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.seed.core.form.layout.visit.SearchDecoratingVisitor;
import org.seed.core.form.layout.visit.UndecoratingVisitor;
import org.seed.core.util.Assert;
import org.seed.core.util.NameUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -847,18 +848,22 @@ private String buildListFormLayout(Form form, FormSettings formSettings) {
}

private static LayoutElement buildListFormField(FormField field) {
final String testClass = new StringBuilder()
.append(field.getForm().getEntity().getInternalName()).append('-')
.append(NameUtils.getInternalName(field.getName().trim()))
.append("-content").toString().replace('_','-').toLowerCase();
// system field
if (field.isSystem()) {
if (field.getSystemField() == SystemField.ENTITYSTATUS) {
return createListCell(load(listPropertyName(field) + ".numberAndName"), null, field.getStyle());
return createListCell(load(listPropertyName(field) + ".numberAndName"), null, field.getStyle(), testClass);
}
else {
return createListCell(load(listPropertyName(field)), null, field.getStyle());
return createListCell(load(listPropertyName(field)), null, field.getStyle(), testClass);
}
}
// reference field
else if (field.getEntityField().getType().isReference()) {
return createListCell(load("vm.getIdentifier(" + listPropertyName(field) + ')'), null, field.getStyle());
return createListCell(load("vm.getIdentifier(" + listPropertyName(field) + ')'), null, field.getStyle(), testClass);
}
// binary field
else if (field.getEntityField().getType().isBinary()) {
Expand All @@ -876,7 +881,7 @@ else if (field.getEntityField().getType().isBinary()) {
final String converter = field.getEntityField().getType().isDateTime()
? "vm.dateTimeConverter"
: "vm.valueConverter";
return createListCell(load(listPropertyName(field)) + ' ' + converter(converter), icon, field.getStyle());
return createListCell(load(listPropertyName(field)) + ' ' + converter(converter), icon, field.getStyle(), testClass);
}
}

Expand Down
69 changes: 36 additions & 33 deletions src/main/java/org/seed/core/form/layout/LayoutUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.seed.core.data.FieldType;
import org.seed.core.entity.EntityField;
import org.seed.core.util.Assert;
import org.seed.core.util.NameUtils;

public abstract class LayoutUtils {

Expand Down Expand Up @@ -90,8 +91,8 @@ public static LayoutElement createZK() {
public static LayoutElement createGrid(int numColumns, int numRows, String title) {
final LayoutElement elemGrid = new LayoutElement(LayoutElement.GRID);
final LayoutElement elemRows = elemGrid.addChild(createRows());
elemGrid.setClass(LayoutElementClass.NO_BORDER);
elemGrid.addChild(createColumns(numColumns));
elemGrid.setClass(LayoutElementClass.NO_BORDER)
.addChild(createColumns(numColumns));
for (int i = 0; i < numRows; i++) {
elemRows.addChild(createRow(numColumns));
}
Expand All @@ -116,9 +117,9 @@ public static LayoutElement createBandbox(EntityField field) {
Assert.notNull(field, C.FIELD);

final LayoutElement elemBandbox = new LayoutElement(LayoutElement.BANDBOX);
elemBandbox.setAttribute(A_ID, field.getUid());
elemBandbox.setAttribute(A_HFLEX, V_1);
elemBandbox.setOrRemoveAttribute(A_MANDATORY, field.isMandatory());
elemBandbox.setAttribute(A_ID, field.getUid())
.setAttribute(A_HFLEX, V_1)
.setOrRemoveAttribute(A_MANDATORY, field.isMandatory());
return elemBandbox;
}

Expand Down Expand Up @@ -196,9 +197,10 @@ public static LayoutElement createLabel(String text) {
Assert.notNull(text, C.TEXT);

final LayoutElement elemLabel = new LayoutElement(LayoutElement.LABEL);
elemLabel.setAttribute(A_SCLASS, NameUtils.getInternalName(text.trim()).replace('_', '-').toLowerCase() + "-label");
if (text.contains("\n")) {
elemLabel.setAttribute(A_PRE, V_TRUE);
elemLabel.addChild(createLabelAttribute(text));
elemLabel.setAttribute(A_PRE, V_TRUE)
.addChild(createLabelAttribute(text));
}
else {
elemLabel.setAttribute(A_VALUE, text);
Expand All @@ -210,17 +212,17 @@ public static LayoutElement createLabelAttribute(String text) {
Assert.notNull(text, C.TEXT);

final LayoutElement elemAttr = new LayoutElement(LayoutElement.ATTRIBUTE);
elemAttr.setAttribute(A_NAME, C.VALUE);
elemAttr.setText(text);
elemAttr.setAttribute(A_NAME, C.VALUE)
.setText(text);
return elemAttr;
}

public static LayoutElement createFormField(EntityField field) {
Assert.notNull(field, C.FIELD);

final LayoutElement elemField = createElement(field.getType());
elemField.setAttribute(A_ID, field.getUid());

elemField.setAttribute(A_ID, field.getUid())
.setAttribute(A_SCLASS, NameUtils.getInternalName(field.getName().trim()).replace('_', '-').toLowerCase() + "-field");
if (field.getType().isDateTime()) {
elemField.setAttribute("format", "long+medium");
}
Expand Down Expand Up @@ -292,32 +294,31 @@ public static LayoutElement createMenuItem(String label, String icon, String com
Assert.notNull(label, C.LABEL);
Assert.notNull(command, C.COMMAND);

final LayoutElement elemMenuItem = new LayoutElement(LayoutElement.MENUITEM);
elemMenuItem.setLabel(Seed.getLabel(label));
final LayoutElement elemMenuItem = new LayoutElement(LayoutElement.MENUITEM)
.setLabel(Seed.getLabel(label))
.setOnClick(command(command));
if (icon != null) {
elemMenuItem.setIcon(icon);
}
elemMenuItem.setOnClick(command(command));
return elemMenuItem;
}

public static LayoutElement createTabbox(String title) {
final LayoutElement elemTabbox = new LayoutElement(LayoutElement.TABBOX);
elemTabbox.setAttribute(A_HFLEX, V_1);
elemTabbox.setAttribute(A_VFLEX, V_1);
elemTabbox.setClass(LayoutElementClass.TABBOX);
final LayoutElement elemTabs = elemTabbox.addChild(createTabs());
elemTabs.addChild(createTab(title));
final LayoutElement elemPanels = elemTabbox.addChild(createTabpanels());
elemPanels.addChild(createTabpanel());
elemTabbox.setAttribute(A_HFLEX, V_1)
.setAttribute(A_VFLEX, V_1)
.setClass(LayoutElementClass.TABBOX);
elemTabbox.addChild(createTabs()).addChild(createTab(title));
elemTabbox.addChild(createTabpanels()).addChild(createTabpanel());
return elemTabbox;
}

public static LayoutElement createTab(String title) {
Assert.notNull(title, "title");

final LayoutElement elemTab = new LayoutElement(LayoutElement.TAB);
elemTab.setLabel(title);
elemTab.setLabel(title)
.setAttribute(A_SCLASS, NameUtils.getInternalName(title).replace('_', '-').toLowerCase() + "-tab");
return elemTab;
}

Expand All @@ -342,8 +343,8 @@ public static LayoutElement createToolbarButton(String label, String command, St
Assert.notNull(command, C.COMMAND);

final LayoutElement elemButton = new LayoutElement(LayoutElement.TOOLBARBUTTON);
elemButton.setLabel(label);
elemButton.setOnClick(command(command));
elemButton.setLabel(label)
.setOnClick(command(command));
if (icon != null) {
elemButton.setAttribute(A_ICONSCLASS, icon);
}
Expand All @@ -352,11 +353,11 @@ public static LayoutElement createToolbarButton(String label, String command, St

public static LayoutElement createListFormList() {
final LayoutElement elemListbox = createListBox();
elemListbox.setAttribute(A_MODEL, load("vm.listModel"));
elemListbox.setAttribute(A_SELECTEDITEM, bind("vm.object"));
elemListbox.setAttribute(A_ONSELECT, command("'selectObject'"));
elemListbox.setAttribute(A_VFLEX, V_TRUE);
elemListbox.setAttribute(A_STYLE, "margin:5px");
elemListbox.setAttribute(A_MODEL, load("vm.listModel"))
.setAttribute(A_SELECTEDITEM, bind("vm.object"))
.setAttribute(A_ONSELECT, command("'selectObject'"))
.setAttribute(A_VFLEX, V_TRUE)
.setAttribute(A_STYLE, "margin:5px");
return elemListbox;
}

Expand Down Expand Up @@ -390,14 +391,16 @@ public static LayoutElement createListItem(String doubleClickAction) {
return elemListitem;
}

public static LayoutElement createListCell(String property, String icon, String style) {
public static LayoutElement createListCell(String property, String icon, String style, String testClass) {
Assert.notNull(property, C.PROPERTY);

final LayoutElement elemListcell = new LayoutElement(LayoutElement.LISTCELL);
elemListcell.setAttribute(A_SCLASS, testClass);
if (icon != null) {
elemListcell.setAttribute(A_ICONSCLASS, icon);
}
final LayoutElement elemLabel = elemListcell.addChild(createLabel(property));
elemLabel.removeAttribute(A_SCLASS);
if (style != null) {
elemLabel.setAttribute(A_STYLE, style);
}
Expand All @@ -417,9 +420,9 @@ public static LayoutElement createTemplate(String name, String variable) {
Assert.notNull(name, C.NAME);
Assert.notNull(variable, A_VAR);

final LayoutElement elemTemplate = new LayoutElement(LayoutElement.TEMPLATE);
elemTemplate.setAttribute(A_NAME, name);
elemTemplate.setAttribute(A_VAR, variable);
final LayoutElement elemTemplate = new LayoutElement(LayoutElement.TEMPLATE)
.setAttribute(A_NAME, name)
.setAttribute(A_VAR, variable);
return elemTemplate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ private void visitBandbox(LayoutElement element) {
elemListbox.addChild(createListHead(true));
elemListbox.addChild(createTemplate("empty", entityField.getReferenceEntity().getInternalName()))
.addChild(createListItem(null))
.addChild(createListCell('[' + Seed.getLabel(LABEL_EMPTY) + ']', null, null));
.addChild(createListCell('[' + Seed.getLabel(LABEL_EMPTY) + ']', null, null, null));
elemListbox.addChild(createTemplate(A_MODEL, entityField.getReferenceEntity().getInternalName()))
.addChild(createListItem(null))
.addChild(createListCell(load(identifier(entityField.getReferenceEntity().getInternalName())) , null, null));
.addChild(createListCell(load(identifier(entityField.getReferenceEntity().getInternalName())) , null, null, null));

final FormFieldExtra fieldExtra = getFieldExtra(entityField);
if (fieldExtra != null && fieldExtra.getDetailForm() != null) {
Expand Down Expand Up @@ -463,10 +463,10 @@ private void createSubFormBandboxField(SubFormField subFormField, String nestedN
elemList.addChild(createListHead(true));
elemList.addChild(createTemplate("empty", nestedEntityField.getReferenceEntity().getInternalName()))
.addChild(createListItem(null))
.addChild(createListCell('[' + Seed.getLabel(LABEL_EMPTY) + ']', null, null));
.addChild(createListCell('[' + Seed.getLabel(LABEL_EMPTY) + ']', null, null, null));
elemList.addChild(createTemplate(A_MODEL, nestedEntityField.getReferenceEntity().getInternalName()))
.addChild(createListItem(null))
.addChild(createListCell(load(identifier(nestedEntityField.getReferenceEntity().getInternalName())), null, null));
.addChild(createListCell(load(identifier(nestedEntityField.getReferenceEntity().getInternalName())), null, null, null));
if (subFormField.getDetailForm() != null) {
addRootChild(createReferencePopup(elemField.getContext(), nestedEntityField.getUid()));
}
Expand Down
Loading

0 comments on commit fabc2af

Please sign in to comment.