1 package org.columba.addressbook.gui.action; 19 20 import java.awt.event.ActionEvent ; 21 import java.io.BufferedOutputStream ; 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 import java.io.FileOutputStream ; 25 import java.io.IOException ; 26 27 import javax.swing.JFileChooser ; 28 29 import org.columba.addressbook.folder.AddressbookFolder; 30 import org.columba.addressbook.gui.frame.AddressbookFrameMediator; 31 import org.columba.addressbook.model.IContactModel; 32 import org.columba.addressbook.parser.VCardParser; 33 import org.columba.api.gui.frame.IFrameMediator; 34 35 39 40 public class ExportVCardAction extends DefaultTableAction { 41 42 46 public ExportVCardAction(IFrameMediator frameMediator) { 47 super(frameMediator, "Export to VCard.."); 48 } 49 50 53 public void actionPerformed(ActionEvent arg0) { 54 AddressbookFrameMediator mediator = (AddressbookFrameMediator) frameMediator; 55 56 AddressbookFolder sourceFolder = (AddressbookFolder) mediator.getTree() 58 .getSelectedFolder(); 59 60 String [] uids = mediator.getTable().getUids(); 62 63 JFileChooser fc = new JFileChooser (); 65 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 66 fc.setApproveButtonText("Select"); 67 68 int returnVal = fc.showOpenDialog(frameMediator.getView().getFrame()); 69 70 if (returnVal == JFileChooser.APPROVE_OPTION) { 72 File file = fc.getSelectedFile(); 73 74 for (int i = 0; i < uids.length; i++) { 75 try { 76 IContactModel contact = sourceFolder.get(uids[i]); 77 File f = new File (file, "contact"+uids[i].toString() + ".vcf"); 78 79 BufferedOutputStream s = new BufferedOutputStream ( 80 new FileOutputStream (f)); 81 82 VCardParser.write(contact, s); 83 84 } catch (FileNotFoundException e) { 85 86 e.printStackTrace(); 87 } catch (IOException e) { 88 89 e.printStackTrace(); 90 } catch (Exception e) { 91 92 e.printStackTrace(); 93 } 94 } 95 } 96 } 97 98 } | Popular Tags |