KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > OppPanel


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

19 /**
20  * This class implements the Opportunity tab panel
21  * users see when they use the MainWindow GUI
22  */

23 public class OppPanel extends JPanel
24     implements DateEditorDialogListener, GUIChars {
25
26     private final static int STRUT_LEN=3;
27     private CalendarDialog calendarDialog;
28     private Whiteboard wb;
29
30     private JLabel nameLabel = new JLabel();
31     private JTextField name = new JTextField();
32
33     private JLabel createDtLabel = new JLabel();
34     private JTextField createDtField = new JTextField();
35
36     private JLabel dollarValueLabel = new JLabel();
37     private JTextField dollarValue = new JTextField("0");
38
39     private JLabel createdByLabel = new JLabel("Created By");
40     private JTextField createdByField = new JTextField("");
41
42     private JLabel stageLabel = new JLabel();
43     private JComboBox stage = new JComboBox(Opportunity.ALL_STAGES);
44
45     private JLabel custLabel = new JLabel();
46     private JComboBox custName = new JComboBox();
47
48     private JLabel groupLabel = new JLabel();
49     private JTextField groupField = new JTextField("");
50
51     private JLabel primSalesLabel = new JLabel();
52     private JComboBox primSalesman = new JComboBox();
53
54     private JLabel probLabel = new JLabel();
55     private JComboBox probability = new JComboBox(Opportunity.PROB);
56
57     private JLabel leadSrcLabel = new JLabel();
58     private JComboBox leadSrcCombo = new JComboBox();
59
60     private JLabel typeLabel = new JLabel();
61     private JComboBox typeCombo = new JComboBox();
62
63     private JLabel closeDateLabel = new JLabel();
64     private JButton closeDtButton = new JButton();
65
66     private JPanel descPanel = new JPanel();
67     private JTextArea descTextArea = new JTextArea(15, 30);
68     private JScrollPane descScrollPane = null;
69
70     private JPanel teamPanel = new JPanel();
71     private JScrollPane groupMembersScrollPane = null;
72     private JList groupMembersList = new JList();
73
74     private JButton applyButton = new JButton("Apply");
75
76     private Vector groupNames = new Vector();
77
78     /**
79      * construct the opp panel
80      */

81     public OppPanel() {
82         super(new BorderLayout());
83
84         wb = MainWindow.getWhiteboard();
85
86         calendarDialog = new CalendarDialog(MainWindow.getMainParent(), this, true);
87
88         JPanel detailPanel = new JPanel();
89         detailPanel.setBorder(new EtchedBorder());
90         detailPanel.setLayout( new GridBagLayout());
91         GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
92
93         nameLabel.setText("Name");
94         nameLabel.setForeground(MainWindow.LETTERS);
95         nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
96         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
97         gridBagConstraints2.gridx = 0;
98         gridBagConstraints2.gridy = 0;
99         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
100         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
101         gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
102         detailPanel.add(nameLabel, gridBagConstraints2);
103
104         name.setText("name");
105         name.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
106         name.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
107         name.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
108         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
109         gridBagConstraints2.gridx = 1;
110         gridBagConstraints2.gridy = 0;
111         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
112         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
113         gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
114         detailPanel.add(name, gridBagConstraints2);
115
116         groupLabel.setText("Group");
117         groupLabel.setForeground(MainWindow.LETTERS);
118         groupLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
119         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints2.gridx = 2;
121         gridBagConstraints2.gridy = 0;
122         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
123         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
124         detailPanel.add(groupLabel, gridBagConstraints2);
125
126         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
127         gridBagConstraints2.gridx = 3;
128         gridBagConstraints2.gridy = 0;
129         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
130         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
131         groupField.setEditable(false);
132         groupField.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
133         groupField.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
134         groupField.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
135         detailPanel.add(groupField, gridBagConstraints2);
136
137         primSalesLabel.setText("Primary Sales Person");
138         createDtLabel.setText("Created Date");
139         createDtLabel.setForeground(MainWindow.LETTERS);
140         createDtLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
141         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints2.gridx = 0;
143         gridBagConstraints2.gridy = 1;
144         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
145         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
146         gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
147         detailPanel.add(createDtLabel, gridBagConstraints2);
148
149         createDtField.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
150         createDtField.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
151         createDtField.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
152         createDtField.setEditable(false);
153         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
154         gridBagConstraints2.gridx = 1;
155         gridBagConstraints2.gridy = 1;
156         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
157         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
158         gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
159         detailPanel.add(createDtField, gridBagConstraints2);
160
161         createdByLabel.setForeground(MainWindow.LETTERS);
162         createdByLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
163         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints2.gridx = 2;
165         gridBagConstraints2.gridy = 1;
166         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
167         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
168         gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
169         detailPanel.add(createdByLabel, gridBagConstraints2);
170
171         createdByField.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
172         createdByField.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
173         createdByField.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
174         createdByField.setEditable(false);
175         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints2.gridx = 3;
177         gridBagConstraints2.gridy = 1;
178         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
180         gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
181         detailPanel.add(createdByField, gridBagConstraints2);
182
183         stageLabel.setText("Sales Stage");
184         stageLabel.setForeground(MainWindow.LETTERS);
185         stageLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
186         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
187         gridBagConstraints2.gridx = 0;
188         gridBagConstraints2.gridy = 2;
189         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
190         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
191         gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
192         detailPanel.add(stageLabel, gridBagConstraints2);
193
194         stage.setName("sales stage");
195         stage.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
196         stage.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
197         stage.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
198         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
199         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
200         gridBagConstraints2.gridx = 1;
201         gridBagConstraints2.gridy = 2;
202         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
203         detailPanel.add(stage, gridBagConstraints2);
204
205         custLabel.setText("Customer");
206         custLabel.setForeground(MainWindow.LETTERS);
207         custLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
208         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints2.gridx = 2;
210         gridBagConstraints2.gridy = 2;
211         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
212         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
213         detailPanel.add(custLabel, gridBagConstraints2);
214
215         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
216         gridBagConstraints2.gridx = 3;
217         gridBagConstraints2.gridy = 2;
218         custName.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
219         custName.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
220         custName.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
221         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
222         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
223         detailPanel.add(custName, gridBagConstraints2);
224
225
226
227         dollarValueLabel.setText("Dollar Value");
228         dollarValueLabel.setForeground(MainWindow.LETTERS);
229         dollarValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
230         primSalesLabel.setForeground(MainWindow.LETTERS);
231         primSalesLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
232         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
233         gridBagConstraints2.gridx = 0;
234         gridBagConstraints2.gridy = 3;
235         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
236         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
237         gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
238         detailPanel.add(primSalesLabel, gridBagConstraints2);
239
240         primSalesman.setName("prime sales");
241         primSalesman.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
242         primSalesman.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
243         primSalesman.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
244         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
245         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
246         gridBagConstraints2.gridx = 1;
247         gridBagConstraints2.gridy = 3;
248         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
249         detailPanel.add(primSalesman, gridBagConstraints2);
250
251         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
252         gridBagConstraints2.gridx = 2;
253         gridBagConstraints2.gridy = 3;
254         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
255         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
256         detailPanel.add(dollarValueLabel, gridBagConstraints2);
257
258         dollarValue.setText("dollar value");
259         dollarValue.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
260         dollarValue.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
261         dollarValue.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
262         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
263         gridBagConstraints2.gridx = 3;
264         gridBagConstraints2.gridy = 3;
265         gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
266         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
267         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
268         detailPanel.add(dollarValue, gridBagConstraints2);
269         dollarValue.addFocusListener(
270             new FocusListener() {
271                 public void focusGained(FocusEvent e) { }
272                 public void focusLost(FocusEvent e) {
273                     int x = Integer.parseInt(dollarValue.getText());
274                     dollarValue.setText(Prefs.wholeMoney.format(x));
275                 }
276             }
277         );
278
279         probLabel.setText("Probability");
280         probLabel.setForeground(MainWindow.LETTERS);
281         probLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
282         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
283         gridBagConstraints2.gridx = 0;
284         gridBagConstraints2.gridy = 4;
285         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
286         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
287         gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
288         detailPanel.add(probLabel, gridBagConstraints2);
289
290         probability.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
291         probability.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
292         probability.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
293         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
294         gridBagConstraints2.gridx = 1;
295         gridBagConstraints2.gridy = 4;
296         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
297         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
298         detailPanel.add(probability, gridBagConstraints2);
299
300         closeDateLabel.setText("Close Date");
301         closeDateLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
302         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
303         gridBagConstraints2.gridx = 2;
304         gridBagConstraints2.gridy = 4;
305         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
306         gridBagConstraints2.ipadx = 5;
307         gridBagConstraints2.ipady = 5;
308         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
309         detailPanel.add(closeDateLabel, gridBagConstraints2);
310
311         Date dummy = new Date();
312         closeDtButton.setHorizontalAlignment(SwingConstants.LEFT);
313         closeDtButton.setText(Prefs.dateFormat.format(dummy));
314         closeDtButton.setMargin(new Insets(0,0,0,0));
315         closeDtButton.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
316         closeDtButton.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
317         closeDtButton.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
318         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
319         gridBagConstraints2.gridx = 3;
320         gridBagConstraints2.gridy = 4;
321         gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
322         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
323         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
324         detailPanel.add(closeDtButton, gridBagConstraints2);
325
326         leadSrcLabel.setText("Lead Source");
327         leadSrcLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
328         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
329         gridBagConstraints2.gridx = 0;
330         gridBagConstraints2.gridy = 5;
331         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
332         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
333         gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
334         detailPanel.add(leadSrcLabel, gridBagConstraints2);
335
336         leadSrcCombo.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(Opportunity.ALL_LEADS));
337         leadSrcCombo.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
338         leadSrcCombo.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
339         leadSrcCombo.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
340         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
341         gridBagConstraints2.gridx = 1;
342         gridBagConstraints2.gridy = 5;
343         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
344         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
345         gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
346         detailPanel.add(leadSrcCombo, gridBagConstraints2);
347
348         typeLabel.setText("Type");
349         typeLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
350         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
351         gridBagConstraints2.gridx = 2;
352         gridBagConstraints2.gridy = 5;
353         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
354         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
355         detailPanel.add(typeLabel, gridBagConstraints2);
356
357         typeCombo.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(Opportunity.ALL_LEAD_TYPES));
358         typeCombo.setPreferredSize(new Dimension(200, Prefs.FIELD_HEIGHT));
359         typeCombo.setMaximumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
360         typeCombo.setMinimumSize(new Dimension(200, Prefs.FIELD_HEIGHT));
361         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
362         gridBagConstraints2.gridx = 3;
363         gridBagConstraints2.gridy = 5;
364         gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
365         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
366         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
367         detailPanel.add(typeCombo, gridBagConstraints2);
368
369
370         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
371         gridBagConstraints2.gridx = 0;
372         gridBagConstraints2.gridy = 6;
373         gridBagConstraints2.gridwidth = 1;
374         gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
375         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
376         teamPanel.setBorder(new TitledBorder("Sales Team"));
377         groupMembersScrollPane = new JScrollPane(groupMembersList);
378         //groupMembersScrollPane.setBorder(new TitledBorder("Sales Team"));
379
groupMembersScrollPane.setPreferredSize(new Dimension(120, 90));
380         groupMembersScrollPane.setMinimumSize(new Dimension(120, 90));
381         groupMembersScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
382         groupMembersScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
383
384         teamPanel.add(groupMembersScrollPane);
385         //detailPanel.add(groupMembersScrollPane, gridBagConstraints2);
386
detailPanel.add(teamPanel, gridBagConstraints2);
387
388         add(detailPanel, BorderLayout.CENTER);
389         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
390         gridBagConstraints2.gridx = 1;
391         gridBagConstraints2.gridy = 6;
392         //gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
393
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
394         gridBagConstraints2.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
395         descTextArea.setLineWrap(true);
396         descTextArea.setWrapStyleWord(true);
397         descTextArea.setRows(4);
398         descTextArea.setColumns(50);
399         descScrollPane = new JScrollPane(descTextArea);
400         //descScrollPane.setBorder(new TitledBorder("Description"));
401
descScrollPane.setPreferredSize(new Dimension(200, 90));
402         descScrollPane.setMinimumSize(new Dimension(200, 90));
403         descScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
404         descScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
405
406         descPanel.add(descScrollPane);
407         //detailPanel.add(descScrollPane, gridBagConstraints2);
408
detailPanel.add(descPanel, gridBagConstraints2);
409
410         add(detailPanel, BorderLayout.CENTER);
411
412         JPanel buttonPanel = new JPanel();
413         buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
414         buttonPanel.add(applyButton);
415         add(buttonPanel, BorderLayout.SOUTH);
416
417         closeDtButton.addActionListener(
418             new ActionListener() {
419                 public void actionPerformed(ActionEvent e) {
420                     calendarDialog.show();
421                 }
422             }
423         );
424
425         applyButton.addActionListener(
426             new ActionListener() {
427                 public void actionPerformed(ActionEvent e) {
428                     updateOpportunity();
429                 }
430             }
431         );
432
433         setColors();
434         setFonts();
435         setLang();
436     }
437
438     /**
439      * load the info into the panel
440      */

441     public final void load() {
442         try {
443             loadCustomerList();
444             ArrayList persons = wb.getSalesPersonNames();
445             primSalesman.setModel(
446                 new DefaultComboBoxModel(persons.toArray()) );
447         } catch (Exception JavaDoc e) {
448             ErrorHandler.show(this, e);
449         }
450     }
451
452     /**
453      * lod the customer list info
454      */

455     public final void loadCustomerList() {
456         try {
457             TreeMap allNames = wb.getAllCustNames(false);
458             custName.setModel(new DefaultComboBoxModel(
459                 allNames.values().toArray()));
460         } catch (AngError e) {
461             ErrorHandler.show(this, e);
462         }
463     }
464
465     /**
466      * enable or disable the panel's fields
467      * @param t true or false
468      */

469     public final void setEnabled(boolean t) {
470          name.setEnabled(t);
471          createDtField.setEnabled(t);
472          dollarValue.setEnabled(t);
473          probability.setEnabled(t);
474          stage.setEnabled(t);
475          custName.setEnabled(t);
476          groupField.setEnabled(t);
477          primSalesman.setEnabled(t);
478     }
479
480     /**
481      * update the current opportunity
482      */

483     public final void updateOpportunity() {
484         Opportunity opp = wb.getCurrentOpportunity();
485         opp.setName(name.getText());
486         Number JavaDoc num = Prefs.wholeMoney.parse(dollarValue.getText(), new ParsePosition(0));
487         opp.setDollarValue(num.intValue());
488         opp.setDesc(descTextArea.getText());
489         opp.setProbability((String JavaDoc)(probability.getSelectedItem()));
490         opp.setStage((String JavaDoc)stage.getSelectedItem());
491         opp.setLeadSource((String JavaDoc)leadSrcCombo.getSelectedItem());
492         opp.setLeadType((String JavaDoc)typeCombo.getSelectedItem());
493         //look up the customer
494
try {
495             Customer c = wb.getCustomer((String JavaDoc)custName.getSelectedItem());
496             opp.setCustomer(c);
497         } catch (AngError e) {
498             ErrorHandler.show(this, e);
499         }
500
501         int index = primSalesman.getSelectedIndex();
502         try {
503             TreeMap allSPs = wb.getSalesPersons();
504             Object JavaDoc[] values = allSPs.values().toArray();
505             SalesPerson p = (SalesPerson)values[index];
506             opp.setPrimeSalesPerson(p);
507
508             wb.setCurrentOpportunity(opp);
509             wb.updateOpportunity(opp);
510             MainWindow.refreshOpportunity(); //refresh all screens
511
} catch (AngError ae) {
512             ErrorHandler.show(this, ae);
513         }
514     }
515
516
517     /**
518      * set the panel to the current opportunity
519      */

520     public final void refreshOpportunity() {
521         Opportunity opp = wb.getCurrentOpportunity();
522         Utility.strSet(name, opp.getName());
523         Utility.strSet(groupField, opp.getGroupName());
524         Utility.strSet(descTextArea, opp.getDesc());
525         createDtField.setText(Prefs.dateFormat.format(opp.getModifiedDate()));
526         closeDtButton.setText(Prefs.dateFormat.format(opp.getCloseDate()));
527         createdByField.setText(opp.getModifiedBy());
528         Utility.strSet(dollarValue, Prefs.wholeMoney.format(opp.getDollarValue()));
529         probability.setSelectedItem(opp.getProbability());
530         Utility.comboSet(stage, opp.getStage());
531         Utility.comboSet(typeCombo, opp.getLeadType());
532         Utility.comboSet(leadSrcCombo, opp.getLeadSource());
533
534         if (opp.getCustomer() != null) {
535             Utility.comboSet(custName, opp.getCustomer().getName());
536         } else {
537             Exception JavaDoc x = new Exception JavaDoc();
538             x.printStackTrace();
539         }
540
541         try {
542             TreeMap users = wb.getUsersInGroup(opp.getGroupName());
543             Object JavaDoc[] keys = users.keySet().toArray();
544             groupMembersList.setListData(keys);
545             groupMembersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
546
547             TreeMap allSPs = wb.getSalesPersons();
548             Object JavaDoc[] values = allSPs.values().toArray();
549             SalesPerson sp = null;
550             if (opp.getPrimeSalesPerson() != null) {
551                 for (int i=0;i<allSPs.size();i++) {
552                     sp = (SalesPerson)values[i];
553                     if (sp.getID().equals(opp.getPrimeSalesPerson().getID())) {
554                         Utility.comboSet(primSalesman, sp.getID());
555                     }
556                 }
557             }
558
559             if (opp.getPrimeSalesPerson() == null)
560                 ;
561             else
562                 Utility.comboSet(primSalesman, opp.getPrimeSalesPerson().getAddress().getFormattedName());
563
564         } catch (AngError e) {
565             ErrorHandler.show(this, e);
566         }
567     }
568
569     /**
570      * set the panel's colors
571      */

572     public final void setColors() {
573         int labels=0,fields=0,buttons=0;
574         Component[] components = getComponents();
575         for (int i=0;i<components.length;i++) {
576             if (components[i] instanceof JLabel)
577                 labels++;
578             else
579             if (components[i] instanceof JTextField)
580                 fields++;
581             else
582             if (components[i] instanceof JButton)
583                 buttons++;
584         }
585
586         nameLabel.setForeground(MainWindow.LETTERS);
587         createDtLabel.setForeground(MainWindow.LETTERS);
588         dollarValueLabel.setForeground(MainWindow.LETTERS);
589         stageLabel.setForeground(MainWindow.LETTERS);
590         custLabel.setForeground(MainWindow.LETTERS);
591         primSalesLabel.setForeground(MainWindow.LETTERS);
592         probLabel.setForeground(MainWindow.LETTERS);
593         probability.setBackground(Color.white);
594         leadSrcLabel.setForeground(MainWindow.LETTERS);
595         createdByLabel.setForeground(MainWindow.LETTERS);
596         typeLabel.setForeground(MainWindow.LETTERS);
597         closeDateLabel.setForeground(MainWindow.LETTERS);
598         closeDtButton.setBackground(Color.white);
599         groupLabel.setForeground(MainWindow.LETTERS);
600         stage.setBackground(Color.white);
601         primSalesman.setBackground(Color.white);
602         custName.setBackground(Color.white);
603         leadSrcCombo.setBackground(Color.white);
604         typeCombo.setBackground(Color.white);
605     }
606
607     /**
608      * set the panel's fonts
609      */

610     public final void setFonts() {
611         leadSrcLabel.setFont(MainWindow.LABEL_FONT);
612         nameLabel.setFont(MainWindow.LABEL_FONT);
613         name.setFont(MainWindow.FIELD_FONT);
614         createDtLabel.setFont(MainWindow.LABEL_FONT);
615         createDtField.setFont(MainWindow.FIELD_FONT);
616         dollarValueLabel.setFont(MainWindow.LABEL_FONT);
617         dollarValue.setFont(MainWindow.FIELD_FONT);
618         stageLabel.setFont(MainWindow.LABEL_FONT);
619         stage.setFont(MainWindow.FIELD_FONT);
620         custLabel.setFont(MainWindow.LABEL_FONT);
621         custName.setFont(MainWindow.FIELD_FONT);
622         primSalesLabel.setFont(MainWindow.LABEL_FONT);
623         primSalesman.setFont(MainWindow.FIELD_FONT);
624         probLabel.setFont(MainWindow.LABEL_FONT);
625         probability.setFont(MainWindow.FIELD_FONT);
626         applyButton.setFont(MainWindow.LABEL_FONT);
627         leadSrcCombo.setFont(MainWindow.FIELD_FONT);
628         typeCombo.setFont(MainWindow.FIELD_FONT);
629         closeDtButton.setFont(MainWindow.FIELD_FONT);
630         descTextArea.setFont(MainWindow.FIELD_FONT);
631         groupLabel.setFont(MainWindow.LABEL_FONT);
632         closeDateLabel.setFont(MainWindow.LABEL_FONT);
633         typeLabel.setFont(MainWindow.LABEL_FONT);
634         createdByLabel.setFont(MainWindow.LABEL_FONT);
635         createdByField.setFont(MainWindow.FIELD_FONT);
636     }
637
638     /**
639      * this is a callback that gets the date from the
640      * CalendarDialog after the user selects a date
641      * @param d the date to set to
642      */

643     public final void setDate(Date d) {
644         closeDtButton.setText(Prefs.dateFormat.format(d));
645         Opportunity opp = wb.getCurrentOpportunity();
646         opp.setCloseDate(d);
647     }
648
649     /**
650      * clear the screen
651      */

652     public final void clearOpportunity() {
653         Utility.strSet(name, null);
654         Utility.strSet(groupField, null);
655         Utility.strSet(descTextArea, null);
656         createDtField.setText("");
657         closeDtButton.setText("");
658         createdByField.setText("");
659         Utility.strSet(dollarValue, null);
660         probability.setSelectedIndex(0);
661         stage.setSelectedIndex(0);
662         typeCombo.setSelectedIndex(0);
663         leadSrcCombo.setSelectedIndex(0);
664         custName.setSelectedIndex(0);
665     }
666
667     /**
668      * set the screen's language
669      */

670     public final void setLang() {
671         nameLabel.setText(wb.getLang().getString("name"));
672         groupLabel.setText(wb.getLang().getString("group"));
673         primSalesLabel.setText(wb.getLang().getString("primeSalesPerson"));
674         createDtLabel.setText(wb.getLang().getString("createdDate"));
675         stageLabel.setText(wb.getLang().getString("salesStage"));
676         custLabel.setText(wb.getLang().getString("customer"));
677         dollarValueLabel.setText(wb.getLang().getString("dollarValue"));
678         probLabel.setText(wb.getLang().getString("probability"));
679         closeDateLabel.setText(wb.getLang().getString("closeDate"));
680         leadSrcLabel.setText(wb.getLang().getString("leadSource"));
681         typeLabel.setText(wb.getLang().getString("type"));
682         teamPanel.setBorder(
683             new TitledBorder(
684                 null,
685                 wb.getLang().getString("salesTeam"),
686                 TitledBorder.DEFAULT_JUSTIFICATION,
687                 TitledBorder.DEFAULT_POSITION,
688                 MainWindow.LABEL_FONT,
689                 MainWindow.LETTERS
690             )
691         );
692         descPanel.setBorder(
693             new TitledBorder(
694                 null,
695                 wb.getLang().getString("description"),
696                 TitledBorder.DEFAULT_JUSTIFICATION,
697                 TitledBorder.DEFAULT_POSITION,
698                 MainWindow.LABEL_FONT,
699                 MainWindow.LETTERS
700             )
701         );
702         applyButton.setText(wb.getLang().getString("apply"));
703     }
704
705     /**
706      * update the customer name list, and reset the current selection
707      * after the update to original value, this is done when
708      * someone adds a new customer, we want the new customer to show up
709      * in the customer combo box
710      */

711     public final void updateCustomerList() {
712         String JavaDoc currCustName = (String JavaDoc)custName.getSelectedItem();
713         loadCustomerList();
714         custName.setSelectedItem(currCustName);
715     }
716 }
717
Popular Tags