2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
43
package org.netbeans.modules.form;
45
import java.io.IOException;
46
import org.openide.cookies.EditCookie;
47
import org.openide.cookies.OpenCookie;
48
import org.openide.filesystems.FileObject;
49
import org.openide.loaders.DataFolder;
50
import org.openide.loaders.DataObject;
51
import org.openide.loaders.DataObjectExistsException;
52
import org.openide.loaders.FileEntry;
53
import org.openide.loaders.MultiDataObject;
54
import org.openide.loaders.SaveAsCapable;
55
import org.openide.nodes.Node;
56
import org.openide.nodes.Node.Cookie;
58
/** The DataObject for forms.
60
* @author Ian Formanek, Petr Hamernik
62
public class FormDataObject extends MultiDataObject {
63
/** generated Serialized Version UID */
64
// static final long serialVersionUID = 7952143476761137063L;
66
//--------------------------------------------------------------------
69
// /** If true, a postInit method is called after reparsing - used after createFromTemplate */
70
// transient private boolean templateInit;
71
// /** If true, the form is marked as modified after regeneration - used if created from template */
72
// transient private boolean modifiedInit;
73
// /** A flag to prevent multiple registration of ComponentRefListener */
74
// transient private boolean componentRefRegistered;
76
transient private FormEditorSupport formEditor;
78
transient private OpenEdit openEdit;
80
/** The entry for the .form file */
83
//--------------------------------------------------------------------
86
static final long serialVersionUID =-975322003627854168L;
88
public FormDataObject(FileObject ffo, FileObject jfo, FormDataLoader loader)
89
throws DataObjectExistsException
92
formEntry = (FileEntry)registerEntry(ffo);
93
getCookieSet().assign( SaveAsCapable.class, new SaveAsCapable() {
94
public void saveAs(FileObject folder, String fileName) throws IOException {
95
getFormEditorSupport().saveAs( folder, fileName );
100
//--------------------------------------------------------------------
104
public <T extends Cookie> T getCookie(Class<T> type) {
107
if (OpenCookie.class.equals(type) || EditCookie.class.equals(type)) {
108
if (openEdit == null)
109
openEdit = new OpenEdit();
110
retValue = type.cast(openEdit);
111
} else if (type.isAssignableFrom(FormEditorSupport.class)) {
112
retValue = (T) getFormEditorSupport();
114
retValue = super.getCookie(type);
119
private class OpenEdit implements OpenCookie, EditCookie {
121
// open form editor with form designer selected
122
getFormEditorSupport().openFormEditor(true);
125
// open form editor with java editor selected (form not loaded)
126
getFormEditorSupport().open();
130
public FileObject getFormFile() {
131
return formEntry.getFile();
134
public boolean isReadOnly() {
135
FileObject javaFO = getPrimaryFile();
136
FileObject formFO = formEntry.getFile();
137
return !javaFO.canWrite() || !formFO.canWrite();
140
public boolean formFileReadOnly() {
141
return !formEntry.getFile().canWrite();
144
public synchronized FormEditorSupport getFormEditorSupport() {
145
if (formEditor == null) {
146
formEditor = new FormEditorSupport(getPrimaryEntry(), this, getCookieSet());
151
// PENDING remove when form_new_layout is merged to trunk
152
public FormEditorSupport getFormEditor() {
153
return getFormEditorSupport();
157
FileEntry getFormEntry() {
161
/** Provides node that should represent this data object. When a node for
162
* representation in a parent is requested by a call to getNode(parent) it
163
* is the exact copy of this node with only parent changed. This
164
* implementation creates instance <CODE>DataNode</CODE>. <P> This method
165
* is called only once.
167
* @return the node representation for this data object
170
protected Node createNodeDelegate() {
171
FormDataNode node = new FormDataNode(this);
175
//--------------------------------------------------------------------
178
private void readObject(java.io.ObjectInputStream is)
179
throws java.io.IOException, ClassNotFoundException {
180
is.defaultReadObject();
184
protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException {
185
FileObject fo = getPrimaryEntry().copyRename (df.getPrimaryFile (), name, ext);
186
return DataObject.find( fo );