IDEMPIERE-1024 Improve default creation of window fields

This commit is contained in:
Carlos Ruiz 2013-06-03 11:50:29 -05:00
parent 4b8389846b
commit e34e51ce3b
1 changed files with 51 additions and 2 deletions

View File

@ -23,8 +23,11 @@ import java.util.logging.Level;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.MField; import org.compiere.model.MField;
import org.compiere.model.MTab; import org.compiere.model.MTab;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.util.AdempiereSystemError; import org.compiere.util.AdempiereSystemError;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.DisplayType;
/** /**
@ -76,9 +79,20 @@ public class TabCreateFields extends SvrProcess
+ " AND AD_Table_ID=?" // #3 + " AND AD_Table_ID=?" // #3
+ " AND NOT (Name LIKE 'Created%' OR Name LIKE 'Updated%')" + " AND NOT (Name LIKE 'Created%' OR Name LIKE 'Updated%')"
+ " AND IsActive='Y' " + " AND IsActive='Y' "
+ "ORDER BY Name"; + "ORDER BY CASE "
+ " WHEN c.ColumnName = 'AD_Client_ID' THEN -100 "
+ " WHEN c.ColumnName = 'AD_Org_ID' THEN -90 "
+ " WHEN c.ColumnName = 'Value' THEN -80 "
+ " WHEN c.ColumnName = 'Name' THEN -70 "
+ " WHEN c.ColumnName = 'Description' THEN -60 "
+ " WHEN c.ColumnName = 'Help' THEN -50 "
+ " WHEN c.ColumnName = 'IsActive' THEN 1000000000 "
+ " ELSE c.AD_Column_ID "
+ " END ";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
int seqno = DB.getSQLValue(null, "SELECT MAX(SeqNo) FROM AD_Field WHERE AD_Tab_ID=?", tab.getAD_Tab_ID());
seqno = seqno + 10;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
@ -86,6 +100,7 @@ public class TabCreateFields extends SvrProcess
pstmt.setInt (2, tab.getAD_Tab_ID()); pstmt.setInt (2, tab.getAD_Tab_ID());
pstmt.setInt (3, tab.getAD_Table_ID()); pstmt.setInt (3, tab.getAD_Table_ID());
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
String uuidcolname = PO.getUUIDColumnName(tab.getAD_Table().getTableName());
while (rs.next ()) while (rs.next ())
{ {
MColumn column = new MColumn (getCtx(), rs, get_TrxName()); MColumn column = new MColumn (getCtx(), rs, get_TrxName());
@ -104,10 +119,44 @@ public class TabCreateFields extends SvrProcess
// end F3P // end F3P
if (column.isKey()){ if (column.isKey() || uuidcolname.equalsIgnoreCase(field.getName())) {
field.setIsDisplayed(false); field.setIsDisplayed(false);
field.setIsDisplayedGrid(false); field.setIsDisplayedGrid(false);
} }
// Assign some default formatting
field.setSeqNo(seqno);
seqno = seqno + 10;
if (column.getAD_Reference_ID() == DisplayType.Button || column.getAD_Reference_ID() == DisplayType.YesNo) {
field.setXPosition(2);
}
field.setColumnSpan(2);
if (column.getFieldLength() >= 60) {
field.setColumnSpan(5);
}
if (column.getAD_Reference_ID() == DisplayType.Text) {
field.setNumLines(3);
} else if (column.getAD_Reference_ID() == DisplayType.TextLong) {
field.setNumLines(5);
} else if (column.getAD_Reference_ID() == DisplayType.Memo) {
field.setNumLines(8);
}
String accessLevel = tab.getAD_Table().getAccessLevel();
if (column.getColumnName().equals("AD_Org_ID")) {
field.setXPosition(4);
if ( accessLevel.equals(MTable.ACCESSLEVEL_ClientOnly)
|| accessLevel.equals(MTable.ACCESSLEVEL_SystemOnly)
|| accessLevel.equals(MTable.ACCESSLEVEL_SystemPlusClient)) {
field.setIsDisplayedGrid(false);
}
}
if (column.getColumnName().equals("AD_Client_ID")) {
if (! (accessLevel.equals(MTable.ACCESSLEVEL_All)
|| accessLevel.equals(MTable.ACCESSLEVEL_SystemPlusClient))) {
field.setIsDisplayedGrid(false);
}
}
if (field.save()) if (field.save())
{ {
addLog(0, null, null, column.getName()); addLog(0, null, null, column.getName());