01: /*
02: * ChooseFolderDialog.java
03: *
04: * Copyright (C) 2000-2002 Peter Graves
05: * $Id: ChooseFolderDialog.java,v 1.1.1.1 2002/09/24 16:10:04 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j.mail;
23:
24: import org.armedbear.j.Debug;
25: import org.armedbear.j.Editor;
26: import org.armedbear.j.File;
27: import org.armedbear.j.History;
28: import org.armedbear.j.InputDialog;
29: import org.armedbear.j.MessageDialog;
30:
31: public final class ChooseFolderDialog extends InputDialog {
32: private ChooseFolderDialog(Editor editor, String prompt,
33: String title) {
34: super (editor, prompt, title, null);
35: History history = new History("chooseFolder");
36: setHistory(history);
37: setDefaultValue(history.getPrevious());
38: }
39:
40: public static String chooseFolder(Editor editor, String title) {
41: return chooseFolder(editor, "Folder:", title);
42: }
43:
44: // Returns null if user cancels.
45: // Returns null if user input (or dereferenced alias) is empty string.
46: public static String chooseFolder(Editor editor, String prompt,
47: String title) {
48: String errorText = null;
49: while (true) {
50: if (errorText != null)
51: MessageDialog.showMessageDialog(editor, errorText,
52: title);
53: ChooseFolderDialog dialog = new ChooseFolderDialog(editor,
54: prompt, title);
55: editor.centerDialog(dialog);
56: dialog.show();
57: editor.repaintNow();
58: final String input = dialog.getInput();
59: if (input == null || input.length() == 0)
60: return null;
61: final String value = editor.getAlias(input);
62: final String destination = value != null ? value : input;
63: Debug.assertTrue(destination != null);
64: if (destination.length() == 0) // Shouldn't happen.
65: return null;
66: if (destination.startsWith("mailbox:")) {
67: // Local folder. Do a little validation.
68: File file = File.getInstance(destination.substring(8));
69: if (file == null) {
70: errorText = "Invalid path";
71: continue;
72: }
73: if (file.isDirectory()) {
74: return "mailbox:".concat(File.getInstance(file,
75: "mbox").canonicalPath());
76: }
77: if (file.isFile()) {
78: // Assume it's really a mailbox...
79: return "mailbox:".concat(file.canonicalPath());
80: }
81: errorText = "Folder does not exist";
82: continue;
83: }
84: // Not local.
85: return destination;
86: }
87: }
88: }
|