From 011c9b3b61806c46d631381f75bac04a61af4f90 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 10 Sep 2012 23:36:38 -0500 Subject: [PATCH] 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 --- .../org/adempiere/webui/component/Group.java | 25 ++-- .../org/adempiere/webui/component/Row.java | 14 ++- .../org/adempiere/webui/editor/WEditor.java | 7 +- .../org/adempiere/webui/panel/ADTabpanel.java | 110 ++++++++++-------- 4 files changed, 94 insertions(+), 62 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Group.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Group.java index 77a4403b80..c58a25226d 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Group.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Group.java @@ -1,5 +1,6 @@ package org.adempiere.webui.component; +import java.util.ArrayList; import java.util.List; import org.zkoss.zk.ui.Component; @@ -13,14 +14,15 @@ import org.zkoss.zul.Label; import org.zkoss.zul.Row; 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"; + private List m_rows = new ArrayList(); + public Group() { super(); setSclass("z-group"); @@ -56,17 +58,13 @@ public class Group extends org.zkoss.zul.Group { throw new UiException("Unsupported child for setLabel: "+cell); } - public void setOpen(boolean open) { - if(getParent() == null && !open) - open = true; // force the group to open when the parent is null - + public void setOpen(boolean open) { super.setOpen(open); autoFirstCell().setOpen(isOpen()); - if(getParent() != null) + if (getParent() != null) { - List rows = getItems(); - for (Row row : rows) + for (Row row : m_rows) { boolean visible = true; 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 { /** @@ -139,4 +141,5 @@ public class Group extends org.zkoss.zul.Group { } } } + } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Row.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Row.java index 68ac17acc3..fcb8e51a63 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Row.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Row.java @@ -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) { return this.appendCellChild(child, 1); @@ -44,5 +44,17 @@ public class Row extends org.zkoss.zul.Row cell.appendChild(child); 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); + } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java index f5899aa408..9fc0a1d9f5 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java @@ -521,11 +521,14 @@ public abstract class WEditor implements EventListener, PropertyChangeLis public void updateLabelStyle() { if (getLabel() != null) { - boolean mandatoryStyle = mandatory && !readOnly && getGridField().isEditable(true) && isNullOrEmpty(); - getLabel().setStyle( (isZoomable() ? STYLE_ZOOMABLE_LABEL : "") + (mandatoryStyle ? STYLE_EMPTY_MANDATORY_LABEL : STYLE_NORMAL_LABEL)); + getLabel().setStyle( (isZoomable() ? STYLE_ZOOMABLE_LABEL : "") + (isMandatoryStyle() ? STYLE_EMPTY_MANDATORY_LABEL : STYLE_NORMAL_LABEL)); } } + public boolean isMandatoryStyle() { + return mandatory && !readOnly && getGridField().isEditable(true) && isNullOrEmpty(); + } + public boolean isNullOrEmpty() { Object value = getValue(); return value == null || value.toString().trim().length() == 0; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java index ca8339dd36..a6fc1224d1 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java @@ -96,12 +96,12 @@ import org.zkoss.zul.impl.XulElement; public class ADTabpanel extends Div implements Evaluatee, EventListener, 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; @@ -135,6 +135,8 @@ DataStatusListener, IADTabpanel private ArrayList rowList; + List allCollapsibleGroups = new ArrayList(); + private Component formComponent = null; private ADTreePanel treePanel = null; @@ -350,22 +352,16 @@ DataStatusListener, IADTabpanel { currentFieldGroup = fieldGroup; - if (numCols - actualxpos > 0) - row.appendCellChild(createSpacer(), numCols - actualxpos); + if (numCols - actualxpos + 1 > 0) + row.appendCellChild(createSpacer(), numCols - actualxpos + 1); + row.setGroup(currentGroup); rows.appendChild(row); if (rowList != null) rowList.add(row); - row = new Row(); - actualxpos = 0; - List headerRows = new ArrayList(); fieldGroupHeaders.put(fieldGroup, headerRows); - row.appendCellChild(new Separator(), numCols); - rows.appendChild(row); - headerRows.add(row); - rowList = new ArrayList(); fieldGroupContents.put(fieldGroup, rowList); @@ -383,11 +379,13 @@ DataStatusListener, IADTabpanel row.appendCellChild(separator, numCols); rows.appendChild(row); headerRows.add(row); + currentGroup = null; } else { Group rowg = new Group(fieldGroup); rowg.setSpans(numColsS); + allCollapsibleGroups.add(rowg); if (X_AD_FieldGroup.FIELDGROUPTYPE_Tab.equals(field.getFieldGroupType()) || field.getIsCollapsedByDefault()) { rowg.setOpen(false); @@ -406,7 +404,10 @@ DataStatusListener, IADTabpanel // Fill right part of the row with spacers until number of columns if (numCols - actualxpos + 1 > 0) row.appendCellChild(createSpacer(), numCols - actualxpos + 1); + row.setGroup(currentGroup); rows.appendChild(row); + if (rowList != null) + rowList.add(row); row=new Row(); actualxpos = 0; } @@ -439,17 +440,6 @@ DataStatusListener, IADTabpanel row.appendCellChild(div,1); } 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) { @@ -498,8 +488,10 @@ DataStatusListener, IADTabpanel row.appendCellChild(div); } } + if (numCols - actualxpos + 1 > 0) row.appendCellChild(createSpacer(), numCols - actualxpos + 1); + row.setGroup(currentGroup); rows.appendChild(row); if (rowList != null) rowList.add(row); @@ -530,6 +522,12 @@ DataStatusListener, IADTabpanel return; } + List collapsedGroups = new ArrayList(); + for (Group group : allCollapsibleGroups) { + if (! group.isOpen()) + collapsedGroups.add(group); + } + for (WEditor comp : editors) { comp.updateLabelStyle(); @@ -582,31 +580,42 @@ DataStatusListener, IADTabpanel } // all components //hide row if all editor within the row is invisible - List rows = grid.getRows().getChildren(); - for(int i = 0; i < rows.size(); i++) + List rows = grid.getRows().getChildren(); + for (Component comp : rows) { - org.zkoss.zul.Row row = (org.zkoss.zul.Row) rows.get(i); - List components = row.getChildren(); - boolean visible = false; - boolean editorRow = false; - for (int j = 0; j < components.size(); j++) - { - Component cellComponent = (Component) components.get(j); - Component component = cellComponent.getFirstChild(); - if (editorComps.contains(component)) - { - editorRow = true; - if (component.isVisible()) - { - visible = true; - break; - } - } - } - if (editorRow && (row.isVisible() != visible)) - { - row.setAttribute(Group.GROUP_ROW_VISIBLE_KEY, visible ? "true" : "false"); - row.setVisible(visible); + if (comp instanceof Row) { + Row row = (Row) comp; + boolean visible = false; + boolean editorRow = false; + for (Component cellComponent : row.getChildren()) + { + Component component = cellComponent.getFirstChild(); + if (editorComps.contains(component)) + { + editorRow = true; + // open the group if there is a mandatory unfilled field + WEditor editor = editors.get(editorComps.indexOf(component)); + if (editor != null + && row.getGroup() != null + && ! row.getGroup().isOpen() + && editor.isMandatoryStyle()) { + row.getGroup().setOpen(true); + if (collapsedGroups.contains(row.getGroup())) { + collapsedGroups.remove(row.getGroup()); + } + } + 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")); } // dynamicDisplay