KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormDataLoader


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /** Loader for Forms. Recognizes file with extension .form and .java and with extension class if
32  * there is their source and form file.
33  *
34  * @author Ian Formanek
35  */

36 public class FormDataLoader extends MultiFileLoader {
37     /** The standard extensions of the recognized files */
38     public static final String JavaDoc FORM_EXTENSION = "form"; // NOI18N
39
/** The standard extension for Java source files. */
40     public static final String JavaDoc JAVA_EXTENSION = "java"; // NOI18N
41

42     static final long serialVersionUID =7259146057404524013L;
43     /** Constructs a new FormDataLoader */
44     public FormDataLoader() {
45         super("org.netbeans.modules.form.FormDataObject"); // NOI18N
46
}
47
48     
49     /** Gets default display name. Overides superclass method. */
50     @Override JavaDoc
51     protected String JavaDoc defaultDisplayName() {
52         return org.openide.util.NbBundle.getBundle(FormDataLoader.class)
53                  .getString("PROP_FormLoader_Name"); // NOI18N
54
}
55
56     @Override JavaDoc
57     protected String JavaDoc actionsContext () {
58         return "Loaders/text/x-java/Actions/"; // NOI18N
59
}
60
61     /** For a given file finds a primary file.
62      * @param fo the file to find primary file for
63      *
64      * @return the primary file for the file or null if the file is not
65      * recognized by this loader
66      */

67     @Override JavaDoc
68     protected FileObject findPrimaryFile(FileObject fo) {
69     // never recognize folders.
70
if (fo.isFolder()) return null;
71         String JavaDoc 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     /** Creates the right data object for given primary file.
82      * It is guaranteed that the provided file is realy primary file
83      * returned from the method findPrimaryFile.
84      *
85      * @param primaryFile the primary file
86      * @return the data object for this file
87      * @exception DataObjectExistsException if the primary file already has data object
88      */

89     @Override JavaDoc
90     protected MultiDataObject createMultiObject(FileObject primaryFile)
91         throws DataObjectExistsException, java.io.IOException JavaDoc
92     {
93         return new FormDataObject(FileUtil.findBrother(primaryFile, FORM_EXTENSION),
94                                   primaryFile,
95                                   this);
96     }
97
98     // from JavaDataLoader
99
// [?] Probably needed in case FormDataObject is deserialized, then the
100
// secondary entry is created additionally.
101
@Override JavaDoc
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 JavaDoc
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