KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > QuotesPanel


1 package sellwin.gui;
2
3 import sellwin.domain.*;
4 import sellwin.utils.*;
5
6 import java.awt.*;
7 import java.awt.event.*;
8 import java.util.*;
9 import javax.swing.*;
10 import javax.swing.event.*;
11 import javax.swing.border.*;
12 import javax.swing.table.*;
13
14 // SellWin http://sourceforge.net/projects/sellwincrm
15
//Contact support@open-app.com for commercial help with SellWin
16
//This software is provided "AS IS", without a warranty of any kind.
17

18 /**
19  * This class is the panel that is shown when
20  * the user selects the Quotes tab from the MainWindow
21  * This panel shows all the quotes for a given Opportunity
22  * and the quote details.
23  */

24 public class QuotesPanel extends JPanel
25     implements InventoryListener,TableModelListener, GUIChars {
26
27     private QuotesPanel thisPanel = null;
28     private JPopupMenu quotePopup = new JPopupMenu();
29     private JPopupMenu linePopup = new JPopupMenu();
30
31     private ArrayList quotes; //reference to current opp's quotes
32

33     private ProductSelectionDialog addProductSelectionDialog;
34     private Whiteboard wb;
35     private Opportunity currentOpp;
36     
37     private QuoteTableModel quoteModel = null;
38     private QuoteLineTableModel lineModel = null;
39
40     private JPanel buttonPanel;
41     private JMenuItem addQuoteMenuItem;
42     private JMenuItem deleteQuoteMenuItem;
43     private JMenuItem addLineMenuItem;
44     private JMenuItem deleteLineMenuItem;
45     private JButton orderButton;
46     private JButton applyButton;
47
48     private JPanel mainPanel;
49     private JScrollPane quotesScrollPane;
50     private final javax.swing.JTable JavaDoc quotesTable = new JTable();
51     private JLabel lineItemsLabel;
52     private TitledBorder lineItemBorder;
53     private JLabel quotesLabel;
54
55     private JPanel linesPanel = new JPanel();
56     private JScrollPane linesScrollPane;
57     private final javax.swing.JTable JavaDoc linesTable = new JTable();
58
59     private JLabel totalLabel;
60     private JTextField totalField;
61
62     private JLabel profitLabel;
63     private JTextField profitField;
64     
65     /**
66      * construct a quote panel
67      */

68     public QuotesPanel() {
69         super();
70
71         thisPanel = this;
72         wb = MainWindow.getWhiteboard();
73         initComponents();
74
75         setFonts();
76         setColors();
77
78         quoteModel = new QuoteTableModel(new ArrayList());
79         quotesTable.setModel(quoteModel);
80         lineModel = new QuoteLineTableModel(new ArrayList());
81         linesTable.setModel(lineModel);
82
83         setLang();
84
85         linesTable.setPreferredScrollableViewportSize(new Dimension(500,150));
86         linesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
87         linesTable.getSelectionModel().addListSelectionListener(
88             new ListSelectionListener() {
89                 public void valueChanged(ListSelectionEvent e) {
90                     if (e.getValueIsAdjusting()) return; //ignore these
91
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
92                 }
93             }
94         );
95
96         quotesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
97         quotesTable.getSelectionModel().addListSelectionListener(
98             new ListSelectionListener() {
99                 public void valueChanged(ListSelectionEvent e) {
100
101                     if (e.getValueIsAdjusting()) return; //ignore these
102

103                     ListSelectionModel lsm = (ListSelectionModel)e.getSource();
104
105                     if (lsm.isSelectionEmpty())
106                         ;
107                     else {
108                         Quote quote = quoteModel.getQuote(quotesTable.getSelectedRow());
109                         setLines(quote.getLines());
110                         
111                     }
112                 }
113             }
114         );
115
116         quotesTable.setDefaultRenderer(Date.class, new DateRenderer());
117
118         addQuoteMenuItem.addActionListener(
119             new ActionListener() {
120                 public void actionPerformed(ActionEvent e) {
121                     Opportunity opp = wb.getCurrentOpportunity();
122                     if (opp == null) {
123                         JOptionPane.showMessageDialog( thisPanel,
124                             wb.getLang().getString("selectOpp"),
125                             wb.getLang().getString("error"),
126                             JOptionPane.INFORMATION_MESSAGE);
127                         return;
128                     }
129                     String JavaDoc val=JOptionPane.showInputDialog("Please enter a Quote name");
130                     Quote quote = new Quote();
131                     quote.setName(val);
132                     try {
133                         quote.setModifiedBy(wb.getCurrentUser().getAddress().getFormattedName());
134                         quote.setPK(wb.addQuote(opp.getPK(), quote));
135                         opp.addQuote(quote);
136                         quotesTable.tableChanged(new TableModelEvent(quoteModel));
137                         int quoteCt = opp.getQuotes().size();
138                         if (quoteCt > 0)
139                             quotesTable.setRowSelectionInterval(quoteCt-1,quoteCt-1);
140                     } catch (Exception JavaDoc f) {
141                         ErrorHandler.show(thisPanel, f);
142                     }
143                 }
144             }
145         );
146
147         deleteQuoteMenuItem.addActionListener(
148             new ActionListener() {
149                 public void actionPerformed(ActionEvent e) {
150                     Quote quote = quoteModel.getQuote(quotesTable.getSelectedRow());
151                     try {
152                         Opportunity opp = wb.getCurrentOpportunity();
153                         wb.deleteQuote(opp.getPK(), quote.getPK());
154                         opp.deleteQuote(quote);
155                         quotesTable.tableChanged(new TableModelEvent(quoteModel));
156                     } catch (Exception JavaDoc f) {
157                         ErrorHandler.show(thisPanel, f);
158                     }
159                 }
160             }
161         );
162
163
164         addLineMenuItem.addActionListener(
165             new ActionListener() {
166                 public void actionPerformed(ActionEvent e) {
167                     if (addProductSelectionDialog == null)
168                         addProductSelectionDialog = new ProductSelectionDialog(thisPanel);
169                     addProductSelectionDialog.show();
170                 }
171             }
172         );
173
174         deleteLineMenuItem.addActionListener(
175             new ActionListener() {
176                 public void actionPerformed(ActionEvent e) {
177                     Quote quote = quoteModel.getQuote(quotesTable.getSelectedRow());
178                     QuoteLine line = lineModel.getQuoteLine(linesTable.getSelectedRow());
179                     try {
180                         Opportunity opp = wb.getCurrentOpportunity();
181                         wb.deleteQuoteLine(opp.getPK(), quote.getPK(), line.getPK());
182                         quote.deleteLine(line.getPK());
183                         linesTable.tableChanged(new TableModelEvent(lineModel));
184                         calcTotal();
185                         //double total = Double.parseDouble(totalField.getText());
186
//total -= line.getTotalPrice().doubleValue();
187
//totalField.setText(Prefs.money.format(total));
188
} catch (Exception JavaDoc f) {
189                         ErrorHandler.show(thisPanel, f);
190                     }
191                 }
192             }
193         );
194
195         createPopup();
196
197         quotesTable.addMouseListener(new MouseAdapter() {
198             public void mousePressed(MouseEvent e) {
199                 if (e.isPopupTrigger())
200                     quotePopup.show(quotesTable, e.getX(), e.getY());
201             }
202             public void mouseReleased(MouseEvent e) {
203                 if (e.isPopupTrigger())
204                     quotePopup.show(quotesTable, e.getX(), e.getY());
205             }
206             public void mouseClicked(MouseEvent e) {
207                 if (e.isPopupTrigger())
208                     quotePopup.show(quotesTable, e.getX(), e.getY());
209             }
210         });
211
212         quotesTable.getTableHeader().addMouseListener(new MouseAdapter() {
213             public void mousePressed(MouseEvent e) {
214                 if (e.isPopupTrigger())
215                     quotePopup.show(quotesTable, e.getX(), e.getY());
216             }
217             public void mouseReleased(MouseEvent e) {
218                 if (e.isPopupTrigger())
219                     quotePopup.show(quotesTable, e.getX(), e.getY());
220             }
221             public void mouseClicked(MouseEvent e) {
222                 if (e.isPopupTrigger())
223                     quotePopup.show(quotesTable, e.getX(), e.getY());
224             }
225         });
226         quotesScrollPane.addMouseListener(new MouseAdapter() {
227             public void mousePressed(MouseEvent e) {
228                 if (e.isPopupTrigger())
229                     quotePopup.show(quotesTable, e.getX(), e.getY());
230             }
231             public void mouseReleased(MouseEvent e) {
232                 if (e.isPopupTrigger())
233                     quotePopup.show(quotesTable, e.getX(), e.getY());
234             }
235             public void mouseClicked(MouseEvent e) {
236                 if (e.isPopupTrigger())
237                     quotePopup.show(quotesTable, e.getX(), e.getY());
238             }
239         });
240
241
242         linesScrollPane.addMouseListener(new MouseAdapter() {
243             public void mousePressed(MouseEvent e) {
244                 if (e.isPopupTrigger())
245                     linePopup.show(linesTable, e.getX(), e.getY());
246             }
247             public void mouseReleased(MouseEvent e) {
248                 if (e.isPopupTrigger())
249                     linePopup.show(linesTable, e.getX(), e.getY());
250             }
251             public void mouseClicked(MouseEvent e) {
252                 if (e.isPopupTrigger())
253                     linePopup.show(linesTable, e.getX(), e.getY());
254             }
255         });
256         linesTable.addMouseListener(new MouseAdapter() {
257             public void mousePressed(MouseEvent e) {
258                 if (e.isPopupTrigger())
259                     linePopup.show(linesTable, e.getX(), e.getY());
260             }
261             public void mouseReleased(MouseEvent e) {
262                 if (e.isPopupTrigger())
263                     linePopup.show(linesTable, e.getX(), e.getY());
264             }
265             public void mouseClicked(MouseEvent e) {
266                 if (e.isPopupTrigger())
267                     linePopup.show(linesTable, e.getX(), e.getY());
268             }
269         });
270
271         linesTable.getTableHeader().addMouseListener(new MouseAdapter() {
272             public void mousePressed(MouseEvent e) {
273                 if (e.isPopupTrigger())
274                     linePopup.show(linesTable, e.getX(), e.getY());
275             }
276             public void mouseReleased(MouseEvent e) {
277                 if (e.isPopupTrigger())
278                     linePopup.show(linesTable, e.getX(), e.getY());
279             }
280             public void mouseClicked(MouseEvent e) {
281                 if (e.isPopupTrigger())
282                     linePopup.show(linesTable, e.getX(), e.getY());
283             }
284         });
285
286         orderButton.addActionListener(
287             new ActionListener() {
288                 public void actionPerformed(ActionEvent e) {
289                     int opt = JOptionPane.showConfirmDialog(thisPanel, "Select 'Yes' to confirm order.", "Confirm Order Creation", JOptionPane.YES_NO_OPTION);
290                     if (opt == JOptionPane.YES_OPTION)
291                         createOrder();
292                 }
293             }
294         );
295
296         applyButton.addActionListener(
297             new ActionListener() {
298                 public void actionPerformed(ActionEvent e) {
299                     ArrayList quotes = wb.getCurrentOpportunity().getQuotes();
300                     Quote quote;
301                     for (int i=0;i<quotes.size();i++) {
302                         quote = (Quote)quotes.get(i);
303                         if (quote.getModified() == true) {
304                             try {
305                                 wb.updateQuote(quote);
306                             } catch (AngError r) {
307                                 ErrorHandler.show(thisPanel, r);
308                             }
309                         }
310                     }
311                     JOptionPane.showMessageDialog( thisPanel,
312                         "Update Successful", "Update Successful",
313                         JOptionPane.INFORMATION_MESSAGE);
314                 }
315             }
316         );
317
318
319     }
320
321     /**
322      * create an order when the user presses the
323      * create order button
324      */

325     private final void createOrder() {
326         Opportunity opp = wb.getCurrentOpportunity();
327         Order order = new Order();
328
329         // 1) get the current selected quote and make an order with it
330
Quote quote = quoteModel.getQuote(quotesTable.getSelectedRow());
331         order.setQuoteKey(quote.getPK());
332         order.setQuote(quote);
333         //for now, just make the order number some big unique number
334
Date temp = new java.util.Date JavaDoc();
335         order.setOrderNumber(new Long JavaDoc(temp.getTime()));
336         //order.setSubmitDate(temp);
337

338         // 2) get the ship & bill-to addresses from the current customer
339
// these can be later changed by the user if they wish
340
Customer currCust = opp.getCustomer();
341         order.setShipAddress(currCust.getShipAddress());
342         System.out.println("ship addr");
343         currCust.getShipAddress().print();
344         order.setBillAddress(currCust.getBillAddress());
345         System.out.println("bill addr");
346         currCust.getBillAddress().print();
347
348         try {
349
350             // 3) add it to database
351
order.setPK(
352                 wb.addOrder(order));
353
354             // 4) add it to memory
355
opp.addOrder(order);
356
357             // 5) refresh the Orders in the Orders Panel
358
OrderFulfillPanel p = MainWindow.getOrdersPanel();
359             p.refreshOpportunity();
360
361             // 6) make the order the one that is initially selected
362
p.setSelectedOrder(order);
363
364             // 7) go to the Orders tab
365
MainWindow.selectOrderTab();
366
367         } catch (AngError e) {
368             ErrorHandler.show(thisPanel, e);
369         }
370     }
371
372     /**
373     callback when the ProductSelectionDialog user selects a Product to
374     be added as a QuoteLine
375      * @param q the QuoteLine to add
376      */

377     public final void addQuoteLine(QuoteLine q) {
378         Quote quote = quoteModel.getQuote(quotesTable.getSelectedRow());
379         int lineCt = quote.getLines().size();
380         try {
381             wb.addQuoteLine(
382                 wb.getCurrentOpportunity().getPK(),
383                 quote.getPK(),
384                 q);
385             quote.addLine(q);
386             linesTable.tableChanged(new TableModelEvent(lineModel));
387             linesTable.setRowSelectionInterval(lineCt, lineCt);
388             calcTotal();
389             //double total = Double.parseDouble(totalField.getText());
390
//total +=q.getTotalPrice().doubleValue();
391
//totalField.setText(Prefs.money.format(total));
392
} catch (AngError e) {
393             ErrorHandler.show(thisPanel, e);
394         }
395     }
396
397     /**
398      * create the popup menu
399      */

400     private final void createPopup() {
401         linePopup.add(addLineMenuItem);
402         linePopup.add(deleteLineMenuItem);
403         quotePopup.add(addQuoteMenuItem);
404         quotePopup.add(deleteQuoteMenuItem);
405     }
406
407     /**
408      *
409      * @param name description
410      * @return description
411      * @exception class-name description
412      */

413     public final void setEnabled(boolean t) {
414     }
415
416     /**
417      * refresh the screen with the current
418      * opportunity
419      */

420     public final void refreshOpportunity() {
421
422         setSecurity();
423
424         currentOpp = wb.getCurrentOpportunity();
425
426         Quote quote=null;
427         ArrayList quotes = currentOpp.getQuotes();
428         for (int i=0;i<quotes.size();i++) {
429             quote = (Quote)(quotes.get(i));
430         }
431         quoteModel = new QuoteTableModel(currentOpp.getQuotes());
432         quotesTable.setModel(quoteModel);
433         ArrayList lines = null;
434         Quote firstQuote = null;
435         if (currentOpp.getQuotes().size() > 0) {
436             firstQuote = (Quote)(currentOpp.getQuotes().get(0));
437             lines = firstQuote.getLines();
438             quotesTable.setRowSelectionInterval(0,0);
439         } else
440             lines = new ArrayList();
441
442         setLines(lines);
443
444         linesTable.setDefaultRenderer(Double JavaDoc.class, new MoneyRenderer());
445
446     }
447
448     /**
449      * set the product lines on the screen
450      * @param lines the product liens to display
451      */

452     private final void setLines(ArrayList lines) {
453         lineModel = new QuoteLineTableModel(lines);
454         lineModel.addTableModelListener(this);
455         linesTable.setModel(lineModel);
456         setLinesColumnWidths();
457         if (lines.size() > 0)
458             linesTable.setRowSelectionInterval(0,0);
459
460         calcTotal();
461         //double total = 0.00;
462
//QuoteLine line;
463
//for (int i=0;i<lines.size();i++) {
464
//line = (QuoteLine)(lines.get(i));
465
//total += line.getTotalPrice().doubleValue();
466
//}
467

468         //totalField.setText(Prefs.money.format(total));
469

470     }
471
472     /**
473      * set the quote lines on the screen
474      * @param name description
475      * @return description
476      * @exception class-name description
477      */

478     public final void setDisplayedQuoteLines(int index) {
479         lineModel = new QuoteLineTableModel(((Quote)(quotes.get(index))).getLines());
480         lineModel.addTableModelListener(this);
481         linesTable.setModel(lineModel);
482         setLinesColumnWidths();
483     }
484
485     /**
486      * set the screen color
487      */

488     public final void setColors() {
489         quotesLabel.setForeground(MainWindow.LETTERS);
490         lineItemsLabel.setForeground(MainWindow.LETTERS);
491         totalLabel.setForeground(MainWindow.LETTERS);
492         profitLabel.setForeground(MainWindow.LETTERS);
493     }
494
495     /**
496      * set the screen fonts
497      */

498     public final void setFonts() {
499         quotesLabel.setFont(MainWindow.LABEL_FONT);
500         lineItemsLabel.setFont(MainWindow.LABEL_FONT);
501         linesTable.setFont(MainWindow.FIELD_FONT);
502         quotesTable.setFont(MainWindow.FIELD_FONT);
503         addQuoteMenuItem.setFont(MainWindow.LABEL_FONT);
504         deleteQuoteMenuItem.setFont(MainWindow.LABEL_FONT);
505         addLineMenuItem.setFont(MainWindow.LABEL_FONT);
506         deleteLineMenuItem.setFont(MainWindow.LABEL_FONT);
507         totalLabel.setFont(MainWindow.LABEL_FONT);
508         profitLabel.setFont(MainWindow.LABEL_FONT);
509         orderButton.setFont(MainWindow.LABEL_FONT);
510         applyButton.setFont(MainWindow.LABEL_FONT);
511     }
512
513     /** This method is called from within the constructor to
514      * initialize the form.
515      */

516     private final void initComponents() {
517         buttonPanel = new JPanel();
518         addQuoteMenuItem = new JMenuItem();
519         deleteQuoteMenuItem = new JMenuItem();
520         addLineMenuItem = new JMenuItem();
521         deleteLineMenuItem = new JMenuItem();
522         orderButton = new JButton();
523         applyButton = new JButton();
524         mainPanel = new JPanel();
525         quotesScrollPane = new JScrollPane();
526         lineItemsLabel = new JLabel();
527         quotesLabel = new JLabel();
528         linesScrollPane = new JScrollPane();
529         totalLabel = new JLabel();
530         totalField = new JTextField();
531         totalField.setEditable(false);
532         profitLabel = new JLabel();
533         profitField = new JTextField();
534         profitField.setEditable(false);
535         
536         setLayout(new java.awt.BorderLayout JavaDoc());
537         
538         addQuoteMenuItem.setText("Add");
539         deleteQuoteMenuItem.setText("Delete");
540         addLineMenuItem.setText("Add");
541         deleteLineMenuItem.setText("Delete");
542         
543         orderButton.setText("Create Order");
544         buttonPanel.add(orderButton);
545         applyButton.setText("Apply");
546         buttonPanel.add(applyButton);
547         
548         add(buttonPanel, java.awt.BorderLayout.SOUTH);
549         
550         mainPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
551         java.awt.GridBagConstraints JavaDoc gridBagConstraints1;
552         
553         mainPanel.setBorder(new javax.swing.border.EtchedBorder JavaDoc());
554
555         //quotesScrollPane.setBorder(new TitledBorder("Quotes"));
556
quotesScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
557         quotesScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
558         quotesScrollPane.setMinimumSize(new Dimension(500, 100));
559         quotesScrollPane.setMaximumSize(new Dimension(500, 100));
560         quotesScrollPane.setPreferredSize(new Dimension(500, 100));
561         quotesTable.setPreferredSize(new Dimension(500, 100));
562         quotesTable.setMaximumSize(new Dimension(500, 100));
563         quotesTable.setMinimumSize(new Dimension(500, 100));
564         quotesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
565         quotesScrollPane.setViewportView(quotesTable);
566         
567         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
568         gridBagConstraints1.gridx = 0;
569         gridBagConstraints1.gridy = 1;
570         gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
571         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
572         gridBagConstraints1.ipadx = 9;
573         gridBagConstraints1.ipady = 9;
574         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
575         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
576         mainPanel.add(quotesScrollPane, gridBagConstraints1);
577         
578        
579         //lineItemBorder = new TitledBorder(null, "Line Items", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, MainWindow.LABEL_FONT, MainWindow.LETTERS);
580
//linesScrollPane.setBorder(lineItemBorder);
581
linesScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
582         linesScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
583         linesScrollPane.setMinimumSize(new Dimension(500, 100));
584         linesScrollPane.setMaximumSize(new Dimension(500, 100));
585         linesScrollPane.setPreferredSize(new Dimension(500, 100));
586         linesTable.setPreferredSize(new Dimension(500, 100));
587         linesTable.setMinimumSize(new Dimension(500, 100));
588         linesTable.setMaximumSize(new Dimension(500, 100));
589         linesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
590         linesScrollPane.setViewportView(linesTable);
591         
592         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
593         gridBagConstraints1.gridx = 0;
594         gridBagConstraints1.gridy = 3;
595         gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
596         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
597         gridBagConstraints1.ipadx = 9;
598         gridBagConstraints1.ipady = 9;
599         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
600         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
601         //mainPanel.add(linesScrollPane, gridBagConstraints1);
602
linesPanel.add(linesScrollPane);
603         mainPanel.add(linesPanel, gridBagConstraints1);
604         
605         totalLabel.setText("Total");
606         totalLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
607         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
608         gridBagConstraints1.gridx = 0;
609         gridBagConstraints1.gridy = 4;
610         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
611         gridBagConstraints1.ipadx = 9;
612         gridBagConstraints1.ipady = 9;
613         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
614         gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
615         mainPanel.add(totalLabel, gridBagConstraints1);
616         
617         totalField.setText("0.00");
618         totalField.setMinimumSize(new Dimension(100, Prefs.FIELD_HEIGHT));
619         totalField.setPreferredSize(new Dimension(100, Prefs.FIELD_HEIGHT));
620         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
621         gridBagConstraints1.gridx = 1;
622         gridBagConstraints1.gridy = 4;
623         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
624         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
625         mainPanel.add(totalField, gridBagConstraints1);
626         
627         profitLabel.setText("Profit");
628         profitLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
629         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
630         gridBagConstraints1.gridx = 0;
631         gridBagConstraints1.gridy = 5;
632         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
633         gridBagConstraints1.ipadx = 9;
634         gridBagConstraints1.ipady = 9;
635         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
636         gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
637         mainPanel.add(profitLabel, gridBagConstraints1);
638         
639         profitField.setText("0.00");
640         profitField.setMinimumSize(new Dimension(100, Prefs.FIELD_HEIGHT));
641         profitField.setPreferredSize(new Dimension(100, Prefs.FIELD_HEIGHT));
642         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
643         gridBagConstraints1.gridx = 1;
644         gridBagConstraints1.gridy = 5;
645         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
646         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
647         mainPanel.add(profitField, gridBagConstraints1);
648         
649         add(mainPanel, java.awt.BorderLayout.CENTER);
650     }
651
652     /**
653      * recalculate the total when the table has changed
654      */

655     public final void tableChanged(TableModelEvent e) {
656         calcTotal();
657     }
658
659     /**
660      * calculate the total for this quote
661      */

662     public final void calcTotal() {
663         //System.out.println("calcTotal called");
664
double total=0.00;
665         double profit=0.00;
666
667         if (quotesTable.getSelectedRow() < 0)
668             return;
669
670         Quote quote = quoteModel.getQuote(quotesTable.getSelectedRow());
671         quote.setModified(true);
672         ArrayList lines = quote.getLines();
673         QuoteLine line;
674         for (int i=0;i<lines.size();i++) {
675             line = (QuoteLine)lines.get(i);
676             total = total +
677                 (line.getProduct().getPrice().doubleValue()
678                 * line.getQuantity().intValue());
679             profit = profit +
680                 ((line.getProduct().getPrice().doubleValue() -
681                  line.getProduct().getCost().doubleValue())
682                 * line.getQuantity().doubleValue());
683             //System.out.println("profit="+ profit);
684
}
685         totalField.setText(Prefs.money.format(total));
686         profitField.setText(Prefs.money.format(profit));
687         //System.out.println("calcTotal ends");
688
}
689
690     /**
691      * enable fields according to security
692      */

693     private final void setSecurity() {
694         try {
695             if (wb.getLogin().quoteWritable()) {
696                 addQuoteMenuItem.setEnabled(true);
697                 deleteQuoteMenuItem.setEnabled(true);
698                 addLineMenuItem.setEnabled(true);
699                 deleteLineMenuItem.setEnabled(true);
700             } else {
701                 addQuoteMenuItem.setEnabled(false);
702                 deleteQuoteMenuItem.setEnabled(false);
703                 addLineMenuItem.setEnabled(false);
704                 deleteLineMenuItem.setEnabled(false);
705             }
706         } catch (AngError e) {
707             ErrorHandler.show(thisPanel, e);
708         }
709     }
710
711     /**
712      * clear the screen components
713      */

714     public final void clearOpportunity() {
715
716         quoteModel = new QuoteTableModel(new ArrayList());
717         quotesTable.setModel(quoteModel);
718         ArrayList lines = new ArrayList();
719         setLines(lines);
720     }
721
722     /**
723      * set the screen language
724      */

725     public final void setLang() {
726         addQuoteMenuItem.setText(wb.getLang().getString("add"));
727         deleteQuoteMenuItem.setText(wb.getLang().getString("delete"));
728         addLineMenuItem.setText(wb.getLang().getString("add"));
729         deleteLineMenuItem.setText(wb.getLang().getString("delete"));
730         orderButton.setText(wb.getLang().getString("createOrder"));
731         applyButton.setText(wb.getLang().getString("apply"));
732         linesPanel.setBorder(
733             new TitledBorder(
734                 null,
735                 wb.getLang().getString("lineItems"),
736                 TitledBorder.DEFAULT_JUSTIFICATION,
737                 TitledBorder.DEFAULT_POSITION,
738                 MainWindow.LABEL_FONT,
739                 MainWindow.LETTERS
740             )
741         );
742         totalLabel.setText(wb.getLang().getString("total"));
743         profitLabel.setText(wb.getLang().getString("profit"));
744         quoteModel.setLang();
745         lineModel.setLang();
746     }
747
748     private void setLinesColumnWidths() {
749         TableColumn col = linesTable.getColumnModel().getColumn(0); //name
750
col.setPreferredWidth(170);
751         col = linesTable.getColumnModel().getColumn(1); //qty
752
col.setPreferredWidth(80);
753         col = linesTable.getColumnModel().getColumn(2); //model
754
col.setPreferredWidth(80);
755         col = linesTable.getColumnModel().getColumn(3); //cost
756
col.setPreferredWidth(80);
757         col = linesTable.getColumnModel().getColumn(4); //unit cost
758
col.setPreferredWidth(80);
759         col = linesTable.getColumnModel().getColumn(5); //total
760
col.setPreferredWidth(80);
761         col = linesTable.getColumnModel().getColumn(6); //desc
762
col.setPreferredWidth(260);
763     }
764 }
765
Popular Tags