KickJava   Java API By Example, From Geeks To Geeks.

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


1 package SnowMailClient.view.actions;
2
3 import snow.utils.gui.Icons;
4 import SnowMailClient.SnowMailClientApp;
5 import SnowMailClient.model.folders.*;
6 import SnowMailClient.model.*;
7 import SnowMailClient.view.folders.*;
8 import SnowMailClient.view.*;
9 import SnowMailClient.Language.Language;
10
11 import java.awt.*;
12 import java.awt.event.*;
13 import javax.swing.*;
14 import javax.swing.event.*;
15 import javax.swing.table.*;
16
17 /** delete the selected mail (move in the deleted folder)
18 */

19 public class DeleteMailAction extends AbstractAction
20 {
21   FolderView folderView;
22   FolderTreeNode deletedNode;
23
24   public DeleteMailAction(FolderView _folderView, FolderTreeNode deletedNode)
25   {
26      super(Language.translate("Delete selected mail"));
27      this.folderView = _folderView;
28      this.deletedNode = deletedNode;
29
30      putValue(AbstractAction.ACCELERATOR_KEY,
31               KeyStroke.getKeyStroke( KeyEvent.VK_D, KeyEvent.CTRL_MASK ) );
32
33      putValue(AbstractAction.SMALL_ICON, Icons.CrossIcon.shared10);
34
35      folderView.getTableSelectionModel().addListSelectionListener( new ListSelectionListener()
36      {
37         public void valueChanged(ListSelectionEvent e)
38         {
39            setEnabled(folderView.getTableSelectionCount()>0);
40         }
41      });
42      setEnabled(folderView.getTableSelectionCount()>0);
43
44   } // Constructor
45

46   public void actionPerformed(ActionEvent e)
47   {
48     MailMessage[] messs = folderView.getSelectedMessages();
49     for(MailMessage mess : messs)
50     {
51        try
52        {
53          if( folderView.getMailFolder().equals(deletedNode.getMailFolder()))
54          {
55            // definitively destroy...
56
}
57          else
58          {
59            // put in deleted
60
mess.setIsNoMoreNew();
61            mess.selectedInView = false; // desselect
62
deletedNode.getMailFolder().addMessage(mess);
63          }
64
65          folderView.removeMail(mess);
66        }
67        catch(Exception JavaDoc ex)
68        {
69          ex.printStackTrace();
70        }
71     }
72   }
73
74
75
76 } // DeleteMailAction
Popular Tags