KickJava   Java API By Example, From Geeks To Geeks.

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


1 package SnowMailClient.view.actions;
2
3 import snow.utils.gui.Icons;
4 import SnowMailClient.MailEngine.*;
5 import SnowMailClient.*;
6 import SnowMailClient.model.*;
7 import SnowMailClient.model.accounts.*;
8 import SnowMailClient.view.*;
9 import SnowMailClient.view.dialogs.*;
10 import SnowMailClient.Language.Language;
11
12 import java.awt.*;
13 import java.awt.event.*;
14 import javax.swing.*;
15
16
17 /** this command is only avaiable for admin users
18 */

19 public final class AddNewUser extends AbstractAction
20 {
21    MailAccount admin;
22    JDialog ref;
23
24    public AddNewUser(JDialog ref, MailAccount admin)
25    {
26        super(Language.translate("Add new user"));
27        this.admin = admin;
28        this.ref= ref;
29
30        putValue(AbstractAction.SMALL_ICON, Icons.PlusIcon.shared10);
31        putValue(AbstractAction.ACCELERATOR_KEY,
32                  KeyStroke.getKeyStroke( KeyEvent.VK_U,
33                                          KeyEvent.CTRL_MASK ) );
34    }
35
36    public void actionPerformed(ActionEvent actionEvent)
37    {
38 /* MailAccount admin = accounts.getSnowraverAdministratorMailAccount();
39        if(admin==null)
40        {
41           JOptionPane.showMessageDialog(
42              ref, "ERROR: No account has administrator privileges");
43           return;
44        } */

45
46        AddNewUserDialog dialog = new AddNewUserDialog(ref, admin.getPop());
47        dialog.pack();
48        SnowMailClientApp.centerComponentOnMainFrame(dialog);
49        dialog.setVisible(true);
50
51        if(dialog.addNewUserOnExit)
52        {
53           try
54           {
55              SecurePopConnection sp = admin.getCheckedPopConnection();
56              sp.addNewUser( dialog.getUserName(), dialog.getPassword() );
57              sp.terminateSession();
58           }
59           catch(Exception JavaDoc ex)
60           {
61              // ### shit, the message is not nice
62
ex.printStackTrace();
63              JOptionPane.showMessageDialog(
64                ref, "Error: \n"+ex.getMessage(),
65                "Failed to add new user",
66                JOptionPane.ERROR_MESSAGE);
67           }
68        }
69
70    }
71
72 }
Popular Tags