KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > actions > MailTransferAction


1 package SnowMailClient.view.actions;
2
3 import SnowMailClient.MailEngine.transfer.*;
4 import SnowMailClient.model.folders.*;
5 import SnowMailClient.model.accounts.*;
6 import SnowMailClient.model.*;
7 import snow.utils.gui.*;
8
9 import SnowMailClient.utils.*;
10 import SnowMailClient.MailEngine.*;
11 import SnowMailClient.SnowMailClientApp;
12 import SnowMailClient.view.folders.*;
13 import SnowMailClient.Language.Language;
14
15 import java.awt.*;
16 import java.util.*;
17 import java.awt.event.*;
18 import javax.swing.*;
19 import javax.swing.event.*;
20 import javax.swing.tree.*;
21 import java.io.*;
22
23 /** send and/or receive mails
24 */

25 public class MailTransferAction extends AbstractAction
26 {
27   final MailTransferModel.TransferType type;
28
29   public MailTransferAction(MailTransferModel.TransferType type)
30   {
31      super();
32      this.type = type;
33
34      if(type == MailTransferModel.TransferType.Receive)
35      {
36        putValue(Action.NAME, Language.translate("Receive"));
37        putValue(AbstractAction.SMALL_ICON, SnowMailClientApp.loadImageIcon("pics/receivemail2.PNG") );
38        putValue(AbstractAction.SHORT_DESCRIPTION, Language.translate("Receive new mails from all accounts"));
39      }
40      else if(type == MailTransferModel.TransferType.Send)
41      {
42        putValue(Action.NAME, Language.translate("Send"));
43        putValue(AbstractAction.SMALL_ICON, SnowMailClientApp.loadImageIcon("pics/sendmail2.PNG") );
44        putValue(AbstractAction.SHORT_DESCRIPTION, Language.translate("Send selected mails and outbox content"));
45      }
46      else if(type == MailTransferModel.TransferType.SendAndReceive)
47      {
48        putValue(Action.NAME, Language.translate("Send / Receive"));
49        //putValue(AbstractAction.SMALL_ICON, SnowMailClientApp.loadImageIcon("pics/sendmail2.PNG") );
50
putValue(AbstractAction.SHORT_DESCRIPTION, Language.translate("Send mails in outbox and receive new mails"));
51      }
52   } // Constructor
53

54   // static => one for all actions
55
static MailTransferDialog downloadDialog = null;
56
57   public void actionPerformed(ActionEvent e)
58   {
59      // here we're in the EDT
60
if(downloadDialog!=null)
61      {
62         if(downloadDialog.downloadTerminated) downloadDialog = null;
63         else if(!downloadDialog.isVisible()) downloadDialog = null;
64         else return;
65      }
66
67      if(type == MailTransferModel.TransferType.Send || type == MailTransferModel.TransferType.SendAndReceive)
68      {
69        // 1) put the selected message in the outbox
70
// (but only if we are not already in the outbox)
71
//
72

73        try
74        {
75           MailFolder outboxFolder = SnowMailClientApp.getInstance().getFoldersModel().getOutboxFolder().getMailFolder();
76           if(SnowMailClientApp.getInstance().getFolderView().getMailFolder() != outboxFolder)
77           {
78              MailMessage[] messs = SnowMailClientApp.getInstance().getFolderView().getSelectedMessages();
79              for(MailMessage m: messs)
80              {
81                 try
82                 {
83                   outboxFolder.addMessage(m); // ok, we're in the EDT !!
84
SnowMailClientApp.getInstance().getFolderView().removeMail(m);
85                   m.selectedInView = false;
86                 }
87                 catch(Exception JavaDoc ee)
88                 {
89                   ee.printStackTrace();
90                 }
91              }
92           }
93        }
94        catch(Exception JavaDoc ee)
95        {
96          ee.printStackTrace();
97        }
98      }
99
100      downloadDialog = new MailTransferDialog(SnowMailClientApp.getInstance(), type);
101   }
102
103 } // ReceiveAllAction
Popular Tags