1 14 package org.compiere.apps.search; 15 16 import java.sql.*; 17 import java.math.*; 18 import java.awt.*; 19 20 import org.compiere.apps.*; 21 import org.compiere.minigrid.*; 22 import org.compiere.plaf.*; 23 import org.compiere.swing.*; 24 import org.compiere.model.*; 25 import org.compiere.util.*; 26 27 33 public class InfoAsset extends Info 34 { 35 46 public InfoAsset (Frame frame, boolean modal, int WindowNo, 47 int A_Asset_ID, String value, 48 boolean multiSelection, String whereClause) 49 { 50 super (frame, modal, WindowNo, "a", "A_Asset_ID", multiSelection, whereClause); 51 Log.trace(Log.l1_User, "InfoAsset", value + ", ID=" + A_Asset_ID + ", WHERE=" + whereClause); 52 setTitle(Msg.getMsg(Env.getCtx(), "InfoAsset")); 53 statInit(); 55 initInfo (value, A_Asset_ID, whereClause); 56 int no = p_table.getRowCount(); 58 setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false); 59 setStatusDB(Integer.toString(no)); 60 if (value != null && value.length() > 0) 62 executeQuery(); 63 p_loadedOK = true; 64 67 AEnv.positionCenterWindow(frame, this); 68 } 70 71 private static String s_assetFROM = "A_ASSET a" 72 + " INNER JOIN M_Product p ON (a.M_Product_ID=p.M_Product_ID)" 73 + " LEFT OUTER JOIN C_BPartner bp ON (a.C_BPartner_ID=bp.C_BPartner_ID)" 74 + " LEFT OUTER JOIN AD_User u ON (a.AD_User_ID=u.AD_User_ID)"; 75 76 77 private static final Info_Column[] s_assetLayout = { 78 new Info_Column(" ", "a.A_Asset_ID", IDColumn.class), 79 new Info_Column(Msg.translate(Env.getCtx(), "Value"), "a.Value", String .class), 80 new Info_Column(Msg.translate(Env.getCtx(), "Name"), "a.Name", String .class), 81 new Info_Column(Msg.translate(Env.getCtx(), "M_Product_ID"), "p.Name", String .class), 82 new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"), "bp.Name", String .class), 83 new Info_Column(Msg.translate(Env.getCtx(), "AD_User_ID"), "u.Name", String .class), 84 new Info_Column(Msg.translate(Env.getCtx(), "AssetServiceDate"), "a.AssetServiceDate", Timestamp.class), 85 new Info_Column(Msg.translate(Env.getCtx(), "GuaranteeDate"), "a.GuaranteeDate", Timestamp.class), 86 new Info_Column(Msg.translate(Env.getCtx(), "VersionNo"), "a.VersionNo", String .class) 87 }; 88 89 private CLabel labelValue = new CLabel(); 91 private CTextField fieldValue = new CTextField(10); 92 private CLabel labelName = new CLabel(); 93 private CTextField fieldName = new CTextField(10); 94 95 98 private void statInit() 99 { 100 labelValue.setText(Msg.getMsg(Env.getCtx(), "Value")); 101 fieldValue.setBackground(CompierePLAF.getInfoBackground()); 102 fieldValue.addActionListener(this); 103 104 labelName.setText(Msg.getMsg(Env.getCtx(), "Name")); 105 fieldName.setBackground(CompierePLAF.getInfoBackground()); 106 fieldName.addActionListener(this); 107 108 parameterPanel.setLayout(new ALayout()); 110 parameterPanel.add(labelValue, new ALayoutConstraint(0,0)); 112 parameterPanel.add(fieldValue, null); 113 parameterPanel.add(labelName, new ALayoutConstraint(1,0)); 115 parameterPanel.add(fieldName, null); 116 } 118 123 private void initInfo (String value, int A_Asset_ID, String whereClause) 124 { 125 StringBuffer where = new StringBuffer (); 127 where.append("a.IsActive='Y'"); 128 if (whereClause != null && whereClause.length() > 0) 129 where.append(" AND ").append(whereClause); 130 prepareTable(s_assetLayout, s_assetFROM, 132 where.toString(), 133 "a.Value"); 134 135 if (value == null) 137 value = "%"; 138 if (!value.endsWith("%")) 139 value += "%"; 140 } 142 143 144 150 String getSQLWhere() 151 { 152 StringBuffer sql = new StringBuffer (); 153 String value = fieldValue.getText().toUpperCase(); 155 if (!(value.equals("") || value.equals("%"))) 156 sql.append(" AND UPPER(bp.Value) LIKE ?"); 157 String name = fieldName.getText().toUpperCase(); 159 if (!(name.equals("") || name.equals("%"))) 160 sql.append (" AND UPPER(bp.Name) LIKE ?"); 161 return sql.toString(); 163 } 165 173 void setParameters(PreparedStatement pstmt) throws SQLException 174 { 175 int index = 1; 176 String value = fieldValue.getText().toUpperCase(); 178 if (!(value.equals("") || value.equals("%"))) 179 { 180 if (!value.endsWith("%")) 181 value += "%"; 182 pstmt.setString(index++, value); 183 Log.trace(Log.l5_DData, "InfoAsset.setParameters", "Value: " + value); 184 } 185 String name = fieldName.getText().toUpperCase(); 187 if (!(name.equals("") || name.equals("%"))) 188 { 189 if (!name.endsWith("%")) 190 name += "%"; 191 pstmt.setString(index++, name); 192 Log.trace(Log.l5_DData, "InfoAsset.setParameters", "Name: " + name); 193 } 194 } 196 200 public void saveSelectionDetail() 201 { 202 int row = p_table.getSelectedRow(); 203 if (row == -1) 204 return; 205 206 Integer ID = getSelectedRowKey(); 208 Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "A_Asset_ID", ID == null ? "0" : ID.toString()); 209 } 211 212 213 214 217 void showHistory() 218 { 219 Log.trace(Log.l1_User, "InfoAsset.showHistory"); 220 } 222 226 boolean hasHistory() 227 { 228 return false; 229 } 231 234 void zoom() 235 { 236 Log.trace(Log.l1_User, "InfoAsset.zoom"); 237 Integer A_Asset_ID = getSelectedRowKey(); 238 if (A_Asset_ID == null) 239 return; 240 MQuery query = new MQuery("A_Asset"); 241 query.addRestriction("A_Asset_ID", MQuery.EQUAL, A_Asset_ID); 242 zoom (123, query); 243 } 245 249 boolean hasZoom() 250 { 251 return true; 252 } 254 257 void customize() 258 { 259 Log.trace(Log.l1_User, "InfoAsset.customize"); 260 } 262 266 boolean hasCustomize() 267 { 268 return false; } 271 } | Popular Tags |