1 14 package org.compiere.print; 15 16 import java.math.*; 17 import java.sql.*; 18 19 import org.compiere.model.MLocation; 20 import org.compiere.util.*; 21 22 28 public class PrintDataElement 29 { 30 38 public PrintDataElement (String columnName, Object value, int displayType, boolean isPKey, boolean isPageBreak) 39 { 40 if (columnName == null) 41 throw new IllegalArgumentException ("PrintDataElement - Name cannot be null"); 42 m_columnName = columnName; 43 m_value = value; 44 m_displayType = displayType; 45 m_isPKey = isPKey; 46 m_isPageBreak = isPageBreak; 47 } 49 55 public PrintDataElement(String columnName, Object value, int displayType) 56 { 57 this (columnName, value, displayType, false, false); 58 } 60 61 private String m_columnName; 62 63 private Object m_value; 64 65 private int m_displayType; 66 67 private boolean m_isPKey; 68 69 private boolean m_isPageBreak; 70 71 72 73 public static final String XML_TAG = "element"; 74 75 public static final String XML_ATTRIBUTE_NAME = "name"; 76 77 public static final String XML_ATTRIBUTE_KEY = "key"; 78 79 80 84 public String getColumnName() 85 { 86 return m_columnName; 87 } 89 93 public Object getValue() 94 { 95 return m_value; 96 } 98 102 public BigDecimal getFunctionValue() 103 { 104 if (m_value == null) 105 return Env.ZERO; 106 107 if (m_value instanceof BigDecimal) 109 return (BigDecimal)m_value; 110 if (m_value instanceof Number ) 111 return new BigDecimal(((Number )m_value).doubleValue()); 112 113 if (m_value instanceof Boolean ) 115 { 116 if (((Boolean )m_value).booleanValue()) 117 return Env.ONE; 118 else 119 return Env.ZERO; 120 } 121 122 String s = m_value.toString(); 124 return new BigDecimal(s.length()); 125 } 127 132 public String getValueDisplay (Language language) 133 { 134 if (m_value == null) 135 return ""; 136 String retValue = m_value.toString(); 137 if (m_displayType == DisplayType.Location) 138 return getValueDisplay_Location(); 139 else if (m_columnName.equals("C_BPartner_Location_ID") || m_columnName.equals("BillTo_ID")) 140 return getValueDisplay_BPLocation(); 141 else if (m_displayType == 0 || m_value instanceof String || m_value instanceof NamePair) 142 ; 143 else if (language != null) { 145 if (DisplayType.isNumeric(m_displayType)) 146 retValue = DisplayType.getNumberFormat(m_displayType, language).format(m_value); 147 else if (DisplayType.isDate(m_displayType)) 148 retValue = DisplayType.getDateFormat(m_displayType, language).format(m_value); 149 } 150 return retValue; 151 } 153 157 private String getValueDisplay_BPLocation () 158 { 159 try 160 { 161 int C_BPartner_Location_ID = Integer.parseInt (getValueKey ()); 162 if (C_BPartner_Location_ID == 0) 163 return m_value.toString(); 164 MLocation loc = new MLocation (Env.getCtx(), 0); 166 loc.loadBPLocation (C_BPartner_Location_ID); 167 return loc.toStringCR(); 168 } 169 catch (Exception ex) 170 { 171 return m_value.toString(); 172 } 173 } 175 176 180 private String getValueDisplay_Location () 181 { 182 try 183 { 184 int C_Location_ID = Integer.parseInt (getValueKey ()); 185 if (C_Location_ID == 0) 186 return m_value.toString(); 187 MLocation loc = new MLocation (Env.getCtx(), 0); 189 loc.load(C_Location_ID); 190 return loc.toStringCR(); 191 } 192 catch (Exception ex) 193 { 194 return m_value.toString(); 195 } 196 } 198 199 203 public String getValueKey() 204 { 205 if (m_value == null) 206 return ""; 207 if (m_value instanceof NamePair) 208 return ((NamePair)m_value).getID(); 209 return ""; 210 } 212 216 public boolean isNull() 217 { 218 return m_value == null; 219 } 221 222 223 227 public int getDisplayType() 228 { 229 return m_displayType; 230 } 232 236 public boolean isNumeric() 237 { 238 if (m_displayType == 0) 239 return m_value instanceof BigDecimal; 240 return DisplayType.isNumeric(m_displayType); 241 } 243 247 public boolean isDate() 248 { 249 if (m_displayType == 0) 250 return m_value instanceof Timestamp; 251 return DisplayType.isDate(m_displayType); 252 } 254 258 public boolean isID() 259 { 260 return DisplayType.isID(m_displayType); 261 } 263 267 public boolean isYesNo() 268 { 269 if (m_displayType == 0) 270 return m_value instanceof Boolean ; 271 return DisplayType.YesNo == m_displayType; 272 } 274 278 public boolean isPKey() 279 { 280 return m_isPKey; 281 } 283 287 public boolean isPageBreak() 288 { 289 return m_isPageBreak; 290 } 292 293 294 298 public int hashCode() 299 { 300 if (m_value == null) 301 return m_columnName.hashCode(); 302 return m_columnName.hashCode() + m_value.hashCode(); 303 } 305 310 public boolean equals (Object compare) 311 { 312 if (compare instanceof PrintDataElement) 313 { 314 PrintDataElement pde = (PrintDataElement)compare; 315 if (pde.getColumnName().equals(m_columnName)) 316 { 317 if (pde.getValue() != null && pde.getValue().equals(m_value)) 318 return true; 319 if (pde.getValue() == null && m_value == null) 320 return true; 321 } 322 } 323 return false; 324 } 326 330 public String toString() 331 { 332 StringBuffer sb = new StringBuffer (m_columnName).append("=").append(m_value); 333 if (m_isPKey) 334 sb.append("(PK)"); 335 return sb.toString(); 336 } 338 342 public boolean hasKey() 343 { 344 return m_value instanceof NamePair; 345 } 347 351 public String dump() 352 { 353 if (m_value instanceof NamePair) 354 { 355 NamePair pp = (NamePair)m_value; 356 StringBuffer sb = new StringBuffer (m_columnName); 357 sb.append("(").append(pp.getID()).append(")") 358 .append("=").append(pp.getName()); 359 if (m_isPKey) 360 sb.append("(PK)"); 361 return sb.toString(); 362 } 363 else 364 return toString(); 365 } 367 }
| Popular Tags
|