KickJava   Java API By Example, From Geeks To Geeks.

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


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.openide.cookies.EditCookie;
24 import org.openide.cookies.OpenCookie;
25 import org.openide.filesystems.FileObject;
26 import org.openide.loaders.DataObjectExistsException;
27 import org.openide.loaders.FileEntry;
28 import org.openide.loaders.MultiDataObject;
29 import org.openide.nodes.Node;
30 import org.openide.nodes.Node.Cookie;
31
32 /** The DataObject for forms.
33  *
34  * @author Ian Formanek, Petr Hamernik
35  */

36 public class FormDataObject extends MultiDataObject {
37     /** generated Serialized Version UID */
38     // static final long serialVersionUID = 7952143476761137063L;
39

40     //--------------------------------------------------------------------
41
// Private variables
42

43 // /** If true, a postInit method is called after reparsing - used after createFromTemplate */
44
// transient private boolean templateInit;
45
// /** If true, the form is marked as modified after regeneration - used if created from template */
46
// transient private boolean modifiedInit;
47
// /** A flag to prevent multiple registration of ComponentRefListener */
48
// transient private boolean componentRefRegistered;
49

50     transient private FormEditorSupport formEditor;
51
52     transient private OpenEdit openEdit;
53
54     /** The entry for the .form file */
55     FileEntry formEntry;
56
57     //--------------------------------------------------------------------
58
// Constructors
59

60     static final long serialVersionUID =-975322003627854168L;
61
62     public FormDataObject(FileObject ffo, FileObject jfo, FormDataLoader loader)
63         throws DataObjectExistsException
64     {
65         super(jfo, loader);
66         formEntry = (FileEntry)registerEntry(ffo);
67     }
68
69     //--------------------------------------------------------------------
70
// Other methods
71

72     @Override JavaDoc
73     public <T extends Cookie> T getCookie(Class JavaDoc<T> type) {
74         T retValue;
75         
76         if (OpenCookie.class.equals(type) || EditCookie.class.equals(type)) {
77             if (openEdit == null)
78                 openEdit = new OpenEdit();
79             retValue = type.cast(openEdit);
80         } else if (type.isAssignableFrom(FormEditorSupport.class)) {
81             retValue = (T) getFormEditorSupport();
82         } else {
83             retValue = super.getCookie(type);
84         }
85         return retValue;
86     }
87
88     private class OpenEdit implements OpenCookie, EditCookie {
89         public void open() {
90             // open form editor with form designer selected
91
getFormEditorSupport().openFormEditor(true);
92         }
93         public void edit() {
94             // open form editor with java editor selected (form not loaded)
95
getFormEditorSupport().open();
96         }
97     }
98
99     public FileObject getFormFile() {
100         return formEntry.getFile();
101     }
102
103     public boolean isReadOnly() {
104         FileObject javaFO = getPrimaryFile();
105         FileObject formFO = formEntry.getFile();
106         return !javaFO.canWrite() || !formFO.canWrite();
107     }
108
109     public boolean formFileReadOnly() {
110         return !formEntry.getFile().canWrite();
111     }
112
113     public synchronized FormEditorSupport getFormEditorSupport() {
114         if (formEditor == null) {
115             formEditor = new FormEditorSupport(getPrimaryEntry(), this, getCookieSet());
116         }
117         return formEditor;
118     }
119
120     // PENDING remove when form_new_layout is merged to trunk
121
public FormEditorSupport getFormEditor() {
122         return getFormEditorSupport();
123     }
124     // END of PENDING
125

126     FileEntry getFormEntry() {
127         return formEntry;
128     }
129
130     /** Provides node that should represent this data object. When a node for
131      * representation in a parent is requested by a call to getNode(parent) it
132      * is the exact copy of this node with only parent changed. This
133      * implementation creates instance <CODE>DataNode</CODE>. <P> This method
134      * is called only once.
135      *
136      * @return the node representation for this data object
137      * @see DataNode
138      */

139     protected Node createNodeDelegate() {
140         FormDataNode node = new FormDataNode(this);
141         return node;
142     }
143
144     //--------------------------------------------------------------------
145
// Serialization
146

147     private void readObject(java.io.ObjectInputStream JavaDoc is)
148         throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc {
149         is.defaultReadObject();
150     }
151
152 }
153
Popular Tags