1 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 { 33 private ChooseFolderDialog(Editor editor, String prompt, String title) 34 { 35 super(editor, prompt, title, null); 36 History history = new History("chooseFolder"); 37 setHistory(history); 38 setDefaultValue(history.getPrevious()); 39 } 40 41 public static String chooseFolder(Editor editor, String title) 42 { 43 return chooseFolder(editor, "Folder:", title); 44 } 45 46 public static String chooseFolder(Editor editor, String prompt, 49 String title) 50 { 51 String errorText = null; 52 while (true) { 53 if (errorText != null) 54 MessageDialog.showMessageDialog(editor, errorText, title); 55 ChooseFolderDialog dialog = 56 new ChooseFolderDialog(editor, prompt, title); 57 editor.centerDialog(dialog); 58 dialog.show(); 59 editor.repaintNow(); 60 final String input = dialog.getInput(); 61 if (input == null || input.length() == 0) 62 return null; 63 final String value = editor.getAlias(input); 64 final String destination = value != null ? value : input; 65 Debug.assertTrue(destination != null); 66 if (destination.length() == 0) return null; 68 if (destination.startsWith("mailbox:")) { 69 File file = File.getInstance(destination.substring(8)); 71 if (file == null) { 72 errorText = "Invalid path"; 73 continue; 74 } 75 if (file.isDirectory()) { 76 return "mailbox:".concat(File.getInstance(file, "mbox").canonicalPath()); 77 } 78 if (file.isFile()) { 79 return "mailbox:".concat(file.canonicalPath()); 81 } 82 errorText = "Folder does not exist"; 83 continue; 84 } 85 return destination; 87 } 88 } 89 } 90 | Popular Tags |