IDEMPIERE-4322 Sort tab does not support virtual column identifier an… (#173)

* IDEMPIERE-4322 Sort tab does not support virtual column identifier and identifiers with different data type

add support for virtual column identifier
concat multiple identifier instead of taking the first not null value

* IDEMPIERE-4322 Sort tab does not support virtual column identifier and identifiers with different data type

Change to use DB.TO_CHAR.
Other condition (parent, key etc) shouldn't exclude IsIdentifier since
the UI allows it.
This commit is contained in:
hengsin 2020-07-25 18:15:10 +08:00 committed by GitHub
parent 763876cca3
commit 1c96affdde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 11 deletions

View File

@ -41,12 +41,14 @@ import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.FDialog;
import org.compiere.model.GridTab;
import org.compiere.model.MRole;
import org.compiere.model.MSysConfig;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.NamePair;
import org.compiere.util.Util;
import org.zkoss.zk.au.out.AuFocus;
import org.zkoss.zk.ui.event.DropEvent;
import org.zkoss.zk.ui.event.Event;
@ -167,7 +169,7 @@ public class ADSortTab extends Panel implements IADTabpanel
int identifiersCount = 0;
StringBuilder identifierSql = new StringBuilder();
String sql = "SELECT t.TableName, c.AD_Column_ID, c.ColumnName, e.Name," // 1..4
+ "c.IsParent, c.IsKey, c.IsIdentifier, c.IsTranslated " // 4..8
+ "c.IsParent, c.IsKey, c.IsIdentifier, c.IsTranslated, c.ColumnSQL, c.AD_Reference_ID " // 5..10
+ "FROM AD_Table t, AD_Column c, AD_Element e "
+ "WHERE t.AD_Table_ID=?" // #1
+ " AND t.AD_Table_ID=c.AD_Table_ID"
@ -177,7 +179,7 @@ public class ADSortTab extends Panel implements IADTabpanel
boolean trl = !Env.isBaseLanguage(Env.getCtx(), "AD_Element");
if (trl)
sql = "SELECT t.TableName, c.AD_Column_ID, c.ColumnName, et.Name," // 1..4
+ "c.IsParent, c.IsKey, c.IsIdentifier, c.IsTranslated " // 4..8
+ "c.IsParent, c.IsKey, c.IsIdentifier, c.IsTranslated, c.ColumnSQL, c.AD_Reference_ID " // 5..10
+ "FROM AD_Table t, AD_Column c, AD_Element_Trl et "
+ "WHERE t.AD_Table_ID=?" // #1
+ " AND t.AD_Table_ID=c.AD_Table_ID"
@ -226,20 +228,30 @@ public class ADSortTab extends Panel implements IADTabpanel
m_KeyColumnName = rs.getString(3);
}
// Identifier
else if (rs.getString(7).equals("Y"))
if (rs.getString(7).equals("Y"))
{
if (log.isLoggable(Level.FINE)) log.fine("Identifier=" + rs.getString(1) + "." + rs.getString(3));
boolean isTranslated = trl && "Y".equals(rs.getString(8));
int AD_Reference_ID = rs.getInt(10);
if (identifierSql.length() > 0)
identifierSql.append(",");
identifierSql.append(isTranslated ? "tt." : "t.").append(rs.getString(3));
{
identifierSql.append(" || '")
.append(MSysConfig.getValue(MSysConfig.IDENTIFIER_SEPARATOR, "_", Env.getAD_Client_ID(Env.getCtx())))
.append("' || ");
}
identifierSql.append("NVL(");
if (!Util.isEmpty(rs.getString(9)))
{
String value = rs.getString(9).replace(m_TableName + ".", isTranslated ? "tt." : "t.");
identifierSql.append(DB.TO_CHAR("("+value+")", AD_Reference_ID, Env.getAD_Language(Env.getCtx())));
}
else
identifierSql.append(DB.TO_CHAR((isTranslated ? "tt." : "t.")+rs.getString(3), AD_Reference_ID, Env.getAD_Language(Env.getCtx())));
identifierSql.append(",'')");
identifiersCount++;
// m_IdentifierColumnName = rs.getString(3);
if (isTranslated)
m_IdentifierTranslated = true;
}
else
if (log.isLoggable(Level.FINE)) log.fine("??NotUsed??=" + rs.getString(1) + "." + rs.getString(3));
}
}
catch (SQLException e)
@ -254,10 +266,8 @@ public class ADSortTab extends Panel implements IADTabpanel
//
if (identifiersCount == 0)
m_IdentifierSql = "NULL";
else if (identifiersCount == 1)
m_IdentifierSql = identifierSql.toString();
else
m_IdentifierSql = identifierSql.insert(0, "COALESCE(").append(")").toString();
m_IdentifierSql = identifierSql.toString();
//
noLabel.setValue(Msg.getMsg(Env.getCtx(), "Available"));
log.fine(m_ColumnSortName);