01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
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: * Save attachment command that asks the user where to save the attachment to.
31: * @author freddy
32: */
33: public class SaveAttachmentAsCommand extends SaveAttachmentCommand {
34:
35: /**
36: * Constructor for SaveAttachmentCommand.
37: *
38: * @param references command references
39: */
40: public SaveAttachmentAsCommand(ICommandReference reference) {
41: super (reference);
42: }
43:
44: /** {@inheritDoc} */
45: protected File getDestinationFile(MimeHeader header) {
46: cFileChooser fileChooser;
47:
48: if (lastDir == null) {
49: fileChooser = new cFileChooser();
50: } else {
51: fileChooser = new cFileChooser(lastDir);
52: }
53:
54: cFileFilter fileFilter = new cFileFilter();
55: fileFilter
56: .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
78: .getInstance().getActiveFrame(),
79: "Overwrite File?", "Warning",
80: JOptionPane.YES_NO_OPTION,
81: JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
82: break;
83: }
84: } else {
85: break;
86: }
87: }
88: return tempFile;
89: }
90: }
|