001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018:
019: package org.columba.addressbook.folder.importfilter;
020:
021: import java.io.File;
022:
023: import javax.swing.JOptionPane;
024:
025: import org.columba.addressbook.folder.AbstractFolder;
026: import org.columba.addressbook.model.IContactModel;
027: import org.columba.addressbook.util.AddressbookResourceLoader;
028: import org.columba.api.plugin.IExtensionInterface;
029: import org.columba.core.gui.frame.FrameManager;
030:
031: /**
032: * Abstract base class for addressbook data importers.
033: */
034: public abstract class DefaultAddressbookImporter implements
035: IExtensionInterface {
036: public static int TYPE_FILE = 0;
037:
038: public static int TYPE_DIRECTORY = 1;
039:
040: protected AbstractFolder destinationFolder;
041:
042: protected File sourceFile;
043:
044: // protected AddressbookFolder tempFolder;
045: protected int counter;
046:
047: public DefaultAddressbookImporter() {
048: }
049:
050: public DefaultAddressbookImporter(File sourceFile,
051: AbstractFolder destinationFolder) {
052: this .sourceFile = sourceFile;
053: this .destinationFolder = destinationFolder;
054: }
055:
056: public void init() {
057: counter = 0;
058:
059: // tempFolder = new AddressbookFolder(null,addressbookInterface);
060: }
061:
062: /** ********* override the following messages ************************* */
063: /**
064: * override this method to specify type the wizard dialog will open the
065: * correct file/directory dialog automatically
066: */
067: public int getType() {
068: return TYPE_FILE;
069: }
070:
071: /**
072: * enter a description which will be shown to the user here
073: */
074: public String getDescription() {
075: return "";
076: }
077:
078: /**
079: * this method does all the import work
080: */
081: public abstract void importAddressbook(File file) throws Exception;
082:
083: public void setSourceFile(File file) {
084: this .sourceFile = file;
085: }
086:
087: /**
088: * set destination folder
089: */
090: public void setDestinationFolder(AbstractFolder folder) {
091: destinationFolder = folder;
092: }
093:
094: /**
095: * counter for successfully imported messages
096: */
097: public int getCount() {
098: return counter;
099: }
100:
101: /**
102: * this method calls your overridden importMailbox(File)-method and handles
103: * exceptions
104: */
105: public void run() {
106: try {
107: importAddressbook(sourceFile);
108: } catch (Exception ex) {
109: JOptionPane.showMessageDialog(FrameManager.getInstance()
110: .getActiveFrame(), AddressbookResourceLoader
111: .getString("dialog", "addressbookimport",
112: "addressbook_import_failed"), "",
113: JOptionPane.ERROR_MESSAGE);
114: return;
115: }
116:
117: if (getCount() == 0) {
118: JOptionPane.showMessageDialog(FrameManager.getInstance()
119: .getActiveFrame(), AddressbookResourceLoader
120: .getString("dialog", "addressbookimport",
121: "addressbook_import_failed_2"), "",
122: JOptionPane.ERROR_MESSAGE);
123: } else {
124: JOptionPane.showMessageDialog(FrameManager.getInstance()
125: .getActiveFrame(), AddressbookResourceLoader
126: .getString("dialog", "addressbookimport",
127: "addressbook_import_was_successfull"),
128: AddressbookResourceLoader.getString("dialog",
129: "contact", "information"),
130: JOptionPane.INFORMATION_MESSAGE);
131: }
132: }
133:
134: /**
135: * use this method to save a message to the specified destination folder
136: */
137: protected void saveContact(IContactModel card) throws Exception {
138: destinationFolder.add(card);
139:
140: counter++;
141: }
142:
143: /**
144: * use this method to save contacts to the specified destination folder
145: */
146: protected void saveContacts(IContactModel[] cards) throws Exception {
147: destinationFolder.add(cards);
148:
149: counter += cards.length;
150: }
151: }
|