1 package org.columba.mail.gui.message.command; 17 18 import java.io.File ; 19 20 import javax.swing.JFileChooser ; 21 import javax.swing.JOptionPane ; 22 23 import org.columba.api.command.ICommandReference; 24 import org.columba.core.base.cFileChooser; 25 import org.columba.core.base.cFileFilter; 26 import org.columba.core.gui.frame.FrameManager; 27 import org.columba.ristretto.message.MimeHeader; 28 29 30 34 public class SaveAttachmentAsCommand extends SaveAttachmentCommand { 35 36 41 public SaveAttachmentAsCommand(ICommandReference reference) { 42 super(reference); 43 } 44 45 46 protected File getDestinationFile(MimeHeader header) { 47 cFileChooser fileChooser; 48 49 if (lastDir == null) { 50 fileChooser = new cFileChooser(); 51 } else { 52 fileChooser = new cFileChooser(lastDir); 53 } 54 55 cFileFilter fileFilter = new cFileFilter(); 56 fileFilter.acceptFilesWithProperty(cFileFilter.FILEPROPERTY_FILE); 57 58 fileChooser.setDialogTitle("Save Attachment as ..."); 59 60 String fileName = getFilename(header); 61 if (fileName != null) { 62 fileChooser.forceSelectedFile(new File (fileName)); 63 } 64 65 fileChooser.setSelectFilter(fileFilter); 66 File tempFile = null; 67 68 while (true) { 69 if (fileChooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) { 70 return null; 71 } 72 73 tempFile = fileChooser.getSelectedFile(); 74 lastDir = tempFile.getParentFile(); 75 76 if (tempFile.exists()) { 77 if (JOptionPane.showConfirmDialog(FrameManager.getInstance() 78 .getActiveFrame(), "Overwrite File?", 79 "Warning", JOptionPane.YES_NO_OPTION, 80 JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { 81 break; 82 } 83 } else { 84 break; 85 } 86 } 87 return tempFile; 88 } 89 } 90 | Popular Tags |