1 19 package org.netbeans.modules.java.j2seplatform.platformdefinition; 20 21 import org.openide.filesystems.FileObject; 22 import org.openide.filesystems.FileUtil; 23 24 import java.beans.PropertyEditorSupport ; 25 import java.io.File ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.StringTokenizer ; 30 31 public class FileObjectPropertyEditor extends PropertyEditorSupport { 32 33 public String getAsText() { 34 try { 35 List fileobjs = (List ) this.getValue(); 36 StringBuffer result = new StringBuffer (); 37 boolean first = true; 38 for (Iterator it = fileobjs.iterator(); it.hasNext();) { 39 FileObject fo = (FileObject) it.next (); 40 File f = FileUtil.toFile(fo); 41 if (f != null) { 42 if (!first) { 43 result.append (File.pathSeparator); 44 } 45 else { 46 first = false; 47 } 48 result.append(f.getAbsolutePath()); 49 } 50 } 51 return result.toString (); 52 } catch (Exception e) { 53 e.printStackTrace(); 54 return ""; 55 } 56 } 57 58 public void setAsText(String text) throws IllegalArgumentException { 59 try { 60 List fileObjs = new ArrayList (); 61 if (text != null) { 62 StringTokenizer tk = new StringTokenizer (text, File.pathSeparator); 63 while (tk.hasMoreTokens()) { 64 String path = tk.nextToken(); 65 File f = new File (path); 66 fileObjs.add(FileUtil.toFileObject(f)); 67 } 68 } 69 setValue (fileObjs); 70 } catch (Exception e) { 71 e.printStackTrace(); 72 } 73 } 74 75 } 76 | Popular Tags |