1 19 package org.columba.addressbook.folder.importfilter; 20 21 import java.io.File ; 22 23 import javax.swing.JOptionPane ; 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 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 sourceFile; 42 43 protected int counter; 45 46 public DefaultAddressbookImporter() { 47 } 48 49 public DefaultAddressbookImporter(File sourceFile, 50 AbstractFolder destinationFolder) { 51 this.sourceFile = sourceFile; 52 this.destinationFolder = destinationFolder; 53 } 54 55 public void init() { 56 counter = 0; 57 58 } 60 61 62 66 public int getType() { 67 return TYPE_FILE; 68 } 69 70 73 public String getDescription() { 74 return ""; 75 } 76 77 80 public abstract void importAddressbook(File file) throws Exception ; 81 82 public void setSourceFile(File file) { 83 this.sourceFile = file; 84 } 85 86 89 public void setDestinationFolder(AbstractFolder folder) { 90 destinationFolder = folder; 91 } 92 93 96 public int getCount() { 97 return counter; 98 } 99 100 104 public void run() { 105 try { 106 importAddressbook(sourceFile); 107 } catch (Exception 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 135 protected void saveContact(IContactModel card) throws Exception { 136 destinationFolder.add(card); 137 138 counter++; 139 } 140 141 144 protected void saveContacts(IContactModel[] cards) throws Exception { 145 destinationFolder.add(cards); 146 147 counter += cards.length; 148 } 149 } 150 | Popular Tags |