IDEMPIERE-368 Improve Form Layout to allow more columns and positioning / Fix problems found:

- field groups collapsed by default were not working
- label field group after a collapsible field group was not working
- uncollapse group if there are mandatory unfilled fields within
This commit is contained in:
Carlos Ruiz 2012-09-10 23:36:38 -05:00
parent df52b82c37
commit 011c9b3b61
4 changed files with 94 additions and 62 deletions

View File

@ -1,5 +1,6 @@
package org.adempiere.webui.component; package org.adempiere.webui.component;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
@ -13,14 +14,15 @@ import org.zkoss.zul.Label;
import org.zkoss.zul.Row; import org.zkoss.zul.Row;
public class Group extends org.zkoss.zul.Group { public class Group extends org.zkoss.zul.Group {
/** /**
* *
*/ */
private static final long serialVersionUID = -357795690637457751L; private static final long serialVersionUID = -6735090880559291438L;
public static final String GROUP_ROW_VISIBLE_KEY = "groupRowVisible"; public static final String GROUP_ROW_VISIBLE_KEY = "groupRowVisible";
private List<org.adempiere.webui.component.Row> m_rows = new ArrayList<org.adempiere.webui.component.Row>();
public Group() { public Group() {
super(); super();
setSclass("z-group"); setSclass("z-group");
@ -56,17 +58,13 @@ public class Group extends org.zkoss.zul.Group {
throw new UiException("Unsupported child for setLabel: "+cell); throw new UiException("Unsupported child for setLabel: "+cell);
} }
public void setOpen(boolean open) { public void setOpen(boolean open) {
if(getParent() == null && !open)
open = true; // force the group to open when the parent is null
super.setOpen(open); super.setOpen(open);
autoFirstCell().setOpen(isOpen()); autoFirstCell().setOpen(isOpen());
if(getParent() != null) if (getParent() != null)
{ {
List<Row> rows = getItems(); for (Row row : m_rows)
for (Row row : rows)
{ {
boolean visible = true; boolean visible = true;
String value = (String) row.getAttribute(GROUP_ROW_VISIBLE_KEY); String value = (String) row.getAttribute(GROUP_ROW_VISIBLE_KEY);
@ -76,7 +74,11 @@ public class Group extends org.zkoss.zul.Group {
} }
} }
} }
public void add(org.adempiere.webui.component.Row row) {
m_rows.add(row);
}
public class GroupHeader extends Div implements EventListener<Event> public class GroupHeader extends Div implements EventListener<Event>
{ {
/** /**
@ -139,4 +141,5 @@ public class Group extends org.zkoss.zul.Group {
} }
} }
} }
} }

View File

@ -31,7 +31,7 @@ public class Row extends org.zkoss.zul.Row
/** /**
* *
*/ */
private static final long serialVersionUID = 3587841381101659893L; private static final long serialVersionUID = -5813452501151101553L;
public boolean appendCellChild(Component child) { public boolean appendCellChild(Component child) {
return this.appendCellChild(child, 1); return this.appendCellChild(child, 1);
@ -44,5 +44,17 @@ public class Row extends org.zkoss.zul.Row
cell.appendChild(child); cell.appendChild(child);
return super.appendChild(cell); return super.appendChild(cell);
} }
private Group m_group;
public Group getGroup() {
return m_group;
}
public void setGroup(Group group) {
this.m_group = group;
if (m_group != null)
m_group.add(this);
}
} }

View File

@ -521,11 +521,14 @@ public abstract class WEditor implements EventListener<Event>, PropertyChangeLis
public void updateLabelStyle() { public void updateLabelStyle() {
if (getLabel() != null) { if (getLabel() != null) {
boolean mandatoryStyle = mandatory && !readOnly && getGridField().isEditable(true) && isNullOrEmpty(); getLabel().setStyle( (isZoomable() ? STYLE_ZOOMABLE_LABEL : "") + (isMandatoryStyle() ? STYLE_EMPTY_MANDATORY_LABEL : STYLE_NORMAL_LABEL));
getLabel().setStyle( (isZoomable() ? STYLE_ZOOMABLE_LABEL : "") + (mandatoryStyle ? STYLE_EMPTY_MANDATORY_LABEL : STYLE_NORMAL_LABEL));
} }
} }
public boolean isMandatoryStyle() {
return mandatory && !readOnly && getGridField().isEditable(true) && isNullOrEmpty();
}
public boolean isNullOrEmpty() { public boolean isNullOrEmpty() {
Object value = getValue(); Object value = getValue();
return value == null || value.toString().trim().length() == 0; return value == null || value.toString().trim().length() == 0;

View File

@ -96,12 +96,12 @@ import org.zkoss.zul.impl.XulElement;
public class ADTabpanel extends Div implements Evaluatee, EventListener<Event>, public class ADTabpanel extends Div implements Evaluatee, EventListener<Event>,
DataStatusListener, IADTabpanel DataStatusListener, IADTabpanel
{ {
private static final String ON_DEFER_SET_SELECTED_NODE = "onDeferSetSelectedNode";
/** /**
* generated serial version ID *
*/ */
private static final long serialVersionUID = 6945934489328360251L; private static final long serialVersionUID = -975129028953555569L;
private static final String ON_DEFER_SET_SELECTED_NODE = "onDeferSetSelectedNode";
private static final CLogger logger; private static final CLogger logger;
@ -135,6 +135,8 @@ DataStatusListener, IADTabpanel
private ArrayList<Row> rowList; private ArrayList<Row> rowList;
List<Group> allCollapsibleGroups = new ArrayList<Group>();
private Component formComponent = null; private Component formComponent = null;
private ADTreePanel treePanel = null; private ADTreePanel treePanel = null;
@ -350,22 +352,16 @@ DataStatusListener, IADTabpanel
{ {
currentFieldGroup = fieldGroup; currentFieldGroup = fieldGroup;
if (numCols - actualxpos > 0) if (numCols - actualxpos + 1 > 0)
row.appendCellChild(createSpacer(), numCols - actualxpos); row.appendCellChild(createSpacer(), numCols - actualxpos + 1);
row.setGroup(currentGroup);
rows.appendChild(row); rows.appendChild(row);
if (rowList != null) if (rowList != null)
rowList.add(row); rowList.add(row);
row = new Row();
actualxpos = 0;
List<org.zkoss.zul.Row> headerRows = new ArrayList<org.zkoss.zul.Row>(); List<org.zkoss.zul.Row> headerRows = new ArrayList<org.zkoss.zul.Row>();
fieldGroupHeaders.put(fieldGroup, headerRows); fieldGroupHeaders.put(fieldGroup, headerRows);
row.appendCellChild(new Separator(), numCols);
rows.appendChild(row);
headerRows.add(row);
rowList = new ArrayList<Row>(); rowList = new ArrayList<Row>();
fieldGroupContents.put(fieldGroup, rowList); fieldGroupContents.put(fieldGroup, rowList);
@ -383,11 +379,13 @@ DataStatusListener, IADTabpanel
row.appendCellChild(separator, numCols); row.appendCellChild(separator, numCols);
rows.appendChild(row); rows.appendChild(row);
headerRows.add(row); headerRows.add(row);
currentGroup = null;
} }
else else
{ {
Group rowg = new Group(fieldGroup); Group rowg = new Group(fieldGroup);
rowg.setSpans(numColsS); rowg.setSpans(numColsS);
allCollapsibleGroups.add(rowg);
if (X_AD_FieldGroup.FIELDGROUPTYPE_Tab.equals(field.getFieldGroupType()) || field.getIsCollapsedByDefault()) if (X_AD_FieldGroup.FIELDGROUPTYPE_Tab.equals(field.getFieldGroupType()) || field.getIsCollapsedByDefault())
{ {
rowg.setOpen(false); rowg.setOpen(false);
@ -406,7 +404,10 @@ DataStatusListener, IADTabpanel
// Fill right part of the row with spacers until number of columns // Fill right part of the row with spacers until number of columns
if (numCols - actualxpos + 1 > 0) if (numCols - actualxpos + 1 > 0)
row.appendCellChild(createSpacer(), numCols - actualxpos + 1); row.appendCellChild(createSpacer(), numCols - actualxpos + 1);
row.setGroup(currentGroup);
rows.appendChild(row); rows.appendChild(row);
if (rowList != null)
rowList.add(row);
row=new Row(); row=new Row();
actualxpos = 0; actualxpos = 0;
} }
@ -439,17 +440,6 @@ DataStatusListener, IADTabpanel
row.appendCellChild(div,1); row.appendCellChild(div,1);
} }
row.appendCellChild(editor.getComponent(), field.getColumnSpan()); row.appendCellChild(editor.getComponent(), field.getColumnSpan());
/*
if (field.isLongField()) {
row.setSpans("1,3,1");
row.appendCellChild(createSpacer());
rows.appendChild(row);
if (rowList != null)
rowList.add(row);
//row = new Row();
}
*/
if (editor instanceof WButtonEditor) if (editor instanceof WButtonEditor)
{ {
@ -498,8 +488,10 @@ DataStatusListener, IADTabpanel
row.appendCellChild(div); row.appendCellChild(div);
} }
} }
if (numCols - actualxpos + 1 > 0) if (numCols - actualxpos + 1 > 0)
row.appendCellChild(createSpacer(), numCols - actualxpos + 1); row.appendCellChild(createSpacer(), numCols - actualxpos + 1);
row.setGroup(currentGroup);
rows.appendChild(row); rows.appendChild(row);
if (rowList != null) if (rowList != null)
rowList.add(row); rowList.add(row);
@ -530,6 +522,12 @@ DataStatusListener, IADTabpanel
return; return;
} }
List<Group> collapsedGroups = new ArrayList<Group>();
for (Group group : allCollapsibleGroups) {
if (! group.isOpen())
collapsedGroups.add(group);
}
for (WEditor comp : editors) for (WEditor comp : editors)
{ {
comp.updateLabelStyle(); comp.updateLabelStyle();
@ -582,31 +580,42 @@ DataStatusListener, IADTabpanel
} // all components } // all components
//hide row if all editor within the row is invisible //hide row if all editor within the row is invisible
List<?> rows = grid.getRows().getChildren(); List<Component> rows = grid.getRows().getChildren();
for(int i = 0; i < rows.size(); i++) for (Component comp : rows)
{ {
org.zkoss.zul.Row row = (org.zkoss.zul.Row) rows.get(i); if (comp instanceof Row) {
List<?> components = row.getChildren(); Row row = (Row) comp;
boolean visible = false; boolean visible = false;
boolean editorRow = false; boolean editorRow = false;
for (int j = 0; j < components.size(); j++) for (Component cellComponent : row.getChildren())
{ {
Component cellComponent = (Component) components.get(j); Component component = cellComponent.getFirstChild();
Component component = cellComponent.getFirstChild(); if (editorComps.contains(component))
if (editorComps.contains(component)) {
{ editorRow = true;
editorRow = true; // open the group if there is a mandatory unfilled field
if (component.isVisible()) WEditor editor = editors.get(editorComps.indexOf(component));
{ if (editor != null
visible = true; && row.getGroup() != null
break; && ! row.getGroup().isOpen()
} && editor.isMandatoryStyle()) {
} row.getGroup().setOpen(true);
} if (collapsedGroups.contains(row.getGroup())) {
if (editorRow && (row.isVisible() != visible)) collapsedGroups.remove(row.getGroup());
{ }
row.setAttribute(Group.GROUP_ROW_VISIBLE_KEY, visible ? "true" : "false"); }
row.setVisible(visible); if (component.isVisible())
{
visible = true;
break;
}
}
}
if (editorRow && (row.isVisible() != visible))
{
row.setAttribute(Group.GROUP_ROW_VISIBLE_KEY, visible ? "true" : "false");
row.setVisible(visible);
}
} }
} }
@ -632,6 +641,11 @@ DataStatusListener, IADTabpanel
} }
} }
// collapse the groups closed
for (Group group : collapsedGroups) {
group.setOpen(false);
}
logger.config(gridTab.toString() + " - fini - " + (col<=0 ? "complete" : "seletive")); logger.config(gridTab.toString() + " - fini - " + (col<=0 ? "complete" : "seletive"));
} // dynamicDisplay } // dynamicDisplay