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:
parent
df52b82c37
commit
011c9b3b61
|
@ -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<org.adempiere.webui.component.Row> m_rows = new ArrayList<org.adempiere.webui.component.Row>();
|
||||
|
||||
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<Row> 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<Event>
|
||||
{
|
||||
/**
|
||||
|
@ -139,4 +141,5 @@ public class Group extends org.zkoss.zul.Group {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -521,11 +521,14 @@ public abstract class WEditor implements EventListener<Event>, 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;
|
||||
|
|
|
@ -96,12 +96,12 @@ import org.zkoss.zul.impl.XulElement;
|
|||
public class ADTabpanel extends Div implements Evaluatee, EventListener<Event>,
|
||||
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<Row> rowList;
|
||||
|
||||
List<Group> allCollapsibleGroups = new ArrayList<Group>();
|
||||
|
||||
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<org.zkoss.zul.Row> headerRows = new ArrayList<org.zkoss.zul.Row>();
|
||||
fieldGroupHeaders.put(fieldGroup, headerRows);
|
||||
|
||||
row.appendCellChild(new Separator(), numCols);
|
||||
rows.appendChild(row);
|
||||
headerRows.add(row);
|
||||
|
||||
rowList = new ArrayList<Row>();
|
||||
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<Group> collapsedGroups = new ArrayList<Group>();
|
||||
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<Component> 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
|
||||
|
||||
|
|
Loading…
Reference in New Issue