1 package sellwin.gui; 2 3 import sellwin.domain.*; 4 import sellwin.utils.*; 5 6 import javax.swing.*; 7 import javax.swing.border.*; 8 import java.awt.*; 9 import java.util.*; 10 import java.text.*; 11 import javax.swing.event.*; 12 import java.awt.event.*; 13 14 18 25 public class CustAdminDialog extends javax.swing.JDialog 26 implements InventoryListener, GUIChars { 27 28 private Whiteboard wb=null; 29 private JDialog thisDialog=null; 30 private Customer currentCustomer=new Customer(); 31 32 private ProductSelectionDialog addProductSelectionDialog=null; 33 34 private JPanel mainPanel; 35 private JScrollPane custScrollPane; 36 private JPanel custPanel; 37 private JScrollPane custListScrollPane; 38 private JList custList; 39 private JLabel custLabel; 40 private JTextField custField; 41 private JLabel annualSalesLabel; 42 private JTextField annualSalesField; 43 private JLabel industryLabel; 44 private JTextField industryField; 45 private JLabel channelLabel; 46 private JTextField channelField; 47 private JLabel inventoryLabel; 48 private JTabbedPane tabbedPane = new JTabbedPane(); 49 private JScrollPane inventoryScrollPane; 50 private JPanel inventoryPanel; 51 private JTable inventoryTable; 52 private AddressPanel contactAddressPanel; 53 private AddressPanel shipAddressPanel; 54 private AddressPanel billAddressPanel; 55 private JPanel buttonPanel; 56 private JButton applyButton; 57 private JButton clearButton; 58 private JButton closeButton; 59 private JPopupMenu custPopup; 60 private JPopupMenu invPopup; 61 private JMenuItem addCustMenuItem; 62 private JMenuItem deleteCustMenuItem; 63 private JMenuItem addInvMenuItem; 64 private JMenuItem deleteInvMenuItem; 65 66 private ProductTableModel inventoryModel = null; 67 private TreeMap customerNames=null; 68 private DefaultListModel custListModel=null; 69 70 private Customer screenCust = new Customer(); 71 72 private final NumberFormat format = NumberFormat.getInstance(); 73 74 79 public CustAdminDialog(java.awt.Frame parent, boolean modal) { 80 81 super(parent, modal); 82 wb = MainWindow.getWhiteboard(); 83 84 85 thisDialog = this; 86 87 initComponents(); 88 setFonts(); 89 setColors(); 90 91 inventoryScrollPane.addMouseListener(new MouseAdapter() { 92 public void mousePressed(MouseEvent e) { 93 if (e.isPopupTrigger()) 94 invPopup.show(inventoryTable, e.getX(), e.getY()); 95 } 96 public void mouseReleased(MouseEvent e) { 97 if (e.isPopupTrigger()) 98 invPopup.show(inventoryTable, e.getX(), e.getY()); 99 } 100 public void mouseClicked(MouseEvent e) { 101 if (e.isPopupTrigger()) 102 invPopup.show(inventoryTable, e.getX(), e.getY()); 103 } 104 }); 105 106 inventoryTable.addMouseListener(new MouseAdapter() { 107 public void mousePressed(MouseEvent e) { 108 if (e.isPopupTrigger()) 109 invPopup.show(inventoryTable, e.getX(), e.getY()); 110 } 111 public void mouseReleased(MouseEvent e) { 112 if (e.isPopupTrigger()) 113 invPopup.show(inventoryTable, e.getX(), e.getY()); 114 } 115 public void mouseClicked(MouseEvent e) { 116 if (e.isPopupTrigger()) 117 invPopup.show(inventoryTable, e.getX(), e.getY()); 118 } 119 }); 120 121 inventoryTable.getTableHeader().addMouseListener(new MouseAdapter() { 122 public void mousePressed(MouseEvent e) { 123 if (e.isPopupTrigger()) 124 invPopup.show(inventoryTable, e.getX(), e.getY()); 125 } 126 public void mouseReleased(MouseEvent e) { 127 if (e.isPopupTrigger()) 128 invPopup.show(inventoryTable, e.getX(), e.getY()); 129 } 130 public void mouseClicked(MouseEvent e) { 131 if (e.isPopupTrigger()) 132 invPopup.show(inventoryTable, e.getX(), e.getY()); 133 } 134 }); 135 136 custList.addMouseListener(new MouseAdapter() { 137 public void mousePressed(MouseEvent e) { 138 if (e.isPopupTrigger()) 139 custPopup.show(custList, e.getX(), e.getY()); 140 } 141 public void mouseReleased(MouseEvent e) { 142 if (e.isPopupTrigger()) 143 custPopup.show(custList, e.getX(), e.getY()); 144 } 145 public void mouseClicked(MouseEvent e) { 146 if (e.isPopupTrigger()) 147 custPopup.show(custList, e.getX(), e.getY()); 148 } 149 }); 150 151 deleteCustMenuItem.addActionListener( 152 new ActionListener() { 153 public void actionPerformed(ActionEvent e) { 154 String v = (String )(custList.getSelectedValue()); 155 int opt = JOptionPane.showConfirmDialog(thisDialog, wb.getLang().getString("deleteQuestion")+ " " +v + " ?"); 156 if (opt == JOptionPane.YES_OPTION) { 157 try { 158 wb.deleteCustomer(v); 159 customerNames.remove(v); 160 updateCustList(null); 161 JOptionPane.showMessageDialog( 162 thisDialog, 163 wb.getLang().getString("deleteNotify"), 164 wb.getLang().getString("info"), 165 JOptionPane.INFORMATION_MESSAGE); 166 } catch (AngError x) { 167 ErrorHandler.show(thisDialog, x); 168 } 169 } 170 } 171 } 172 ); 173 174 addCustMenuItem.addActionListener( 175 new ActionListener() { 176 public void actionPerformed(ActionEvent e) { 177 currentCustomer = new Customer(); 178 String v = JOptionPane.showInputDialog(wb.getLang().getString("enterCust")); 179 if ((v == null) || (v.length() == 0)) return; 180 181 try { 182 currentCustomer.setName(v); 183 currentCustomer.setPK(wb.addCustomer(currentCustomer)); 184 wb.addCustName(currentCustomer.getName()); 185 clearFields(); 186 updateCustList(v); 187 JOptionPane.showMessageDialog( 188 thisDialog, 189 wb.getLang().getString("custAddNotify"), 190 wb.getLang().getString("info"), 191 JOptionPane.INFORMATION_MESSAGE); 192 } catch (AngError x) { 193 ErrorHandler.show(thisDialog, x); 194 } 195 } 196 } 197 ); 198 199 closeButton.addActionListener( 200 new ActionListener() { 201 public void actionPerformed(ActionEvent e) { 202 thisDialog.hide(); 203 } 204 } 205 ); 206 207 applyButton.addActionListener( 208 new ActionListener() { 209 public void actionPerformed(ActionEvent e) { 210 String cname = (String )(custList.getSelectedValue()); 211 Customer c = getCustomer(); 212 int opt = JOptionPane.showConfirmDialog(thisDialog, wb.getLang().getString("updateQuestion")+ " " +cname + " ?"); 213 if (opt == JOptionPane.YES_OPTION) { 214 try { 215 copyFields(currentCustomer, c); 216 217 wb.updateCustomer(currentCustomer); 218 219 JOptionPane.showMessageDialog( 220 thisDialog, 221 wb.getLang().getString("updateNotify"), 222 wb.getLang().getString("info"), 223 JOptionPane.INFORMATION_MESSAGE); 224 } catch (AngError x) { 225 ErrorHandler.show(thisDialog, x); 226 } 227 } 228 } 229 } 230 ); 231 232 clearButton.addActionListener( 233 new ActionListener() { 234 public void actionPerformed(ActionEvent e) { 235 clear(); 236 } 237 } 238 ); 239 240 custList.addMouseListener( 241 new MouseAdapter() { 242 public void mouseClicked(MouseEvent e) { 243 if (e.getClickCount() == 1) { 244 String value = (String )custList.getSelectedValue(); 245 if (value == null) return; 246 try { 247 currentCustomer = wb.getCustomer((String )(customerNames.get(value))); 248 setCustomer(currentCustomer); 249 } catch (AngError x) { 250 ErrorHandler.show(thisDialog, x); 251 } 252 } 253 } 254 } 255 ); 256 257 deleteInvMenuItem.addActionListener( 258 new ActionListener() { 259 public void actionPerformed(ActionEvent e) { 260 int opt = JOptionPane.showConfirmDialog(thisDialog, wb.getLang().getString("deleteInvQuestion")); 261 if (opt != JOptionPane.YES_OPTION) return; 262 263 int i = inventoryTable.getSelectedRow(); 264 ArrayList inventory = currentCustomer.getInventory(); 265 inventory.remove(i); 266 inventoryTable.tableChanged(new TableModelEvent(inventoryModel)); 267 } 268 } 269 ); 270 addInvMenuItem.addActionListener( 271 new ActionListener() { 272 public void actionPerformed(ActionEvent e) { 273 if (addProductSelectionDialog == null) 274 addProductSelectionDialog = new ProductSelectionDialog((InventoryListener)thisDialog); 275 addProductSelectionDialog.show(); 276 } 277 } 278 ); 279 280 281 updateCustList(null); 282 setSecurity(); 283 setSize(500, 730); 284 inventoryModel = new ProductTableModel(new ArrayList()); 285 inventoryTable.setModel(inventoryModel); 286 setLang(); 287 } 288 289 292 private final void initComponents() { 293 mainPanel = new JPanel(); 294 custPanel = new JPanel(); 295 custList = new JList(); 296 custListScrollPane = new JScrollPane(custList); 297 custListScrollPane.setMinimumSize(new Dimension(300, 160)); 298 custListScrollPane.setPreferredSize(new Dimension(300, 160)); 299 custListScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 300 custPanel.add(custListScrollPane); 301 annualSalesLabel = new JLabel(); 302 custLabel = new JLabel(); 303 custField = new JTextField(); 304 custField.setEditable(false); 305 annualSalesField = new JTextField(); 306 industryLabel = new JLabel(); 307 industryField = new JTextField(); 308 channelLabel = new JLabel(); 309 channelField = new JTextField(); 310 inventoryLabel = new JLabel(); 311 inventoryScrollPane = new JScrollPane(); 312 inventoryPanel = new JPanel(); 313 inventoryTable = new JTable(); 314 contactAddressPanel = new AddressPanel(); 315 shipAddressPanel = new AddressPanel(); 316 billAddressPanel = new AddressPanel(); 317 buttonPanel = new JPanel(); 318 applyButton = new JButton(); 319 clearButton = new JButton(); 320 closeButton = new JButton(); 321 custPopup = new JPopupMenu(); 322 addCustMenuItem = new JMenuItem(); 323 deleteCustMenuItem = new JMenuItem(); 324 invPopup = new JPopupMenu(); 325 addInvMenuItem = new JMenuItem(); 326 deleteInvMenuItem = new JMenuItem(); 327 328 addCustMenuItem.setText("Add"); 329 custPopup.add(addCustMenuItem); 330 deleteCustMenuItem.setText("Delete"); 331 custPopup.add(deleteCustMenuItem); 332 333 addInvMenuItem.setText("Add"); 334 invPopup.add(addInvMenuItem); 335 deleteInvMenuItem.setText("Delete"); 336 invPopup.add(deleteInvMenuItem); 337 338 addWindowListener(new java.awt.event.WindowAdapter () { 339 public void windowClosing(java.awt.event.WindowEvent evt) { 340 closeDialog(evt); 341 } 342 }); 343 344 mainPanel.setLayout(new java.awt.GridBagLayout ()); 345 346 JPanel detailPanel = new JPanel(); 347 detailPanel.setLayout(new GridBagLayout()); 348 349 java.awt.GridBagConstraints gridBagConstraints1; 350 351 mainPanel.setBorder(new javax.swing.border.EtchedBorder ()); 352 353 custList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 354 gridBagConstraints1 = new java.awt.GridBagConstraints (); 355 gridBagConstraints1.gridx = 0; 356 gridBagConstraints1.gridy = 0; 357 gridBagConstraints1.ipady = 5; 358 gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT); 359 gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; 360 mainPanel.add(custPanel, gridBagConstraints1); 361 362 custLabel.setText("Customer"); 363 custLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 364 GridBagConstraints gbc = new java.awt.GridBagConstraints (); 365 gbc.fill = java.awt.GridBagConstraints.HORIZONTAL; 366 gbc.gridx = 0; 367 gbc.gridy = 0; 368 gbc.ipadx = 5; 369 gbc.anchor = java.awt.GridBagConstraints.EAST; 370 detailPanel.add(custLabel, gbc); 371 372 custField.setHorizontalAlignment(JTextField.LEFT); 373 custField.setCaretPosition(0); 374 custField.setMaximumSize(new Dimension(240, Prefs.FIELD_HEIGHT)); 375 custField.setPreferredSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 376 custField.setMinimumSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 377 gbc = new java.awt.GridBagConstraints (); 378 gbc.gridx = 1; 379 gbc.gridy = 0; 380 gbc.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT); 381 gbc.anchor = java.awt.GridBagConstraints.WEST; 382 detailPanel.add(custField, gbc); 383 384 annualSalesLabel.setText("Annual Sales"); 385 annualSalesLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 386 gbc = new java.awt.GridBagConstraints (); 387 gbc.fill = java.awt.GridBagConstraints.HORIZONTAL; 388 gbc.gridx = 0; 389 gbc.gridy = 1; 390 gbc.ipadx = 5; 391 gbc.anchor = java.awt.GridBagConstraints.EAST; 392 detailPanel.add(annualSalesLabel, gbc); 393 394 annualSalesField.setText("0"); 395 annualSalesField.setPreferredSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 396 annualSalesField.setMinimumSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 397 gbc = new java.awt.GridBagConstraints (); 398 gbc.gridx = 1; 399 gbc.gridy = 1; 400 gbc.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT); 401 gbc.anchor = java.awt.GridBagConstraints.WEST; 402 detailPanel.add(annualSalesField, gbc); 403 404 annualSalesField.addFocusListener( 405 new FocusListener() { 406 public void focusGained(FocusEvent e) {} 407 public void focusLost(FocusEvent e) { 408 try { 409 Number num = format.parse(annualSalesField.getText()); 410 double x = num.doubleValue(); 411 annualSalesField.setText(Prefs.wholeMoney.format(x)); 412 } catch (ParseException p) { 413 Toolkit.getDefaultToolkit().beep(); 414 return; 415 } 416 } 417 } 418 ); 419 420 industryLabel.setText("Industry"); 421 industryLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 422 gbc = new java.awt.GridBagConstraints (); 423 gbc.gridx = 0; 424 gbc.gridy = 3; 425 gbc.fill = java.awt.GridBagConstraints.HORIZONTAL; 426 gbc.ipadx = 5; 427 gbc.anchor = java.awt.GridBagConstraints.EAST; 428 detailPanel.add(industryLabel, gbc); 429 430 industryField.setText("industry"); 431 industryField.setPreferredSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 432 industryField.setMinimumSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 433 gbc = new java.awt.GridBagConstraints (); 434 gbc.gridx = 1; 435 gbc.gridy = 3; 436 gbc.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT); 437 gbc.anchor = java.awt.GridBagConstraints.WEST; 438 detailPanel.add(industryField, gbc); 439 440 channelLabel.setText("Channel"); 441 channelLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 442 gbc = new java.awt.GridBagConstraints (); 443 gbc.fill = java.awt.GridBagConstraints.HORIZONTAL; 444 gbc.gridx = 0; 445 gbc.gridy = 4; 446 gbc.ipadx = 5; 447 gbc.anchor = java.awt.GridBagConstraints.EAST; 448 detailPanel.add(channelLabel, gbc); 449 450 channelField.setText("channel"); 451 channelField.setPreferredSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 452 channelField.setMinimumSize(new Dimension(140, Prefs.FIELD_HEIGHT)); 453 gbc = new java.awt.GridBagConstraints (); 454 gbc.gridx = 1; 455 gbc.gridy = 4; 456 gbc.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT); 457 gbc.anchor = java.awt.GridBagConstraints.WEST; 458 detailPanel.add(channelField, gbc); 459 460 gridBagConstraints1 = new java.awt.GridBagConstraints (); 461 gridBagConstraints1.gridx = 0; 462 gridBagConstraints1.gridy = 1; 463 gridBagConstraints1.ipadx = 5; 464 gridBagConstraints1.ipady = 5; 465 gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT); 466 gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; 467 mainPanel.add(detailPanel, gridBagConstraints1); 468 469 inventoryScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 470 inventoryScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 471 inventoryScrollPane.setViewportBorder(new javax.swing.border.BevelBorder (javax.swing.border.BevelBorder.RAISED)); 472 inventoryScrollPane.setMinimumSize(new Dimension(300, 120)); 473 inventoryScrollPane.setPreferredSize(new Dimension(300, 120)); 474 inventoryTable.setMinimumSize(new Dimension(300, 120)); 475 inventoryTable.setPreferredSize(new Dimension(300, 120)); 476 inventoryScrollPane.setViewportView(inventoryTable); 477 478 gridBagConstraints1 = new java.awt.GridBagConstraints (); 479 gridBagConstraints1.gridx = 0; 480 gridBagConstraints1.gridy = 2; 481 gridBagConstraints1.ipadx = 5; 482 gridBagConstraints1.ipady = 5; 483 gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT); 484 gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; 485 inventoryPanel.add(inventoryScrollPane); 486 487 mainPanel.add(tabbedPane, gridBagConstraints1); 488 tabbedPane.add(wb.getLang().getString("inventory"), inventoryPanel); 489 490 tabbedPane.add(wb.getLang().getString("contact"), contactAddressPanel); 491 492 tabbedPane.add(wb.getLang().getString("shipAddress"), shipAddressPanel); 493 494 tabbedPane.add(wb.getLang().getString("billAddress"), billAddressPanel); 495 496 getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); 497 498 applyButton.setText("Apply"); 499 buttonPanel.add(applyButton); 500 501 clearButton.setText("Clear"); 502 buttonPanel.add(clearButton); 503 504 closeButton.setText("Cancel"); 505 buttonPanel.add(closeButton); 506 507 getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH); 508 509 pack(); 510 } 511 512 516 private final void closeDialog(java.awt.event.WindowEvent evt) { 517 setVisible(false); 518 dispose(); 519 } 520 521 522 525 private final void clear() { 526 shipAddressPanel.clear(); 527 contactAddressPanel.clear(); 528 billAddressPanel.clear(); 529 channelField.setText(""); 530 industryField.setText(""); 531 annualSalesField.setText("0"); 532 } 533 534 538 private final void setCustomer(Customer c) { 539 custField.setText(c.getName()); 540 custField.setCaretPosition(0); 541 annualSalesField.setText(Prefs.wholeMoney.format(c.getAnnualSales())); 542 industryField.setText(c.getIndustry()); 543 channelField.setText(c.getChannel()); 544 if (c.getContact() == null) 545 contactAddressPanel.clear(); 546 else 547 contactAddressPanel.setAddress(c.getContact()); 548 if (c.getShipAddress() == null) 549 shipAddressPanel.clear(); 550 else 551 shipAddressPanel.setAddress(c.getShipAddress()); 552 if (c.getBillAddress() == null) 553 billAddressPanel.clear(); 554 else 555 billAddressPanel.setAddress(c.getBillAddress()); 556 inventoryModel = new ProductTableModel(c.getInventory()); 557 inventoryTable.setModel(inventoryModel); 558 inventoryTable.tableChanged(new TableModelEvent(inventoryModel)); 559 } 560 561 567 private final void copyFields(Customer to, Customer from) { 568 to.setName(from.getName()); 569 to.setAnnualSales(from.getAnnualSales()); 570 to.setIndustry(from.getIndustry()); 571 to.setChannel(from.getChannel()); 572 long pk = to.getContact().getPK(); to.setContact(from.getContact()); to.getContact().setPK(pk); pk = to.getShipAddress().getPK(); to.setShipAddress(from.getShipAddress()); to.getShipAddress().setPK(pk); pk = to.getBillAddress().getPK(); to.setBillAddress(from.getBillAddress()); to.getBillAddress().setPK(pk); } 582 583 587 private final Customer getCustomer() { 588 screenCust.setName(custField.getText()); 589 Number num = Prefs.wholeMoney.parse(annualSalesField.getText(), new ParsePosition(0)); 590 screenCust.setAnnualSales(num.intValue()); 591 screenCust.setIndustry(industryField.getText()); 592 screenCust.setChannel(channelField.getText()); 593 if (screenCust.getContact() == null) { 594 screenCust.setContact(new Address()); 595 screenCust.setContact(new Address()); 596 } 597 screenCust.setContact(contactAddressPanel.getAddress()); 598 if (screenCust.getShipAddress() == null) { 599 screenCust.setShipAddress(new Address()); 600 screenCust.setBillAddress(new Address()); 601 } 602 603 screenCust.setShipAddress(shipAddressPanel.getAddress()); 604 screenCust.setBillAddress(billAddressPanel.getAddress()); 605 screenCust.setInventory(currentCustomer.getInventory()); 606 return screenCust; 607 } 608 609 612 public final void setFonts() { 613 tabbedPane.setFont(MainWindow.LABEL_FONT); 614 addCustMenuItem.setFont(MainWindow.LABEL_FONT); 615 deleteCustMenuItem.setFont(MainWindow.LABEL_FONT); 616 addInvMenuItem.setFont(MainWindow.LABEL_FONT); 617 deleteInvMenuItem.setFont(MainWindow.LABEL_FONT); 618 custList.setFont(MainWindow.FIELD_FONT); 619 annualSalesLabel.setFont(MainWindow.LABEL_FONT); 620 annualSalesField.setFont(MainWindow.FIELD_FONT); 621 industryLabel.setFont(MainWindow.LABEL_FONT); 622 industryField.setFont(MainWindow.FIELD_FONT); 623 channelLabel.setFont(MainWindow.LABEL_FONT); 624 channelField.setFont(MainWindow.FIELD_FONT); 625 custLabel.setFont(MainWindow.LABEL_FONT); 626 inventoryLabel.setFont(MainWindow.LABEL_FONT); 627 inventoryTable.setFont(MainWindow.FIELD_FONT); 628 applyButton.setFont(MainWindow.LABEL_FONT); 629 clearButton.setFont(MainWindow.LABEL_FONT); 630 closeButton.setFont(MainWindow.LABEL_FONT); 631 } 632 633 636 public final void setColors() { 637 annualSalesLabel.setForeground(MainWindow.LETTERS); 638 industryLabel.setForeground(MainWindow.LETTERS); 639 channelLabel.setForeground(MainWindow.LETTERS); 640 custLabel.setForeground(MainWindow.LETTERS); 641 inventoryLabel.setForeground(MainWindow.LETTERS); 642 } 643 644 647 private final void updateCustList(String requestedKey) { 648 try { 649 customerNames = wb.getAllCustNames(true); 650 } catch (AngError e) { 651 ErrorHandler.show(thisDialog, e); 652 } 653 654 Object [] keys = customerNames.keySet().toArray(); 655 custList.setListData(keys); 656 custList.updateUI(); 657 658 if (keys.length > 0) { 659 if (requestedKey == null) { 660 custList.setSelectedIndex(0); 661 requestedKey = (String )keys[0]; 662 } 663 else 664 custList.setSelectedValue(requestedKey, true); 665 666 try { 667 currentCustomer = wb.getCustomer(requestedKey); 668 setCustomer(currentCustomer); 669 } catch (AngError e) { 670 ErrorHandler.show(thisDialog, e); 671 } 672 } 673 } 674 675 679 public final void addQuoteLine(QuoteLine x) { 680 int lineCt = currentCustomer.getInventory().size(); 681 CustomerInventory ci = new CustomerInventory(); 682 ci.setCount(x.getQuantity()); 683 ci.setProduct(x.getProduct()); 684 ci.setCustomerPK(currentCustomer.getPK()); 685 try { 686 wb.addCustomerInventory(ci); 687 currentCustomer.addInventory(ci); 688 inventoryModel = new ProductTableModel(currentCustomer.getInventory()); 689 inventoryTable.setModel(inventoryModel); 690 inventoryTable.tableChanged(new TableModelEvent(inventoryModel)); 691 inventoryTable.setRowSelectionInterval(lineCt, lineCt); 692 JOptionPane.showMessageDialog( 693 thisDialog, 694 wb.getLang().getString("custInvAddNotify"), 695 wb.getLang().getString("info"), 696 JOptionPane.INFORMATION_MESSAGE); 697 } catch (AngError e) { 698 ErrorHandler.show(thisDialog, e); 699 } 700 } 701 702 706 private final void setSecurity() { 707 try { 708 if (wb.getLogin().basicAdminWritable()) { 709 applyButton.setEnabled(true); 710 custPopup.setEnabled(true); 711 invPopup.setEnabled(true); 712 addCustMenuItem.setEnabled(true); 713 deleteCustMenuItem.setEnabled(true); 714 addInvMenuItem.setEnabled(true); 715 deleteInvMenuItem.setEnabled(true); 716 } else { 717 applyButton.setEnabled(false); 718 custPopup.setEnabled(false); 719 invPopup.setEnabled(false); 720 addCustMenuItem.setEnabled(false); 721 deleteCustMenuItem.setEnabled(false); 722 addInvMenuItem.setEnabled(false); 723 deleteInvMenuItem.setEnabled(false); 724 } 725 } catch (AngError e) { 726 ErrorHandler.show(thisDialog, e); 727 } 728 } 729 730 733 public final void setLang() { 734 inventoryModel.setLang(); 735 setTitle(wb.getLang().getString("custAdmin")); 736 custPanel.setBorder( 737 new javax.swing.border.TitledBorder ( 738 null, 739 wb.getLang().getString("customer"), 740 TitledBorder.DEFAULT_JUSTIFICATION, 741 TitledBorder.DEFAULT_POSITION, 742 MainWindow.LABEL_FONT, 743 MainWindow.LETTERS 744 ) 745 ); 746 applyButton.setText(wb.getLang().getString("apply")); 747 clearButton.setText(wb.getLang().getString("clear")); 748 closeButton.setText(wb.getLang().getString("close")); 749 750 custLabel.setText(wb.getLang().getString("customer")); 751 channelLabel.setText(wb.getLang().getString("channel")); 752 industryLabel.setText(wb.getLang().getString("industry")); 753 annualSalesLabel.setText(wb.getLang().getString("annualSales")); 754 } 755 756 private void clearFields() { 757 custField.setText(""); 758 annualSalesField.setText(""); 759 industryField.setText(""); 760 channelField.setText(""); 761 } 762 } 763 | Popular Tags |