KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > message > command > SaveAttachmentAsCommand


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.message.command;
17
18 import java.io.File JavaDoc;
19
20 import javax.swing.JFileChooser JavaDoc;
21 import javax.swing.JOptionPane JavaDoc;
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 /**
31  * Save attachment command that asks the user where to save the attachment to.
32  * @author freddy
33  */

34 public class SaveAttachmentAsCommand extends SaveAttachmentCommand {
35
36     /**
37      * Constructor for SaveAttachmentCommand.
38      *
39      * @param references command references
40      */

41     public SaveAttachmentAsCommand(ICommandReference reference) {
42         super(reference);
43     }
44
45     /** {@inheritDoc} */
46     protected File JavaDoc 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 JavaDoc fileName = getFilename(header);
61         if (fileName != null) {
62             fileChooser.forceSelectedFile(new File JavaDoc(fileName));
63         }
64
65         fileChooser.setSelectFilter(fileFilter);
66         File JavaDoc 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