1 14 package org.compiere.model; 15 16 import java.io.Serializable ; 17 import java.sql.ResultSet ; 18 import java.sql.ResultSetMetaData ; 19 import java.sql.SQLException ; 20 import java.util.Properties ; 21 22 import org.compiere.util.DisplayType; 23 import org.compiere.util.Env; 24 import org.compiere.util.Log; 25 26 27 33 public class MFieldVO implements Serializable 34 { 35 43 private MFieldVO (Properties ctx, int WindowNo, int TabNo, int AD_Window_ID, boolean tabReadOnly) 44 { 45 this.ctx = ctx; 46 this.WindowNo = WindowNo; 47 this.TabNo = TabNo; 48 this.AD_Window_ID = AD_Window_ID; 49 this.tabReadOnly = tabReadOnly; 50 } 52 53 public Properties ctx = null; 54 55 public int WindowNo; 56 57 public int TabNo; 58 59 public int AD_Window_ID; 60 61 public boolean tabReadOnly = false; 62 63 64 public boolean isProcess = false; 65 66 public String ColumnName = ""; 68 public String Header = ""; 69 public int displayType = 0; 70 public int AD_Column_ID = 0; 71 public int DisplayLength = 0; 72 public boolean IsSameLine = false; 73 public boolean IsDisplayed = false; 74 public String DisplayLogic = ""; 75 public String DefaultValue = ""; 76 public boolean IsMandatory = false; 77 public boolean IsReadOnly = false; 78 public boolean IsUpdateable = false; 79 public boolean IsHeading = false; 80 public boolean IsFieldOnly = false; 81 public boolean IsEncryptedField = false; 82 public boolean IsSelectionColumn = false; 83 public int SortNo = 0; 84 public int FieldLength = 0; 85 public String VFormat = ""; 86 public String ValueMin = ""; 87 public String ValueMax = ""; 88 public String FieldGroup = ""; 89 public boolean IsKey = false; 90 public boolean IsParent = false; 91 public String Callout = ""; 92 public int AD_Process_ID = 0; 93 public String Description = ""; 94 public String Help = ""; 95 public String ReadOnlyLogic = ""; 96 public String ValidationCode = ""; 98 public int AD_Reference_Value_ID = 0; 99 100 public boolean isRange = false; 102 public String DefaultValue2 = ""; 103 104 105 public MLookupInfo lookupInfo = null; 106 107 111 public void setCtx (Properties newCtx) 112 { 113 ctx = newCtx; 114 if (lookupInfo != null) 115 lookupInfo.ctx = newCtx; 116 } 118 121 public void initRowID() 122 { 123 displayType = DisplayType.RowID; 124 ColumnName = "ROWID"; 125 IsDisplayed = false; 126 IsMandatory = false; 127 IsReadOnly = true; 128 IsUpdateable = false; 129 } 131 134 protected void initFinish() 135 { 136 if (DisplayLogic == null) 138 DisplayLogic = ""; 139 if (DefaultValue == null) 140 DefaultValue = ""; 141 if (FieldGroup == null) 142 FieldGroup = ""; 143 if (Description == null) 144 Description = ""; 145 if (Help == null) 146 Help = ""; 147 if (Callout == null) 148 Callout = ""; 149 if (ReadOnlyLogic == null) 150 ReadOnlyLogic = ""; 151 152 153 if (DisplayType.isLookup(displayType)) 155 { 156 try 157 { 158 lookupInfo = MLookupFactory.getLookupInfo (ctx, WindowNo, AD_Column_ID, displayType, 159 Env.getLanguage(ctx), ColumnName, AD_Reference_Value_ID, 160 IsParent, ValidationCode); 161 } 162 catch (Exception e) { 164 Log.error("MFieldVO.initFinish - No LookupInfo for " + ColumnName, e); 165 displayType = DisplayType.ID; 166 } 167 } 168 } 170 171 172 177 protected static String getSQL (MTabVO mTabVO) 178 { 179 String sql = "SELECT * FROM AD_Field_v WHERE AD_Tab_ID=?" 181 + " ORDER BY SeqNo"; 182 if (!Env.isBaseLanguage(mTabVO.ctx, "AD_Tab")) 183 sql = "SELECT * FROM AD_Field_vt WHERE AD_Tab_ID=?" 184 + " AND AD_Language='" + Env.getAD_Language(mTabVO.ctx) + "'" 185 + " ORDER BY SeqNo"; 186 return sql; 187 } 189 199 public static MFieldVO create (Properties ctx, int WindowNo, int TabNo, int AD_Window_ID, boolean readOnly, ResultSet rs) 200 { 201 MFieldVO vo = new MFieldVO (ctx, WindowNo, TabNo, AD_Window_ID, readOnly); 202 try 203 { 204 vo.ColumnName = rs.getString("ColumnName"); 205 if (vo.ColumnName == null) 206 return null; 207 208 Log.trace(Log.l5_DData, "MFieldVO.create", vo.ColumnName); 209 210 ResultSetMetaData rsmd = rs.getMetaData(); 211 for (int i = 1; i <= rsmd.getColumnCount(); i++) 212 { 213 String columnName = rsmd.getColumnName (i); 214 if (columnName.equalsIgnoreCase("Name")) 215 vo.Header = rs.getString (i); 216 else if (columnName.equalsIgnoreCase("AD_Reference_ID")) 217 vo.displayType = rs.getInt (i); 218 else if (columnName.equalsIgnoreCase("AD_Column_ID")) 219 vo.AD_Column_ID = rs.getInt (i); 220 else if (columnName.equalsIgnoreCase("DisplayLength")) 221 vo.DisplayLength = rs.getInt (i); 222 else if (columnName.equalsIgnoreCase("IsSameLine")) 223 vo.IsSameLine = "Y".equals(rs.getString (i)); 224 else if (columnName.equalsIgnoreCase("IsDisplayed")) 225 vo.IsDisplayed = "Y".equals(rs.getString (i)); 226 else if (columnName.equalsIgnoreCase("DisplayLogic")) 227 vo.DisplayLogic = rs.getString (i); 228 else if (columnName.equalsIgnoreCase("DefaultValue")) 229 vo.DefaultValue = rs.getString (i); 230 else if (columnName.equalsIgnoreCase("IsMandatory")) 231 vo.IsMandatory = "Y".equals(rs.getString (i)); 232 else if (columnName.equalsIgnoreCase("IsReadOnly")) 233 vo.IsReadOnly = "Y".equals(rs.getString (i)); 234 else if (columnName.equalsIgnoreCase("IsUpdateable")) 235 vo.IsUpdateable = "Y".equals(rs.getString (i)); 236 else if (columnName.equalsIgnoreCase("IsHeading")) 237 vo.IsHeading = "Y".equals(rs.getString (i)); 238 else if (columnName.equalsIgnoreCase("IsFieldOnly")) 239 vo.IsFieldOnly = "Y".equals(rs.getString (i)); 240 else if (columnName.equalsIgnoreCase("IsEncryptedField")) 241 vo.IsEncryptedField = "Y".equals(rs.getString (i)); 242 else if (columnName.equalsIgnoreCase("IsSelectionColumn")) 243 vo.IsSelectionColumn = "Y".equals(rs.getString (i)); 244 else if (columnName.equalsIgnoreCase("SortNo")) 245 vo.SortNo = rs.getInt (i); 246 else if (columnName.equalsIgnoreCase("FieldLength")) 247 vo.FieldLength = rs.getInt (i); 248 else if (columnName.equalsIgnoreCase("VFormat")) 249 vo.VFormat = rs.getString (i); 250 else if (columnName.equalsIgnoreCase("ValueMin")) 251 vo.ValueMin = rs.getString (i); 252 else if (columnName.equalsIgnoreCase("ValueMax")) 253 vo.ValueMax = rs.getString (i); 254 else if (columnName.equalsIgnoreCase("FieldGroup")) 255 vo.FieldGroup = rs.getString (i); 256 else if (columnName.equalsIgnoreCase("IsKey")) 257 vo.IsKey = "Y".equals(rs.getString (i)); 258 else if (columnName.equalsIgnoreCase("IsParent")) 259 vo.IsParent = "Y".equals(rs.getString (i)); 260 else if (columnName.equalsIgnoreCase("Description")) 261 vo.Description = rs.getString (i); 262 else if (columnName.equalsIgnoreCase("Help")) 263 vo.Help = rs.getString (i); 264 else if (columnName.equalsIgnoreCase("Callout")) 265 vo.Callout = rs.getString (i); 266 else if (columnName.equalsIgnoreCase("AD_Process_ID")) 267 vo.AD_Process_ID = rs.getInt (i); 268 else if (columnName.equalsIgnoreCase("ReadOnlyLogic")) 269 vo.ReadOnlyLogic = rs.getString (i); 270 else if (columnName.equalsIgnoreCase("AD_Reference_Value_ID")) 272 vo.AD_Reference_Value_ID = rs.getInt(i); 273 else if (columnName.equalsIgnoreCase("ValidationCode")) 274 vo.ValidationCode = rs.getString(i); 275 } 276 if (vo.Header == null) 277 vo.Header = vo.ColumnName; 278 } 279 catch (SQLException e) 280 { 281 Log.error ("MFieldVO.create", e); 282 return null; 283 } 284 vo.initFinish(); 285 return vo; 286 } 288 295 public static MFieldVO createParameter (Properties ctx, int WindowNo, ResultSet rs) 296 { 297 MFieldVO vo = new MFieldVO (ctx, WindowNo, 0, 0, false); 298 vo.isProcess = true; 299 vo.IsDisplayed = true; 300 vo.IsReadOnly = false; 301 vo.IsUpdateable = true; 302 303 try 304 { 305 vo.AD_Column_ID = rs.getInt("AD_Process_Para_ID"); vo.ColumnName = rs.getString("ColumnName"); 307 vo.Header = rs.getString("Name"); 308 vo.Description = rs.getString("Description"); 309 vo.Help = rs.getString("Help"); 310 vo.displayType = rs.getInt("AD_Reference_ID"); 311 vo.IsMandatory = rs.getString("IsMandatory").equals("Y"); 312 vo.FieldLength = rs.getInt("FieldLength"); 313 vo.DisplayLength = vo.FieldLength; 314 vo.DefaultValue = rs.getString("DefaultValue"); 315 vo.DefaultValue2 = rs.getString("DefaultValue2"); 316 vo.VFormat = rs.getString("VFormat"); 317 vo.ValueMin = rs.getString("ValueMin"); 318 vo.ValueMax = rs.getString("ValueMax"); 319 vo.isRange = rs.getString("IsRange").equals("Y"); 320 vo.AD_Reference_Value_ID = rs.getInt("AD_Reference_Value_ID"); 322 vo.ValidationCode = rs.getString("ValidationCode"); 323 } 324 catch (SQLException e) 325 { 326 Log.error ("MFieldVO.createParameter", e); 327 } 328 vo.initFinish(); 330 if (vo.DefaultValue2 == null) 331 vo.DefaultValue2 = ""; 332 return vo; 333 } 335 340 public static MFieldVO createParameter (MFieldVO voF) 341 { 342 MFieldVO voT = new MFieldVO (voF.ctx, voF.WindowNo, voF.TabNo, voF.AD_Window_ID, voF.tabReadOnly); 343 voT.isProcess = true; 344 voT.IsDisplayed = true; 345 voT.IsReadOnly = false; 346 voT.IsUpdateable = true; 347 voT.AD_Column_ID = voF.AD_Column_ID; voT.ColumnName = voF.ColumnName; 350 voT.Header = voF.Header; 351 voT.Description = voF.Description; 352 voT.Help = voF.Help; 353 voT.displayType = voF.displayType; 354 voT.IsMandatory = voF.IsMandatory; 355 voT.FieldLength = voF.FieldLength; 356 voT.DisplayLength = voF.FieldLength; 357 voT.DefaultValue = voF.DefaultValue2; 358 voT.VFormat = voF.VFormat; 359 voT.ValueMin = voF.ValueMin; 360 voT.ValueMax = voF.ValueMax; 361 voT.isRange = voF.isRange; 362 return voT; 364 } 366 367 375 public static MFieldVO createRowID (Properties ctx, int WindowNo, int TabNo, int AD_Window_ID) 376 { 377 MFieldVO vo = new MFieldVO (ctx, WindowNo, TabNo, AD_Window_ID, true); 378 vo.initRowID(); 379 vo.initFinish(); 380 return vo; 381 } 383 394 public static MFieldVO createStdField (Properties ctx, int WindowNo, int TabNo, int AD_Window_ID, boolean tabReadOnly, 395 boolean isCreated, boolean isTimestamp) 396 { 397 MFieldVO vo = new MFieldVO (ctx, WindowNo, TabNo, AD_Window_ID, tabReadOnly); 398 vo.ColumnName = isCreated ? "Created" : "Updated"; 399 if (!isTimestamp) 400 vo.ColumnName += "By"; 401 vo.displayType = isTimestamp ? DisplayType.DateTime : DisplayType.Integer; 402 vo.IsDisplayed = false; 403 vo.IsMandatory = false; 404 vo.IsReadOnly = false; 405 vo.IsUpdateable = true; 406 vo.initFinish(); 407 return vo; 408 } 410 } | Popular Tags |