1 19 20 21 package org.netbeans.modules.form; 22 23 import org.netbeans.api.java.loaders.JavaDataSupport; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileUtil; 26 import org.openide.loaders.DataObjectExistsException; 27 import org.openide.loaders.FileEntry; 28 import org.openide.loaders.MultiDataObject; 29 import org.openide.loaders.MultiFileLoader; 30 31 36 public class FormDataLoader extends MultiFileLoader { 37 38 public static final String FORM_EXTENSION = "form"; 40 public static final String JAVA_EXTENSION = "java"; 42 static final long serialVersionUID =7259146057404524013L; 43 44 public FormDataLoader() { 45 super("org.netbeans.modules.form.FormDataObject"); } 47 48 49 50 @Override 51 protected String defaultDisplayName() { 52 return org.openide.util.NbBundle.getBundle(FormDataLoader.class) 53 .getString("PROP_FormLoader_Name"); } 55 56 @Override 57 protected String actionsContext () { 58 return "Loaders/text/x-java/Actions/"; } 60 61 67 @Override 68 protected FileObject findPrimaryFile(FileObject fo) { 69 if (fo.isFolder()) return null; 71 String ext = fo.getExt(); 72 if (ext.equals(FORM_EXTENSION)) 73 return FileUtil.findBrother(fo, JAVA_EXTENSION); 74 75 FileObject javaFile = findJavaPrimaryFile(fo); 76 return javaFile != null 77 && FileUtil.findBrother(javaFile, FORM_EXTENSION) != null ? 78 javaFile : null; 79 } 80 81 89 @Override 90 protected MultiDataObject createMultiObject(FileObject primaryFile) 91 throws DataObjectExistsException, java.io.IOException 92 { 93 return new FormDataObject(FileUtil.findBrother(primaryFile, FORM_EXTENSION), 94 primaryFile, 95 this); 96 } 97 98 @Override 102 protected MultiDataObject.Entry createSecondaryEntry(MultiDataObject obj, 103 FileObject secondaryFile) 104 { 105 assert FORM_EXTENSION.equals(secondaryFile.getExt()); 106 107 FileEntry formEntry = new FileEntry(obj, secondaryFile); 108 ((FormDataObject)obj).formEntry = formEntry; 109 return formEntry; 110 } 111 112 @Override 113 protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) { 114 return JavaDataSupport.createJavaFileEntry(obj, primaryFile); 115 } 116 117 private FileObject findJavaPrimaryFile(FileObject fo) { 118 if (fo.getExt().equals(JAVA_EXTENSION)) 119 return fo; 120 return null; 121 } 122 } 123 | Popular Tags |