1 11 package org.eclipse.jface.preference; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.StringTokenizer ; 16 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.DirectoryDialog; 19 20 23 public class PathEditor extends ListEditor { 24 25 28 private String lastPath; 29 30 34 private String dirChooserLabelText; 35 36 39 protected PathEditor() { 40 } 41 42 50 public PathEditor(String name, String labelText, 51 String dirChooserLabelText, Composite parent) { 52 init(name, labelText); 53 this.dirChooserLabelText = dirChooserLabelText; 54 createControl(parent); 55 } 56 57 62 protected String createList(String [] items) { 63 StringBuffer path = new StringBuffer (""); 65 for (int i = 0; i < items.length; i++) { 66 path.append(items[i]); 67 path.append(File.pathSeparator); 68 } 69 return path.toString(); 70 } 71 72 76 protected String getNewInputObject() { 77 78 DirectoryDialog dialog = new DirectoryDialog(getShell()); 79 if (dirChooserLabelText != null) { 80 dialog.setMessage(dirChooserLabelText); 81 } 82 if (lastPath != null) { 83 if (new File (lastPath).exists()) { 84 dialog.setFilterPath(lastPath); 85 } 86 } 87 String dir = dialog.open(); 88 if (dir != null) { 89 dir = dir.trim(); 90 if (dir.length() == 0) { 91 return null; 92 } 93 lastPath = dir; 94 } 95 return dir; 96 } 97 98 101 protected String [] parseString(String stringList) { 102 StringTokenizer st = new StringTokenizer (stringList, File.pathSeparator 103 + "\n\r"); ArrayList v = new ArrayList (); 105 while (st.hasMoreElements()) { 106 v.add(st.nextElement()); 107 } 108 return (String []) v.toArray(new String [v.size()]); 109 } 110 } 111 | Popular Tags |