IDEMPIERE-4841 Info Window: Implement auto hide empty columns (#781)

This commit is contained in:
hengsin 2021-07-15 23:03:33 +08:00 committed by GitHub
parent de2b29d129
commit 3dcef18868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 237 additions and 150 deletions

View File

@ -0,0 +1,10 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Jul 15, 2021, 3:50:49 PM MYT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200180,0,0,TO_DATE('2021-07-15 15:50:48','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2021-07-15 15:50:48','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_INFO_AUTO_HIDE_EMPTY_COLUMNS','N','Y/N - Define if info window will auto hide columns with empty content','D','C','99ba73cd-f64a-418d-bb55-82f4192b1055')
;
SELECT Register_Migration_Script ('202107150800_IDEMPIERE-4841.sql') FROM DUAL
;

View File

@ -0,0 +1,7 @@
-- Jul 15, 2021, 3:50:49 PM MYT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200180,0,0,TO_TIMESTAMP('2021-07-15 15:50:48','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2021-07-15 15:50:48','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_INFO_AUTO_HIDE_EMPTY_COLUMNS','N','Y/N - Define if info window will auto hide columns with empty content','D','C','99ba73cd-f64a-418d-bb55-82f4192b1055')
;
SELECT Register_Migration_Script ('202107150800_IDEMPIERE-4841.sql') FROM DUAL
;

View File

@ -189,6 +189,7 @@ public class MSysConfig extends X_AD_SysConfig
public static final String ZK_GRID_MOBILE_MAX_COLUMNS = "ZK_GRID_MOBILE_MAX_COLUMNS";
public static final String ZK_GRID_MOBILE_SHOW_CURRENT_ROW_INDICATOR = "ZK_GRID_MOBILE_SHOW_CURRENT_ROW_INDICATOR";
public static final String ZK_GRID_VIEW_USE_DEFER_RENDERING = "ZK_GRID_VIEW_USE_DEFER_RENDERING";
public static final String ZK_INFO_AUTO_HIDE_EMPTY_COLUMNS = "ZK_INFO_AUTO_HIDE_EMPTY_COLUMNS";
public static final String ZK_INFO_NUM_PAGE_PRELOAD = "ZK_INFO_NUM_PAGE_PRELOAD";
public static final String ZK_INFO_QUERY_TIME_OUT = "ZK_INFO_QUERY_TIME_OUT";
public static final String ZK_LOGIN_ALLOW_CHROME_SAVE_PASSWORD = "ZK_LOGIN_ALLOW_CHROME_SAVE_PASSWORD";

View File

@ -135,7 +135,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
/**
*
*/
private static final long serialVersionUID = 5041961608373943362L;
private static final long serialVersionUID = 1180753002653812499L;
protected Grid parameterGrid;
private Borderlayout layout;

View File

@ -92,6 +92,7 @@ import org.compiere.util.Trx;
import org.compiere.util.Util;
import org.compiere.util.ValueNamePair;
import org.zkoss.zk.au.out.AuEcho;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
@ -124,6 +125,8 @@ import org.zkoss.zul.ext.Sortable;
public abstract class InfoPanel extends Window implements EventListener<Event>, WTableModelListener, Sortable<Object>, IHelpContext
{
protected static final String INFO_QUERY_TIME_OUT_ERROR = "InfoQueryTimeOutError";
protected static final String COLUMN_VISIBLE_ORIGINAL = "column.visible.original";
/**
*
*/
@ -895,6 +898,7 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
model.setMultiple(p_multipleSelection);
contentPanel.setData(model, null);
}
autoHideEmptyColumns();
restoreSelectedInPage();
updateStatusBar (m_count);
setStatusSelected ();
@ -904,6 +908,69 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
insertPagingComponent();
}
/**
* auto hide empty columns
*/
protected void autoHideEmptyColumns() {
String attr = contentPanel.getUuid()+".autoHideEmptyColumns";
if (Executions.getCurrent().getAttribute(attr) != null) {
return;
} else {
Executions.getCurrent().setAttribute(attr, Boolean.TRUE);
}
Listhead columns = contentPanel.getListhead();
List<Listheader> columnList = columns.getChildren();
int rowCount = model.getSize();
for(Listheader column : columnList) {
if (!isAutoHideEmptyColumns()) {
if (!column.isVisible()) {
Object attrValue = column.getAttribute(COLUMN_VISIBLE_ORIGINAL);
if (attrValue != null && attrValue instanceof Boolean) {
Boolean b = (Boolean) attrValue;
if (b.booleanValue())
column.setVisible(true);
}
}
continue;
}
boolean hideColumn = false;
if (rowCount > 0) {
hideColumn = true;
for (int i = 0; i < rowCount; i++) {
Object value = model.getDataAt(i, column.getColumnIndex());
String display = value != null ? value.toString() : "";
if (!Util.isEmpty(display, true)) {
hideColumn = false;
break;
}
}
}
if (hideColumn && column.isVisible()) {
column.setVisible(false);
column.setAttribute(COLUMN_VISIBLE_ORIGINAL, Boolean.TRUE);
} else if (!hideColumn && !column.isVisible()) {
Object attrValue = column.getAttribute(COLUMN_VISIBLE_ORIGINAL);
if (attrValue != null && attrValue instanceof Boolean) {
Boolean b = (Boolean) attrValue;
if (b.booleanValue())
column.setVisible(true);
}
}
}
}
/**
*
* @return true if info window should auto hide empty columns
*/
protected boolean isAutoHideEmptyColumns() {
return MSysConfig.getBooleanValue(MSysConfig.ZK_INFO_AUTO_HIDE_EMPTY_COLUMNS, false, Env.getAD_Client_ID(Env.getCtx()));
}
protected void updateStatusBar (int no){
setStatusLine((no == Integer.MAX_VALUE?"?":Integer.toString(no)) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
setStatusDB(no == Integer.MAX_VALUE?"?":Integer.toString(no));
@ -2003,7 +2070,8 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
if (isLookup())
this.detach();
}
}else if (event.getTarget().equals(confirmPanel.getButton(ConfirmPanel.A_NEW)))
}
else if (event.getTarget().equals(confirmPanel.getButton(ConfirmPanel.A_NEW)))
{
newRecordAction ();
}
@ -2067,6 +2135,7 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
//contentPanel.setSelectedIndex(0);
}
autoHideEmptyColumns();
}
else if (event.getName().equals(Events.ON_CHANGE))
{