1 14 package org.compiere.apps.form; 15 16 import java.awt.BorderLayout ; 17 import java.awt.Cursor ; 18 import java.awt.GridBagConstraints ; 19 import java.awt.GridBagLayout ; 20 import java.awt.Insets ; 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.VetoableChangeListener ; 25 import java.sql.PreparedStatement ; 26 import java.sql.ResultSet ; 27 import java.sql.SQLException ; 28 import java.sql.Timestamp ; 29 import java.util.Properties ; 30 31 import javax.swing.JLabel ; 32 33 import org.compiere.apps.AEnv; 34 import org.compiere.apps.AWindow; 35 import org.compiere.apps.ConfirmPanel; 36 import org.compiere.apps.StatusBar; 37 import org.compiere.grid.GridController; 38 import org.compiere.grid.ed.VDate; 39 import org.compiere.grid.ed.VLocator; 40 import org.compiere.grid.ed.VLookup; 41 import org.compiere.model.MLocatorLookup; 42 import org.compiere.model.MLookup; 43 import org.compiere.model.MLookupFactory; 44 import org.compiere.model.MQuery; 45 import org.compiere.model.MTab; 46 import org.compiere.model.MWindow; 47 import org.compiere.model.MWindowVO; 48 import org.compiere.plaf.CompiereColor; 49 import org.compiere.swing.CPanel; 50 import org.compiere.util.DB; 51 import org.compiere.util.DisplayType; 52 import org.compiere.util.Env; 53 import org.compiere.util.Log; 54 import org.compiere.util.Msg; 55 56 62 public class VTrxMaterial extends CPanel 63 implements FormPanel, ActionListener , VetoableChangeListener 64 { 65 68 public VTrxMaterial() 69 { 70 } 72 73 private int m_WindowNo = 0; 74 75 private FormFrame m_frame; 76 77 78 private GridController m_gridController = null; 79 80 private MWindow m_mWindow = null; 81 82 private MTab m_mTab = null; 83 84 private MQuery m_staticQuery = null; 85 private CPanel mainPanel = new CPanel(); 87 private BorderLayout mainLayout = new BorderLayout (); 88 private CPanel parameterPanel = new CPanel(); 89 private JLabel orgLabel = new JLabel (); 90 private VLookup orgField; 91 private JLabel locatorLabel = new JLabel (); 92 private VLocator locatorField; 93 private JLabel productLabel = new JLabel (); 94 private VLookup productField; 95 private JLabel dateFLabel = new JLabel (); 96 private VDate dateFField; 97 private JLabel dateTLabel = new JLabel (); 98 private VDate dateTField; 99 private JLabel mtypeLabel = new JLabel (); 100 private VLookup mtypeField; 101 private GridBagLayout parameterLayout = new GridBagLayout (); 102 private CPanel southPanel = new CPanel(); 103 private BorderLayout southLayout = new BorderLayout (); 104 private ConfirmPanel confirmPanel = new ConfirmPanel(true, true, false, false, false, true, true); 105 private StatusBar statusBar = new StatusBar(); 106 107 108 113 public void init (int WindowNo, FormFrame frame) 114 { 115 Log.trace(Log.l1_User, "VTrxMaterial.init"); 116 m_WindowNo = WindowNo; 117 m_frame = frame; 118 try 119 { 120 dynParameter(); 121 jbInit(); 122 dynInit(); 123 frame.getContentPane().add(mainPanel, BorderLayout.CENTER); 124 frame.getContentPane().add(statusBar, BorderLayout.SOUTH); 125 } 126 catch(Exception ex) 127 { 128 Log.error("VTrxMaterial.init", ex); 129 } 130 } 132 133 137 void jbInit() throws Exception 138 { 139 CompiereColor.setBackground(this); 140 mainPanel.setLayout(mainLayout); 141 mainLayout.setVgap(10); 142 parameterPanel.setLayout(parameterLayout); 143 orgLabel.setText(Msg.translate(Env.getCtx(), "AD_Org_ID")); 145 locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); 146 productLabel.setText(Msg.translate(Env.getCtx(), "M_Product_ID")); 147 dateFLabel.setText(Msg.translate(Env.getCtx(), "DateFrom")); 148 dateTLabel.setText(Msg.translate(Env.getCtx(), "DateTo")); 149 mtypeLabel.setText(Msg.translate(Env.getCtx(), "MovementType")); 150 mainPanel.add(parameterPanel, BorderLayout.NORTH); 152 parameterPanel.add(orgLabel, new GridBagConstraints (0, 0, 1, 1, 0.0, 0.0 153 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 5, 0, 5), 0, 0)); 154 parameterPanel.add(orgField, new GridBagConstraints (1, 0, 1, 1, 0.0, 0.0 155 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (5, 0, 0, 5), 0, 0)); 156 parameterPanel.add(mtypeLabel, new GridBagConstraints (2, 0, 1, 1, 0.0, 0.0 157 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 5, 0, 5), 0, 0)); 158 parameterPanel.add(mtypeField, new GridBagConstraints (3, 0, 1, 1, 0.0, 0.0 159 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (5, 0, 0, 5), 0, 0)); 160 parameterPanel.add(dateFLabel, new GridBagConstraints (4, 0, 1, 1, 0.0, 0.0 161 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 5, 0, 5), 0, 0)); 162 parameterPanel.add(dateFField, new GridBagConstraints (5, 0, 1, 1, 0.0, 0.0 163 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (5, 0, 0, 5), 0, 0)); 164 165 parameterPanel.add(locatorLabel, new GridBagConstraints (0, 1, 1, 1, 0.0, 0.0 166 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 5, 0, 5), 0, 0)); 167 parameterPanel.add(locatorField, new GridBagConstraints (1, 1, 1, 1, 0.0, 0.0 168 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (5, 0, 0, 5), 0, 0)); 169 parameterPanel.add(productLabel, new GridBagConstraints (2, 1, 1, 1, 0.0, 0.0 170 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 5, 0, 5), 0, 0)); 171 parameterPanel.add(productField, new GridBagConstraints (3, 1, 1, 1, 0.0, 0.0 172 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (5, 0, 0, 5), 0, 0)); 173 parameterPanel.add(dateTLabel, new GridBagConstraints (4, 1, 1, 1, 0.0, 0.0 174 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 5, 0, 5), 0, 0)); 175 parameterPanel.add(dateTField, new GridBagConstraints (5, 1, 1, 1, 0.0, 0.0 176 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (5, 0, 0, 5), 0, 0)); 177 southPanel.setLayout(southLayout); 179 southPanel.add(confirmPanel, BorderLayout.NORTH); 180 southPanel.add(statusBar, BorderLayout.SOUTH); 181 mainPanel.add(southPanel, BorderLayout.SOUTH); 182 } 184 188 private void dynParameter() throws Exception 189 { 190 Properties ctx = Env.getCtx(); 191 MLookup orgLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3660, DisplayType.TableDir); 193 orgField = new VLookup("AD_Org_ID", false, false, true, orgLookup, DisplayType.TableDir, m_WindowNo); 194 MLocatorLookup locatorLookup = new MLocatorLookup(ctx, m_WindowNo); 197 locatorField = new VLocator ("M_Locator_ID", false, false, true, locatorLookup, m_WindowNo); 198 MLookup productLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3668, DisplayType.Search); 201 productField = new VLookup("M_Product_ID", false, false, true, productLookup, DisplayType.Search, m_WindowNo); 202 productField.addVetoableChangeListener(this); 203 MLookup mtypeLookup = MLookupFactory.get (ctx, m_WindowNo, 0, 3666, DisplayType.List); 205 mtypeField = new VLookup("MovementType", false, false, true, mtypeLookup, DisplayType.List, m_WindowNo); 206 dateFField = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateFrom")); 208 dateTField = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.getMsg(Env.getCtx(), "DateTo")); 209 confirmPanel.addActionListener(this); 211 statusBar.setStatusLine(""); 212 } 214 217 private void dynInit() 218 { 219 m_staticQuery = new MQuery(); 220 m_staticQuery.addRestriction("AD_Client_ID", MQuery.EQUAL, Env.getContextAsInt(Env.getCtx(), "#AD_Client_ID")); 221 MWindowVO wVO = AEnv.getMWindowVO (m_WindowNo, 223, 0); 222 if (wVO == null) 223 return; 224 m_mWindow = new MWindow (wVO); 225 m_mTab = m_mWindow.getTab(0); 226 m_gridController = new GridController(); 228 m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null); 229 mainPanel.add(m_gridController, BorderLayout.CENTER); 230 m_mTab.setQuery(MQuery.getEqualQuery("1", "2")); 232 m_mTab.query(false); 233 statusBar.setStatusLine(" ", false); 234 statusBar.setStatusDB(" "); 235 } 237 238 241 public void dispose() 242 { 243 if (m_gridController != null) 244 m_gridController.dispose(); 245 m_gridController = null; 246 m_mTab = null; 247 if (m_mWindow != null) 248 m_mWindow.dispose(); 249 m_mWindow = null; 250 251 orgField = null; 252 locatorField = null; 253 productField = null; 254 mtypeField = null; 255 dateFField = null; 256 dateTField = null; 257 m_frame.dispose(); 259 } 261 262 263 267 public void actionPerformed (ActionEvent e) 268 { 269 if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 270 dispose(); 271 else if (e.getActionCommand().equals(ConfirmPanel.A_REFRESH) 272 || e.getActionCommand().equals(ConfirmPanel.A_OK)) 273 refresh(); 274 else if (e.getActionCommand().equals(ConfirmPanel.A_ZOOM)) 275 zoom(); 276 } 278 279 280 284 public void vetoableChange (PropertyChangeEvent e) 285 { 286 if (e.getPropertyName().equals("M_Product_ID")) 287 productField.setValue(e.getNewValue()); 288 } 290 291 292 293 296 private void refresh() 297 { 298 301 MQuery query = m_staticQuery.deepCopy(); 302 Object value = orgField.getValue(); 304 if (value != null && value.toString().length() > 0) 305 query.addRestriction("AD_Org_ID", MQuery.EQUAL, value); 306 value = locatorField.getValue(); 308 if (value != null && value.toString().length() > 0) 309 query.addRestriction("M_Locator_ID", MQuery.EQUAL, value); 310 value = productField.getValue(); 312 if (value != null && value.toString().length() > 0) 313 query.addRestriction("M_Product_ID", MQuery.EQUAL, value); 314 value = mtypeField.getValue(); 316 if (value != null && value.toString().length() > 0) 317 query.addRestriction("MovementType", MQuery.EQUAL, value); 318 Timestamp ts = (Timestamp )dateFField.getValue(); 320 if (ts != null) 321 query.addRestriction("TRUNC(MovementDate)", MQuery.GREATER_EQUAL, ts); 322 ts = (Timestamp )dateTField.getValue(); 324 if (ts != null) 325 query.addRestriction("TRUNC(MovementDate)", MQuery.LESS_EQUAL, ts); 326 Log.trace(Log.l1_User, "VTrxMaterial.refresh query=" + query.toString()); 327 328 331 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 332 statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "StartSearch"), false); 333 m_mTab.setQuery(query); 335 m_mTab.query(false); 336 setCursor(Cursor.getDefaultCursor()); 338 int no = m_mTab.getRowCount(); 339 statusBar.setStatusLine(" ", false); 340 statusBar.setStatusDB(Integer.toString(no)); 341 } 343 346 private void zoom() 347 { 348 Log.trace(Log.l1_User, "VTrxMaterial.zoom"); 349 int AD_Window_ID = 0; 351 String ColumnName = null; 352 String SQL = null; 353 boolean isSOTrx = false; 354 int lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InOutLine_ID"); 356 if (lineID != 0) 357 { 358 Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_InOutLine_ID=" + lineID); 359 if (Env.getContext(Env.getCtx(), m_WindowNo, "MovementType").startsWith("C")) 360 { 361 AD_Window_ID = 169; isSOTrx = true; 363 } 364 else 365 { 366 AD_Window_ID = 184; isSOTrx = false; 368 } 369 ColumnName = "M_InOut_ID"; 370 SQL = "SELECT M_InOut_ID FROM M_InOutLine WHERE M_InOutLine_ID=?"; 371 } 372 else 373 { 374 lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_InventoryLine_ID"); 375 if (lineID != 0) 376 { 377 Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_InventoryLine_ID=" + lineID); 378 AD_Window_ID = 168; 379 ColumnName = "M_Inventory_ID"; 380 SQL = "SELECT M_Inventory_ID FROM M_InventoryLine WHERE M_InventoryLine_ID=?"; 381 } 382 else 383 { 384 lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_MovementLine_ID"); 385 if (lineID != 0) 386 { 387 Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_MovementLine_ID=" + lineID); 388 AD_Window_ID = 170; 389 ColumnName = "M_Movement_ID"; 390 SQL = "SELECT M_Movement_ID FROM M_MovementLine WHERE M_MovementLine_ID=?"; 391 } 392 else 393 { 394 lineID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductionLine_ID"); 395 if (lineID != 0) 396 { 397 Log.trace(Log.l6_Database, "VTrxMaterial.zoom - M_ProductionLine_ID=" + lineID); 398 AD_Window_ID = 191; 399 ColumnName = "M_Production_ID"; 400 SQL = "SELECT M_Production_ID FROM M_ProductionLine WHERE M_ProductionLine_ID=?"; 401 } 402 else 403 Log.trace(Log.l6_Database, "VTrxMaterial.zoom - not found WindowNo=" + m_WindowNo); 404 } 405 } 406 } 407 if (AD_Window_ID == 0) 408 return; 409 410 int parentID = 0; 412 try 413 { 414 PreparedStatement pstmt = DB.prepareStatement(SQL); 415 pstmt.setInt(1, lineID); 416 ResultSet rs = pstmt.executeQuery(); 417 if (rs.next()) 418 parentID = rs.getInt(1); 419 rs.close(); 420 pstmt.close(); 421 } 422 catch (SQLException e) 423 { 424 Log.error ("VTrxMaterial.zoom - " + SQL, e); 425 } 426 MQuery query = MQuery.getEqualQuery(ColumnName, parentID); 427 Log.trace(Log.l2_Sub, "Zoom: AD_Window_ID=" + AD_Window_ID + " - " + query); 428 if (parentID == 0) 429 Log.error("VTrxMaterial.zoom - No ParentValue - " + SQL + " - " + lineID); 430 431 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 433 AWindow frame = new AWindow(); 434 if (!frame.initWindow(AD_Window_ID, query, isSOTrx)) 435 { 436 setCursor(Cursor.getDefaultCursor()); 437 return; 438 } 439 AEnv.showCenterScreen(frame); 440 frame = null; 441 setCursor(Cursor.getDefaultCursor()); 442 } 444 } | Popular Tags |