KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > folder > importfilter > DefaultAddressbookImporter


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18

19 package org.columba.addressbook.folder.importfilter;
20
21 import java.io.File JavaDoc;
22
23 import javax.swing.JOptionPane JavaDoc;
24
25 import org.columba.addressbook.folder.AbstractFolder;
26 import org.columba.addressbook.model.IContactModel;
27 import org.columba.addressbook.util.AddressbookResourceLoader;
28 import org.columba.api.plugin.IExtensionInterface;
29 import org.columba.core.gui.frame.FrameManager;
30
31 /**
32  * Abstract base class for addressbook data importers.
33  */

34 public abstract class DefaultAddressbookImporter implements IExtensionInterface {
35     public static int TYPE_FILE = 0;
36
37     public static int TYPE_DIRECTORY = 1;
38
39     protected AbstractFolder destinationFolder;
40
41     protected File JavaDoc sourceFile;
42
43     // protected AddressbookFolder tempFolder;
44
protected int counter;
45
46     public DefaultAddressbookImporter() {
47     }
48
49     public DefaultAddressbookImporter(File JavaDoc sourceFile,
50             AbstractFolder destinationFolder) {
51         this.sourceFile = sourceFile;
52         this.destinationFolder = destinationFolder;
53     }
54
55     public void init() {
56         counter = 0;
57
58         // tempFolder = new AddressbookFolder(null,addressbookInterface);
59
}
60
61     /** ********* override the following messages ************************* */
62     /**
63      * override this method to specify type the wizard dialog will open the
64      * correct file/directory dialog automatically
65      */

66     public int getType() {
67         return TYPE_FILE;
68     }
69
70     /**
71      * enter a description which will be shown to the user here
72      */

73     public String JavaDoc getDescription() {
74         return "";
75     }
76
77     /**
78      * this method does all the import work
79      */

80     public abstract void importAddressbook(File JavaDoc file) throws Exception JavaDoc;
81
82     public void setSourceFile(File JavaDoc file) {
83         this.sourceFile = file;
84     }
85
86     /**
87      * set destination folder
88      */

89     public void setDestinationFolder(AbstractFolder folder) {
90         destinationFolder = folder;
91     }
92
93     /**
94      * counter for successfully imported messages
95      */

96     public int getCount() {
97         return counter;
98     }
99
100     /**
101      * this method calls your overridden importMailbox(File)-method and handles
102      * exceptions
103      */

104     public void run() {
105         try {
106             importAddressbook(sourceFile);
107         } catch (Exception JavaDoc ex) {
108             JOptionPane.showMessageDialog(FrameManager.getInstance()
109                     .getActiveFrame(),
110                     AddressbookResourceLoader.getString("dialog",
111                             "addressbookimport", "addressbook_import_failed"),
112                     "", JOptionPane.ERROR_MESSAGE);
113             return;
114         }
115
116         if (getCount() == 0) {
117             JOptionPane.showMessageDialog(FrameManager.getInstance()
118                     .getActiveFrame(), AddressbookResourceLoader.getString(
119                     "dialog", "addressbookimport",
120                     "addressbook_import_failed_2"), "",
121                     JOptionPane.ERROR_MESSAGE);
122         } else {
123             JOptionPane.showMessageDialog(FrameManager.getInstance()
124                     .getActiveFrame(), AddressbookResourceLoader.getString(
125                     "dialog", "addressbookimport",
126                     "addressbook_import_was_successfull"),
127                     AddressbookResourceLoader.getString("dialog", "contact",
128                             "information"), JOptionPane.INFORMATION_MESSAGE);
129         }
130     }
131
132     /**
133      * use this method to save a message to the specified destination folder
134      */

135     protected void saveContact(IContactModel card) throws Exception JavaDoc {
136         destinationFolder.add(card);
137
138         counter++;
139     }
140
141     /**
142      * use this method to save contacts to the specified destination folder
143      */

144     protected void saveContacts(IContactModel[] cards) throws Exception JavaDoc {
145         destinationFolder.add(cards);
146
147         counter += cards.length;
148     }
149 }
150
Popular Tags