KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > SyncDialog


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

20 /**
21  * This class handles the process of uploading changed and/or
22  * deleted objects from the local data to the remote database.
23  * It also handles the downloading of a user's data FROM
24  * the remote database to the local laptop disk. These two
25  * tasks are initiated via the GUI by the user whenever they
26  * want to SYNChronize their work.
27  */

28 public class SyncDialog extends JDialog implements GUIChars {
29
30     private Whiteboard wb=null;
31     private BizServices localServer;
32     private SellwinSession remoteServer;
33     private java.awt.Frame JavaDoc parent;
34     private JPanel buttonPanel, mainPanel, timesPanel;
35     private JButton syncButton, completeRefreshButton, closeButton;
36
37     private JLabel lastSyncLabel, currEndLabel, currStartLabel;
38     private JTextField currEndField, currStartField, lastSyncField;
39     private static final int FIELD_WIDTH=140;
40
41     private ArrayList stats = new ArrayList();
42     private JTable statTable = new JTable();
43     private JScrollPane statTableScrollPane = new JScrollPane();
44     private StatTableModel statModel;
45     private String JavaDoc READY_STAT = "Ready";
46     private String JavaDoc RUNNING_STAT = "Running";
47     private String JavaDoc FINISH_STAT = "Finished";
48     private final static int STAT_ROLES =0;
49     private final static int STAT_GROUPS =1;
50     private final static int STAT_GROUP_MEMBERS =2;
51     private final static int STAT_SALES_PERSONS =3;
52     private final static int STAT_PRODUCTS =4;
53     private final static int STAT_CAMPAIGNS =5;
54     private final static int STAT_LEADS =6;
55     private final static int STAT_CUSTOMERS =7;
56     private final static int STAT_OPPS =8;
57     private final static int STAT_TAX =9;
58
59     /**
60      * Creates new form SyncDialog
61      * @param parent the SyncDialog's parent
62      * @param modal signifies the type of SyncDialog modality
63      */

64     public SyncDialog(java.awt.Frame JavaDoc parent, boolean modal) {
65         super(parent, modal);
66
67         this.parent = parent;
68
69         wb = MainWindow.getWhiteboard();
70         initComponents();
71         initStatTable();
72
73         setLang();
74         setFonts();
75         setColors();
76         getInterfaces();
77         setSize(455, 365);
78     }
79
80     /**
81      * get the local and remote interfaces, both
82      * are required to get data from the server and
83      * store it locally
84      */

85     private final void getInterfaces() {
86         SellwinSession w = wb.getRemIF();
87         try {
88             if (w instanceof BizServices) {
89                 localServer = (BizServices)w;
90                 Properties props = wb.getProps();
91                 String JavaDoc serverName = (String JavaDoc)(props.getProperty(Prefs.SERVER_NAME));
92                 InitialContext ic = Utility.getEJBContext(serverName, "1099");
93                 SellwinSessionHome sellwinHome = (SellwinSessionHome) ic.lookup("SellWinSessionBean");
94
95                 remoteServer = sellwinHome.create();
96             }
97             else {
98                 remoteServer = w;
99                 localServer = new BizServices(Prefs.MYSQL);
100                 localServer.init2Tier("jdbc:mysql:///sellwin", "jmccormi", "jeffery2");
101             }
102         } catch (Exception JavaDoc e) {
103             ErrorHandler.show(parent, e);
104         }
105     }
106
107     /**
108      * This method is called from within the constructor to
109      * initialize the form.
110      */

111     private final void initComponents() {
112         statTable = new JTable();
113         buttonPanel = new JPanel();
114         syncButton = new JButton();
115         completeRefreshButton = new JButton();
116         closeButton = new JButton();
117         mainPanel = new JPanel();
118
119         lastSyncLabel = new javax.swing.JLabel JavaDoc();
120         lastSyncField = new javax.swing.JTextField JavaDoc();
121         lastSyncField.setMinimumSize(new Dimension(FIELD_WIDTH, Prefs.FIELD_HEIGHT));
122         lastSyncField.setPreferredSize(new Dimension(FIELD_WIDTH, Prefs.FIELD_HEIGHT));
123         if (wb.getCurrentUser().getSyncDate() == null)
124             lastSyncField.setText("");
125         else
126             lastSyncField.setText(
127                 Prefs.dateTimeFormat.format(wb.getCurrentUser().getSyncDate()));
128
129         currStartLabel = new javax.swing.JLabel JavaDoc();
130         currStartField = new javax.swing.JTextField JavaDoc();
131         currStartField.setMinimumSize(new Dimension(FIELD_WIDTH, Prefs.FIELD_HEIGHT));
132         currStartField.setPreferredSize(new Dimension(FIELD_WIDTH, Prefs.FIELD_HEIGHT));
133         currEndLabel = new javax.swing.JLabel JavaDoc();
134         currEndField = new javax.swing.JTextField JavaDoc();
135         currEndField.setMinimumSize(new Dimension(FIELD_WIDTH, Prefs.FIELD_HEIGHT));
136         currEndField.setPreferredSize(new Dimension(FIELD_WIDTH, Prefs.FIELD_HEIGHT));
137
138      
139         setTitle(wb.getLang().getString("syncDialog"));
140         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
141             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
142                 closeDialog();
143             }
144         });
145         
146         syncButton.setText(wb.getLang().getString("sync"));
147         syncButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
148             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
149                 java.util.Date JavaDoc lastSyncDate = wb.getCurrentUser().getSyncDate();
150                 System.out.println("syncing with sync_date="+lastSyncDate);
151                 syncAction(evt, lastSyncDate);
152             }
153         });
154         
155         buttonPanel.add(syncButton);
156
157         completeRefreshButton.setText(wb.getLang().getString("completeRefresh"));
158         completeRefreshButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
159             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
160
161                 //use a date in 1969 as the sync date to cause a complete
162
//refresh of data during the synchronization
163

164                 java.util.Date JavaDoc lastSyncDate = new java.util.Date JavaDoc(1);
165
166                 //
167
//remove the local data
168
//
169
try {
170                     localServer.truncateDB();
171
172                     syncAction(evt, lastSyncDate);
173                 } catch (Exception JavaDoc e) {
174                     ErrorHandler.show(parent, e);
175                 }
176             }
177         });
178         
179         buttonPanel.add(completeRefreshButton);
180         
181         closeButton.setText(wb.getLang().getString("close"));
182         closeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
183             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
184                 closeDialog();
185             }
186         });
187         
188         buttonPanel.add(closeButton);
189         
190         getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
191        
192         statTable.setPreferredSize(new Dimension(350, 180));
193         statTable.setMaximumSize(new Dimension(350, 180));
194         statTable.setMinimumSize(new Dimension(350, 180));
195         statTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
196         statTableScrollPane.setMinimumSize(new Dimension(350, 180));
197         statTableScrollPane.setMaximumSize(new Dimension(350, 180));
198         statTableScrollPane.setPreferredSize(new Dimension(350, 180));
199         statTableScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
200         statTableScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
201         statTableScrollPane.setViewportView(statTable);
202
203         mainPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
204         java.awt.GridBagConstraints JavaDoc gridBagConstraints1;
205         
206         mainPanel.setBorder(new javax.swing.border.EtchedBorder JavaDoc());
207         
208         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints1.gridx = 0;
210         gridBagConstraints1.gridy = 0;
211         gridBagConstraints1.gridwidth = 2;
212         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
213         mainPanel.add(statTableScrollPane, gridBagConstraints1);
214         
215         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
216         gridBagConstraints1.gridx = 0;
217         gridBagConstraints1.gridy = 1;
218         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
219         mainPanel.add(currStartLabel, gridBagConstraints1);
220         
221         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
222         gridBagConstraints1.gridx = 1;
223         gridBagConstraints1.gridy = 1;
224         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
225         mainPanel.add(currStartField, gridBagConstraints1);
226         
227         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
228         gridBagConstraints1.gridx = 0;
229         gridBagConstraints1.gridy = 2;
230         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
231         mainPanel.add(currEndLabel, gridBagConstraints1);
232         
233         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
234         gridBagConstraints1.gridx = 1;
235         gridBagConstraints1.gridy = 2;
236         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
237         mainPanel.add(currEndField, gridBagConstraints1);
238
239         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
240         gridBagConstraints1.gridx = 0;
241         gridBagConstraints1.gridy = 3;
242         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
243         mainPanel.add(lastSyncLabel, gridBagConstraints1);
244         
245         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
246         gridBagConstraints1.gridx = 1;
247         gridBagConstraints1.gridy = 3;
248         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
249         mainPanel.add(lastSyncField, gridBagConstraints1);
250         
251         getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);
252         
253         pack();
254
255     }
256
257     /**
258      * the action that gets performed when a user presses
259      * the 'Sync' button
260      * @param evt the action event
261      */

262     private final void syncAction(java.awt.event.ActionEvent JavaDoc evt, java.util.Date JavaDoc lastSyncDate) {
263
264         try {
265
266             currStartField.setText(
267                 Prefs.dateTimeFormat.format(new java.util.Date JavaDoc())
268             );
269             currEndField.setText("");
270
271             //perform upload tasks before the download tasks
272
//get the list of locally deleted objects
273

274             //
275
//process locally deleted data
276
//
277
ArrayList deletes = localServer.getDeletes();
278             DeleteInfo d;
279             System.out.println("Delete List follows ("+deletes.size()+")...");
280             for (int i=0;i<deletes.size();i++) {
281                 d = (DeleteInfo)deletes.get(i);
282                 System.out.println("PK="+d.pk +" Class="+ d.className);
283             }
284             remoteServer.uploadDeletes(deletes);
285             localServer.resetDeletes();
286
287             //
288
//look for and process all the locally updated data
289
//
290
ArrayList opps = localServer.getOpportunities(wb.getCurrentUser(), null);
291             uploadChanges(opps);
292
293
294             //
295
//load from remote to local
296
//
297

298
299             /**
300              * ROLES
301              */

302             int localUpdates=0, localInserts=0;
303             setStat(STAT_ROLES, RUNNING_STAT, localInserts, localUpdates);
304
305             ArrayList roles = remoteServer.getAllUserRoles(lastSyncDate);
306             System.out.println("got " + roles.size() + " roles from remote");
307             UserRole localUserRole, remoteUserRole;
308             for (int i=0;i<roles.size();i++) {
309                 remoteUserRole = (UserRole)roles.get(i);
310                 localUserRole = localServer.getUserRole(remoteUserRole.getName());
311                 if (localUserRole == null) {
312                     localServer.loadUserRole(remoteUserRole);
313                     localInserts++;
314                 } else {
315                     localServer.updateUserRole(remoteUserRole);
316                     localUpdates++;
317                 }
318             }
319
320             setStat(STAT_ROLES, FINISH_STAT, localInserts, localUpdates);
321
322             /**
323              * GROUPS
324              */

325             localInserts=0; localUpdates=0;
326             setStat(STAT_GROUPS, RUNNING_STAT, localInserts, localUpdates);
327
328             Object JavaDoc[] values = remoteServer.getUserGroups(lastSyncDate);
329             System.out.println("got " + values.length + " user groups from remote");
330             UserGroup remoteUserGroup, localUserGroup;
331             for (int j=0;j<values.length;j++) {
332                 remoteUserGroup = (UserGroup)values[j];
333                 localUserGroup = localServer.getUserGroup(remoteUserGroup.getPK());
334                 if (localUserGroup == null) {
335                     localServer.loadUserGroup(remoteUserGroup);
336                     localInserts++;
337                 } else {
338                     localUpdates++;
339                     //no need to update these as this version had no
340
//fields to update...just update the stats to show
341
//some kind of status anyway
342
}
343             }
344
345             setStat(STAT_GROUPS, FINISH_STAT, localInserts, localUpdates);
346
347             /**
348              * SALES PERSONS
349              */

350             localInserts=0; localUpdates=0;
351             setStat(STAT_SALES_PERSONS, RUNNING_STAT, localInserts, localUpdates);
352
353             values = remoteServer.getSalesPersons(lastSyncDate);
354             System.out.println("got " + values.length + " sales persons from remote");
355             SalesPerson remoteSalesPerson, localSalesPerson;
356             for (int k=0;k<values.length;k++) {
357                 remoteSalesPerson = (SalesPerson)values[k];
358                 localSalesPerson = localServer.getSalesPerson(remoteSalesPerson.getPK());
359
360                 if (localSalesPerson == null) {
361                     localServer.loadSalesPerson(remoteSalesPerson);
362                     localInserts++;
363                 } else {
364                     localServer.updateSalesPerson(remoteSalesPerson);
365                     localUpdates++;
366                 }
367             }
368
369             setStat(STAT_SALES_PERSONS, FINISH_STAT, localInserts, localUpdates);
370
371             /**
372              * GROUP MEMBERS
373              */

374             localInserts=0; localUpdates=0;
375             setStat(STAT_GROUP_MEMBERS, RUNNING_STAT, localInserts, localUpdates);
376
377             ArrayList remoteMembers = remoteServer.getGroupMembers(lastSyncDate);
378             System.out.println("got " + remoteMembers.size() + " group members from remote");
379             UserGroupMember remoteGroupMember, localGroupMember;
380             for (int jj=0;jj<remoteMembers.size();jj++) {
381                 remoteGroupMember = (UserGroupMember)remoteMembers.get(jj);
382                 localGroupMember = localServer.getGroupMember(remoteGroupMember.getPK());
383                 if (localGroupMember == null) {
384                     localServer.loadGroupMember(remoteGroupMember);
385                     localInserts++;
386                 } else {
387                     localUpdates++;
388                     //nothing to update on this object so skip the update
389
//show updates in the stats for some visual
390
}
391             }
392
393             setStat(STAT_GROUP_MEMBERS, FINISH_STAT, localInserts, localUpdates);
394
395             /**
396              * PRODUCTS
397              */

398             localInserts=0; localUpdates=0;
399             setStat(STAT_PRODUCTS, RUNNING_STAT, localInserts, localUpdates);
400
401             ArrayList remoteProds = remoteServer.getProducts(lastSyncDate);
402             System.out.println("got " + remoteProds.size() + " products from remote");
403             Product localProd, remoteProd;
404             for (int m=0;m<remoteProds.size();m++) {
405                 remoteProd = (Product)remoteProds.get(m);
406                 localProd = localServer.getProduct(remoteProd.getPK());
407                 if (localProd == null) {
408                     localServer.loadProduct(remoteProd);
409                     localInserts++;
410                 } else {
411                     localServer.updateProduct(remoteProd);
412                     localUpdates++;
413                 }
414             }
415
416             setStat(STAT_PRODUCTS, FINISH_STAT, localInserts, localUpdates);
417
418             /**
419              * CAMPAIGNS
420              */

421             localInserts=0; localUpdates=0;
422             setStat(STAT_CAMPAIGNS, RUNNING_STAT, localInserts, localUpdates);
423
424             ArrayList remoteCamps = remoteServer.getCampaigns(lastSyncDate);
425             System.out.println("got " + remoteCamps.size() + " campaigns from remote");
426             Campaign remoteCampaign, localCampaign;
427             for (int n=0;n<remoteCamps.size();n++) {
428                 remoteCampaign = (Campaign)remoteCamps.get(n);
429                 localCampaign = localServer.getCampaign(remoteCampaign.getPK());
430                 if (localCampaign == null) {
431                     localServer.loadCampaign(remoteCampaign);
432                     localInserts++;
433                 } else {
434                     localUpdates++;
435                     //nothing to update right now, maybe in the future
436
//show updates for a visual in the stats table
437
}
438             }
439             setStat(STAT_CAMPAIGNS, FINISH_STAT, localInserts, localUpdates);
440
441             /**
442              * LEADS
443              */

444             localInserts=0; localUpdates=0;
445             setStat(STAT_LEADS, RUNNING_STAT, localInserts, localUpdates);
446
447             ArrayList remoteLeads = remoteServer.getCampaignLeads(lastSyncDate);
448             System.out.println("got " + remoteLeads.size() + " leads from remote");
449             Lead remoteLead, localLead;
450             for (int aj=0;aj < remoteLeads.size();aj++) {
451                 remoteLead = (Lead)remoteLeads.get(aj);
452                 localLead = localServer.getLead(remoteLead.getPK());
453                 if (localLead == null) {
454                     localServer.loadLead(remoteLead);
455                     localInserts++;
456                 } else {
457                     localServer.updateLead(remoteLead.getCampaignKey(), remoteLead);
458                     localUpdates++;
459                 }
460             }
461             setStat(STAT_LEADS, FINISH_STAT, localInserts, localUpdates);
462
463             /**
464              * CUSTOMERS
465              */

466             localInserts=0; localUpdates=0;
467             setStat(STAT_CUSTOMERS, RUNNING_STAT, localInserts, localUpdates);
468
469             ArrayList remoteCusts = remoteServer.getCustomers(lastSyncDate);
470             System.out.println("got " + remoteCusts.size() + " custs from remote");
471             Customer localCust, remoteCust;
472             for (int p=0;p<remoteCusts.size();p++) {
473                 remoteCust = (Customer)remoteCusts.get(p);
474                 localCust = localServer.getCustomer(remoteCust.getName());
475                 if (localCust == null) {
476                     localServer.loadCustomer(remoteCust);
477                     localInserts++;
478                 } else {
479                     localServer.updateCustomer(remoteCust);
480                     localUpdates++;
481                 }
482             }
483
484             setStat(STAT_CUSTOMERS, FINISH_STAT, localInserts, localUpdates);
485
486             /**
487              * OPPS
488              */

489             localInserts=0; localUpdates=0;
490             setStat(STAT_OPPS, RUNNING_STAT, localInserts, localUpdates);
491
492             ArrayList remoteOpps = remoteServer.getOpportunities(wb.getCurrentUser(), lastSyncDate);
493             System.out.println("got " + remoteOpps.size() + " opps from remote");
494             Opportunity remoteOpp, localOpp;
495             for (int x=0;x<remoteOpps.size();x++) {
496                 remoteOpp = (Opportunity)remoteOpps.get(x);
497                 localOpp = localServer.getOpportunity(remoteOpp.getPK());
498                 if (localOpp == null) {
499                     localServer.loadOpportunity(remoteOpp);
500                     localInserts++;
501                 } else {
502                     localServer.updateOpportunity(remoteOpp);
503                     localUpdates++;
504                 }
505             }
506             setStat(STAT_OPPS, FINISH_STAT, localInserts, localUpdates);
507
508             /**
509              * STATE_TAX
510              */

511             localInserts=0; localUpdates=0;
512             setStat(STAT_TAX, RUNNING_STAT, localInserts, localUpdates);
513     
514             ArrayList remoteTaxes = remoteServer.getStateTax(lastSyncDate);
515             System.out.println("got " + remoteTaxes.size() + " taxes from remote");
516             StateTax remoteTax, localTax;
517             for (int r=0;r<remoteTaxes.size();r++) {
518                 remoteTax = (StateTax)remoteTaxes.get(r);
519                 localTax = localServer.getTax(remoteTax.getCode());
520                 if (localTax == null) {
521                     localServer.loadTax(remoteTax);
522                     localInserts++;
523                 } else {
524                     localServer.updateTax(remoteTax);
525                     localUpdates++;
526                 }
527             }
528
529             setStat(STAT_TAX, FINISH_STAT, localInserts, localUpdates);
530
531             /**
532              * update this user's sync date to reflect this synchronization
533              * has occurred
534              */

535             wb.getCurrentUser().setSyncDate(new java.util.Date JavaDoc());
536             wb.updateSalesPerson(wb.getCurrentUser());
537
538             currEndField.setText(Prefs.dateTimeFormat.format(new java.util.Date JavaDoc()));
539
540         } catch (Exception JavaDoc e) {
541             e.printStackTrace();
542         }
543     }
544
545     /**
546      * Closes the dialog
547      * @param evt the action event
548      */

549     private final void closeDialog() {
550         resetStats();
551         setVisible(false);
552         dispose();
553     }
554
555
556
557     public void setColors() {
558     }
559
560     public void setFonts() {
561         statTable.setFont(MainWindow.FIELD_FONT);
562         syncButton.setFont(MainWindow.LABEL_FONT);
563         closeButton.setFont(MainWindow.LABEL_FONT);
564         completeRefreshButton.setFont(MainWindow.LABEL_FONT);
565     }
566
567     /**
568      * set the language type for this dialog
569      */

570     public final void setLang() {
571         System.out.println("SyncDialog setLang() called");
572         statModel.setLang();
573         currEndLabel.setText(wb.getLang().getString("currEnd"));
574         currStartLabel.setText(wb.getLang().getString("currStart"));
575         lastSyncLabel.setText(wb.getLang().getString("lastSync"));
576
577         setTitle(wb.getLang().getString("syncDialog"));
578         syncButton.setText(wb.getLang().getString("sync"));
579         completeRefreshButton.setText(wb.getLang().getString("completeRefresh"));
580         closeButton.setText(wb.getLang().getString("close"));
581
582         READY_STAT = wb.getLang().getString("ready");
583         RUNNING_STAT = wb.getLang().getString("running");
584         FINISH_STAT = wb.getLang().getString("finished");
585
586         Stat stat;
587         stat = (Stat)stats.get(STAT_ROLES);
588         stat.dataType = (String JavaDoc)wb.getLang().getString("roles");
589         stat = (Stat)stats.get(STAT_GROUPS);
590         stat.dataType = (String JavaDoc)wb.getLang().getString("groups");
591         stat = (Stat)stats.get(STAT_GROUP_MEMBERS);
592         stat.dataType = (String JavaDoc)wb.getLang().getString("groupMembers");
593         stat = (Stat)stats.get(STAT_SALES_PERSONS);
594         stat.dataType = (String JavaDoc)wb.getLang().getString("salesPersons");
595         stat = (Stat)stats.get(STAT_PRODUCTS);
596         stat.dataType = (String JavaDoc)wb.getLang().getString("products");
597         stat = (Stat)stats.get(STAT_CAMPAIGNS);
598         stat.dataType = (String JavaDoc)wb.getLang().getString("campaigns");
599         stat = (Stat)stats.get(STAT_LEADS);
600         stat.dataType = (String JavaDoc)wb.getLang().getString("leads");
601         stat = (Stat)stats.get(STAT_CUSTOMERS);
602         stat.dataType = (String JavaDoc)wb.getLang().getString("customers");
603         stat = (Stat)stats.get(STAT_OPPS);
604         stat.dataType = (String JavaDoc)wb.getLang().getString("opps");
605         stat = (Stat)stats.get(STAT_TAX);
606         stat.dataType = (String JavaDoc)wb.getLang().getString("tax");
607         reloadStatTable();
608     }
609
610     /**
611      * upload all changes to the local set of
612      * opportuntiies from the local disk to
613      * the remote server
614      * @param opps the current set of Opportunities
615      */

616     private final void uploadChanges(ArrayList opps) {
617         Opportunity o;
618
619         for (int i=0;i<opps.size();i++) {
620             o = (Opportunity)opps.get(i);
621             uploadOpportunityChanges(o);
622             uploadOrderChanges(o);
623             uploadActivityChanges(o);
624             uploadContactChanges(o);
625             uploadQuoteChanges(o);
626             uploadForecastChanges(o);
627         }
628     }
629
630     /**
631      * upload the changes for a given Opportunity
632      * @param o the Opportunity we are to process
633      */

634     private final void uploadOpportunityChanges(Opportunity o) {
635         try {
636             if (o.getAddedLocally()) {
637                 System.out.println("upload log: Opp " + o.getPK() + " was added");
638                 remoteServer.addOpportunity(o);
639             }
640
641             if (o.getUpdatedLocally()) {
642                 System.out.println("upload log: Opp " + o.getPK() + " was updated");
643                 remoteServer.updateOpportunity(o);
644             }
645         } catch (Exception JavaDoc e) {
646                 System.out.println("UPLOAD ERROR: Opportunity : OPP pk=" + o.getPK());
647                 System.out.println(e.getMessage());
648         }
649     }
650
651     /**
652      * upload some Order changes within a given
653      * Opportunity
654      * @param o the Opportunity we are processing
655      */

656     private final void uploadOrderChanges(Opportunity o) {
657         ArrayList orders = o.getOrders();
658         Order order;
659         for (int i=0;i<orders.size();i++) {
660             order = (Order)orders.get(i);
661             try {
662                 if (order.getAddedLocally()) {
663                     System.out.println("upload log: Order " + order.getPK() + " was added");
664                     remoteServer.addOrder(o.getPK(), order);
665                 }
666
667                 if (order.getUpdatedLocally()) {
668                     System.out.println("upload log: Order " + order.getPK() + " was updated");
669                     remoteServer.updateOrder(o.getPK(), order);
670                 }
671             } catch (Exception JavaDoc e) {
672                 System.out.println("UPLOAD ERROR: Order : pk="+order.getPK() + " OPP pk=" + o.getPK());
673                 System.out.println(e.getMessage());
674             }
675         }
676     }
677
678     /**
679      * upload activity changes for a given opportunity
680      * @param o the Opportunity we are processing
681      */

682     private final void uploadActivityChanges(Opportunity o) {
683         ArrayList acts = o.getActivities();
684         Activity act;
685         for (int i=0;i<acts.size();i++) {
686             act = (Activity)acts.get(i);
687             try {
688                 if (act.getAddedLocally()) {
689                     System.out.println("upload log: Activity " + act.getPK() + " was added");
690                     remoteServer.addActivity(o.getPK(), act);
691                 }
692
693                 if (act.getUpdatedLocally()) {
694                     System.out.println("upload log: Activity " + act.getPK() + " was updated");
695                     remoteServer.updateActivity(o.getPK(), act);
696                 }
697             } catch (Exception JavaDoc e) {
698                 System.out.println("UPLOAD ERROR: Activity : pk="+act.getPK() + " OPP pk=" + o.getPK());
699                 System.out.println(e.getMessage());
700             }
701         }
702     }
703
704     /**
705      * upload contact changes for a given opportunity
706      * @param o the Opportunity we are processing
707      */

708     private final void uploadContactChanges(Opportunity o) {
709         ArrayList contacts = o.getContacts();
710         Contact con;
711         for (int i=0;i<contacts.size();i++) {
712             con = (Contact)contacts.get(i);
713
714             try {
715                 if (con.getAddedLocally()) {
716                     System.out.println("upload log: Contact " + con.getPK() + " was added");
717                     remoteServer.addContact(o.getPK(), con);
718                 }
719
720                 if (con.getUpdatedLocally()) {
721                     System.out.println("upload log: Contact " + con.getPK() + " was updated");
722                     remoteServer.updateContact(o.getPK(), con);
723                 }
724             } catch (Exception JavaDoc e) {
725                 System.out.println("UPLOAD ERROR: Contact : pk="+con.getPK() + " OPP pk=" + o.getPK());
726                 System.out.println(e.getMessage());
727             }
728         }
729     }
730
731     /**
732      * upload some quote changes for a given opportunity
733      * @param o the Opportunity we are processing
734      */

735     private final void uploadQuoteChanges(Opportunity o) {
736         ArrayList quotes = o.getQuotes();
737         Quote quote;
738
739         for (int i=0;i<quotes.size();i++) {
740             quote = (Quote)quotes.get(i);
741             try {
742                 if (quote.getAddedLocally()) {
743                     System.out.println("upload log: Quote " + quote.getPK() + " was added");
744                     remoteServer.addQuote(o.getPK(), quote);
745                 }
746
747                 if (quote.getUpdatedLocally()) {
748                     System.out.println("upload log: Quote " + quote.getPK() + " was updated");
749                     remoteServer.updateQuote(o.getPK(), quote);
750                 }
751             } catch (Exception JavaDoc e) {
752                 System.out.println("UPLOAD ERROR: Quote : pk="+quote.getPK() + " OPP pk=" + quote.getPK());
753                 System.out.println(e.getMessage());
754             }
755         }
756     }
757
758     /**
759      * upload forecast changes for a given Opportunity
760      * @param o the Opportunity we are processing
761      */

762     private final void uploadForecastChanges(Opportunity o) {
763         ArrayList forecasts = o.getForecasts();
764         Forecast f;
765         for (int i=0;i<forecasts.size();i++) {
766             f = (Forecast)forecasts.get(i);
767             try {
768                 if (f.getAddedLocally()) {
769                     System.out.println("upload log: Forecast " + f.getPK() + " was added");
770                     remoteServer.addForecast(o.getPK(), f);
771                 }
772
773                 if (f.getUpdatedLocally()) {
774                     System.out.println("upload log: Forecast " + f.getPK() + " was updated");
775                     remoteServer.updateForecast(o.getPK(), f);
776                 }
777             } catch (Exception JavaDoc e) {
778                 System.out.println("UPLOAD ERROR: Forecast : pk="+f.getPK() + " OPP pk=" + o.getPK());
779                 System.out.println(e.getMessage());
780             }
781         }
782     }
783
784     private final void resetStats() {
785
786         for (int i=0;i<stats.size();i++)
787             setStat(i, READY_STAT, 0, 0);
788
789         if (wb.getCurrentUser().getSyncDate() == null)
790             lastSyncField.setText("");
791         else
792             lastSyncField.setText(
793                 Prefs.dateTimeFormat.format(wb.getCurrentUser().getSyncDate()));
794         currStartField.setText("");
795         currEndField.setText("");
796     }
797
798     private final void setStat(int dataType, String JavaDoc syncStatus,
799         int localInserts, int localUpdates) {
800
801         Stat stat = (Stat)stats.get(dataType);
802         stat.syncStatus = syncStatus;
803         stat.localInserts = new Integer JavaDoc(localInserts);
804         stat.localUpdates = new Integer JavaDoc(localUpdates);
805
806         statTable.tableChanged(new TableModelEvent(statModel));
807     }
808
809     private final void initStatTable() {
810         stats = new ArrayList();
811         Stat stat;
812         stat = new Stat(wb.getLang().getString("roles"), READY_STAT, 0, 0);
813         stats.add(stat);
814         stat = new Stat(wb.getLang().getString("groups"), READY_STAT, 0, 0);
815         stats.add(stat);
816         stat = new Stat(wb.getLang().getString("groupMembers"), READY_STAT, 0, 0);
817         stats.add(stat);
818         stat = new Stat(wb.getLang().getString("salesPersons"), READY_STAT, 0, 0);
819         stats.add(stat);
820         stat = new Stat(wb.getLang().getString("products"), READY_STAT, 0, 0);
821         stats.add(stat);
822         stat = new Stat(wb.getLang().getString("campaigns"), READY_STAT, 0, 0);
823         stats.add(stat);
824         stat = new Stat(wb.getLang().getString("leads"), READY_STAT, 0, 0);
825         stats.add(stat);
826         stat = new Stat(wb.getLang().getString("customers"), READY_STAT, 0, 0);
827         stats.add(stat);
828         stat = new Stat(wb.getLang().getString("opps"), READY_STAT, 0, 0);
829         stats.add(stat);
830         stat = new Stat(wb.getLang().getString("tax"), READY_STAT, 0, 0);
831         stats.add(stat);
832
833         reloadStatTable();
834     }
835
836     private final void reloadStatTable() {
837         statModel = new StatTableModel(stats);
838         statTable.setModel(statModel);
839     }
840 }
841
Popular Tags