1 14 package org.compiere.grid.ed; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 import java.sql.*; 20 21 import org.compiere.util.*; 22 import org.compiere.model.*; 23 import org.compiere.apps.*; 24 import org.compiere.plaf.*; 25 import org.compiere.swing.*; 26 27 33 public class VLocatorDialog extends JDialog implements ActionListener, KeyListener 34 { 35 44 public VLocatorDialog (Frame frame, String title, MLocatorLookup mLocator, 45 int M_Locator_ID, boolean mandatory, int only_Warehouse_ID) 46 { 47 super (frame, title, true); 48 m_WindowNo = Env.getWindowNo(frame); 49 try 50 { 51 jbInit(); 52 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 53 } 54 catch(Exception ex) 55 { 56 Log.error("VLocatorDialog", ex); 57 } 58 m_mLocator = mLocator; 60 m_M_Locator_ID = M_Locator_ID; 61 m_mandatory = mandatory; 62 m_only_Warehouse_ID = only_Warehouse_ID; 63 initLocator(); 65 AEnv.positionCenterWindow(frame, this); 66 } 68 private int m_WindowNo; 69 private boolean m_change = false; 70 private MLocatorLookup m_mLocator; 71 private int m_M_Locator_ID; 72 private boolean m_mandatory = false; 73 private int m_only_Warehouse_ID = 0; 74 private int m_M_Warehouse_ID; 76 private String m_M_WarehouseName; 77 private String m_M_WarehouseValue; 78 private String m_Separator; 79 private int m_AD_Client_ID; 80 private int m_AD_Org_ID; 81 private CPanel panel = new CPanel(); 83 private CPanel mainPanel = new CPanel(); 84 private CPanel southPanel = new CPanel(); 85 private BorderLayout panelLayout = new BorderLayout(); 86 private GridBagLayout gridBagLayout = new GridBagLayout(); 87 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 88 private BorderLayout southLayout = new BorderLayout(); 89 private VComboBox fLocator = new VComboBox(); 91 private CComboBox fWarehouse = new CComboBox(); 92 private JCheckBox fCreateNew = new JCheckBox(); 93 private CTextField fX = new CTextField(); 94 private CTextField fY = new CTextField(); 95 private CTextField fZ = new CTextField(); 96 private JLabel lLocator = new JLabel(); 97 private CTextField fWarehouseInfo = new CTextField(); 98 private CTextField fValue = new CTextField(); 99 private JLabel lWarehouseInfo = new JLabel(); 100 private JLabel lWarehouse = new JLabel(); 101 private JLabel lX = new JLabel(); 102 private JLabel lY = new JLabel(); 103 private JLabel lZ = new JLabel(); 104 private JLabel lValue = new JLabel(); 105 106 110 private void jbInit() throws Exception 111 { 112 CompiereColor.setBackground(this); 113 panel.setLayout(panelLayout); 114 southPanel.setLayout(southLayout); 115 mainPanel.setLayout(gridBagLayout); 116 panelLayout.setHgap(5); 117 panelLayout.setVgap(10); 118 fCreateNew.setText(Msg.getMsg(Env.getCtx(), "CreateNew")); 119 fX.setColumns(15); 120 fY.setColumns(15); 121 fZ.setColumns(15); 122 lLocator.setLabelFor(fLocator); 123 lLocator.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); 124 fWarehouseInfo.setBackground(CompierePLAF.getFieldBackground_Inactive()); 125 fWarehouseInfo.setReadWrite(false); 126 fWarehouseInfo.setColumns(15); 127 fValue.setColumns(15); 128 lWarehouseInfo.setLabelFor(fWarehouseInfo); 129 lWarehouseInfo.setText(Msg.translate(Env.getCtx(), "M_Warehouse_ID")); 130 lWarehouse.setLabelFor(fWarehouse); 131 lWarehouse.setText(Msg.translate(Env.getCtx(), "M_Warehouse_ID")); 132 lX.setLabelFor(fX); 133 lX.setText(Msg.getElement(Env.getCtx(), "X")); 134 lY.setLabelFor(fY); 135 lY.setText(Msg.getElement(Env.getCtx(), "Y")); 136 lZ.setLabelFor(fZ); 137 lZ.setText(Msg.getElement(Env.getCtx(), "Z")); 138 lValue.setLabelFor(fValue); 139 lValue.setText(Msg.translate(Env.getCtx(), "Value")); 140 getContentPane().add(panel); 141 panel.add(mainPanel, BorderLayout.CENTER); 142 mainPanel.add(lLocator, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 144 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 145 mainPanel.add(fLocator, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 146 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0)); 147 mainPanel.add(fCreateNew, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 148 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 5), 0, 0)); 149 mainPanel.add(lWarehouseInfo, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 150 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 151 mainPanel.add(fWarehouseInfo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 152 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0)); 153 mainPanel.add(lWarehouse, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 154 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 155 mainPanel.add(fWarehouse, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 156 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0)); 157 mainPanel.add(lX, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0 158 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 159 mainPanel.add(fX, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0 160 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0)); 161 mainPanel.add(lY, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 162 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 163 mainPanel.add(fY, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0 164 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0)); 165 mainPanel.add(lZ, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0 166 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 167 mainPanel.add(fZ, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0 168 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0)); 169 mainPanel.add(lValue, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0 170 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 171 mainPanel.add(fValue, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0 172 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0)); 173 panel.add(southPanel, BorderLayout.SOUTH); 175 southPanel.add(confirmPanel, BorderLayout.NORTH); 176 confirmPanel.addActionListener(this); 177 } 179 182 private void initLocator() 183 { 184 Log.trace(Log.l5_DData, "VLocatorDialog.initLocator"); 185 186 String sql = "SELECT M_Warehouse_ID, Name FROM M_Warehouse"; 188 if (m_only_Warehouse_ID != 0) 189 sql += " WHERE M_Warehouse_ID=" + m_only_Warehouse_ID; 190 String SQL = MRole.getDefault().addAccessSQL( 191 sql, "M_Warehouse", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO) 192 + " ORDER BY 2"; 193 try 194 { 195 PreparedStatement pstmt = DB.prepareStatement(SQL); 196 ResultSet rs = pstmt.executeQuery(); 197 while (rs.next()) 198 fWarehouse.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2))); 199 rs.close(); 200 pstmt.close(); 201 } 202 catch (SQLException e) 203 { 204 Log.error ("VLocatorDialog.initLoactor", e); 205 } 206 Log.trace(Log.l6_Database, "Warehouses=" + fWarehouse.getItemCount()); 207 208 m_mLocator.fillComboBox(m_mandatory, true, true, false); 210 Log.trace(Log.l6_Database, "initLocator", m_mLocator.toString()); 211 fLocator.setModel(m_mLocator); 212 fLocator.setValue(m_M_Locator_ID); 213 fLocator.addActionListener(this); 214 displayLocator(); 215 fCreateNew.setSelected(false); 217 fCreateNew.addActionListener(this); 218 enableNew(); 219 fWarehouse.addActionListener(this); 221 fX.addKeyListener(this); 222 fY.addKeyListener(this); 223 fZ.addKeyListener(this); 224 225 pack(); 227 } 229 230 231 232 236 public void actionPerformed(ActionEvent e) 237 { 238 Object source = e.getSource(); 239 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 241 { 242 actionOK(); 243 m_change = true; 244 dispose(); 245 } 246 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 247 { 248 m_change = false; 249 dispose(); 250 } 251 else if (e.getSource() == fLocator) 253 displayLocator(); 254 255 else if (source == fCreateNew) 257 enableNew(); 258 259 else if (fCreateNew.isSelected() && source == fWarehouse) 261 createValue(); 262 263 } 265 269 public void keyPressed(KeyEvent e) 270 {} 271 275 public void keyReleased(KeyEvent e) 276 { 277 if (fCreateNew.isSelected()) 278 createValue(); 279 } 280 284 public void keyTyped(KeyEvent e) 285 {} 286 287 290 private void displayLocator() 291 { 292 MLocator l = (MLocator) fLocator.getSelectedItem(); 293 if (l == null) 294 return; 295 m_M_Locator_ID = l.getM_Locator_ID(); 297 fWarehouseInfo.setText(l.getWarehouseName()); 298 fX.setText(l.getX()); 299 fY.setText(l.getY()); 300 fZ.setText(l.getZ()); 301 fValue.setText(l.getValue()); 302 getWarehouseInfo(l.getM_Warehouse_ID()); 303 int size = fWarehouse.getItemCount(); 305 for (int i = 0; i < size; i++) 306 { 307 KeyNamePair pp = (KeyNamePair)fWarehouse.getItemAt(i); 308 if (pp.getKey() == l.getM_Warehouse_ID()) 309 { 310 fWarehouse.setSelectedIndex(i); 311 continue; 312 } 313 } 314 } 316 319 private void enableNew() 320 { 321 boolean sel = fCreateNew.isSelected(); 322 lWarehouse.setVisible(sel); 323 fWarehouse.setVisible(sel); 324 lWarehouseInfo.setVisible(!sel); 325 fWarehouseInfo.setVisible(!sel); 326 fX.setReadWrite(sel); 327 fY.setReadWrite(sel); 328 fZ.setReadWrite(sel); 329 fValue.setReadWrite(sel); 330 pack(); 331 } 333 337 private void getWarehouseInfo (int M_Warehouse_ID) 338 { 339 if (M_Warehouse_ID == m_M_Warehouse_ID) 340 return; 341 m_M_Warehouse_ID = 0; 343 m_M_WarehouseName = ""; 344 m_M_WarehouseValue = ""; 345 m_Separator = "."; 346 m_AD_Client_ID = 0; 347 m_AD_Org_ID = 0; 348 String SQL = "SELECT M_Warehouse_ID, Value, Name, Separator, AD_Client_ID, AD_Org_ID " 350 + "FROM M_Warehouse WHERE M_Warehouse_ID=?"; 351 try 352 { 353 PreparedStatement pstmt = DB.prepareStatement(SQL); 354 pstmt.setInt(1, M_Warehouse_ID); 355 ResultSet rs = pstmt.executeQuery(); 356 if (rs.next()) 357 { 358 m_M_Warehouse_ID = rs.getInt(1); 359 m_M_WarehouseValue = rs.getString(2); 360 m_M_WarehouseName = rs.getString(3); 361 m_Separator = rs.getString(4); 362 m_AD_Client_ID = rs.getInt(5); 363 m_AD_Org_ID = rs.getInt(6); 364 } 365 rs.close(); 366 pstmt.close(); 367 } 368 catch (SQLException e) 369 { 370 Log.error ("VLocatorDialog.getWarehouseInfo", e); 371 } 372 } 374 377 private void createValue() 378 { 379 KeyNamePair pp = (KeyNamePair)fWarehouse.getSelectedItem(); 381 if (pp == null) 382 return; 383 getWarehouseInfo(pp.getKey()); 384 StringBuffer buf = new StringBuffer (m_M_WarehouseValue); 386 buf.append(m_Separator).append(fX.getText()); 387 buf.append(m_Separator).append(fY.getText()); 388 buf.append(m_Separator).append(fZ.getText()); 389 fValue.setText(buf.toString()); 390 } 392 395 private void actionOK() 396 { 397 if (fCreateNew.isSelected()) 398 { 399 KeyNamePair pp = (KeyNamePair)fWarehouse.getSelectedItem(); 401 if (pp != null) 402 getWarehouseInfo(pp.getKey()); 403 404 String mandatoryFields = ""; 406 if (m_M_Warehouse_ID == 0) 407 mandatoryFields += lWarehouse.getText() + " - "; 408 if (fValue.getText().length()==0) 409 mandatoryFields += lValue.getText() + " - "; 410 if (fX.getText().length()==0) 411 mandatoryFields += lX.getText() + " - "; 412 if (fY.getText().length()==0) 413 mandatoryFields += lY.getText() + " - "; 414 if (fZ.getText().length()==0) 415 mandatoryFields += lZ.getText() + " - "; 416 if (mandatoryFields.length() != 0) 417 { 418 ADialog.error(m_WindowNo, this, "FillMandatory", mandatoryFields.substring(0, mandatoryFields.length()-3)); 419 return; 420 } 421 422 MLocator loc = MLocator.get(Env.getCtx(), m_M_Warehouse_ID, fValue.getText(), 423 fX.getText(), fY.getText(), fZ.getText()); 424 m_M_Locator_ID = loc.getM_Locator_ID(); 425 fLocator.addItem(loc); 426 fLocator.setSelectedItem(loc); 427 } Log.trace(Log.l4_Data, "VLocationDialog.actionOK - M_Locator_ID=" + m_M_Locator_ID); 430 } 432 436 public Integer getValue() 437 { 438 MLocator l = (MLocator) fLocator.getSelectedItem(); 439 if (l != null && l.getM_Locator_ID() != 0) 440 return new Integer (l.getM_Locator_ID()); 441 return null; 442 } 444 448 public boolean isChanged() 449 { 450 if (m_change) 451 { 452 MLocator l = (MLocator) fLocator.getSelectedItem(); 453 if (l != null) 454 return l.getM_Locator_ID() == m_M_Locator_ID; 455 } 456 return m_change; 457 } 459 } | Popular Tags |