KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > jmailaccount > JMailAccountPlugin


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.jmailaccount;
20
21 import java.awt.Dimension JavaDoc;
22
23 import org.lucane.client.*;
24 import org.lucane.client.widgets.DialogBox;
25 import org.lucane.common.ConnectInfo;
26 import org.lucane.common.net.ObjectConnection;
27
28
29 public class JMailAccountPlugin
30   extends StandalonePlugin
31 {
32     private ConnectInfo service;
33
34     public JMailAccountPlugin()
35     {
36     }
37     
38     public Plugin newInstance(ConnectInfo[] friends)
39     {
40         return new JMailAccountPlugin();
41     }
42
43     public void start()
44     {
45         this.service = Communicator.getInstance().getConnectInfo("org.lucane.applications.jmailaccount");
46         AccountFrame frame = new AccountFrame(this);
47         frame.setAccount(getAccount());
48         frame.setPreferredSize(new Dimension JavaDoc(250, 300));
49         frame.show();
50     }
51     
52     public boolean storeAccount(Account a)
53     {
54         boolean result = true;
55         
56         JMailAccountAction jma = new JMailAccountAction(JMailAccountAction.STORE_ACCOUNT, a);
57         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
58                 service, service.getName(), jma);
59
60         try {
61             if(oc.readString().startsWith("OK"))
62                 DialogBox.info(tr("msg.accountStored"));
63             else
64             {
65                 DialogBox.error(tr("err.storeAccount"));
66                 result = false;
67             }
68         } catch(Exception JavaDoc e) {
69             result = false;
70             DialogBox.error(tr("err.storeAccount"));
71             e.printStackTrace();
72         }
73         oc.close();
74         
75         return result;
76     }
77     
78     public Account getAccount()
79     {
80         Account a = null;
81         JMailAccountAction jma = new JMailAccountAction(JMailAccountAction.GET_ACCOUNT);
82         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
83                 service, service.getName(), jma);
84         
85         try {
86             if(oc.readString().startsWith("OK"))
87                 a = (Account)oc.read();
88         } catch(Exception JavaDoc e) {
89             //probably no account yet
90
}
91         
92         oc.close();
93         return a;
94     }
95 }
96
Popular Tags