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.openide.loaders;
46
import java.io.IOException;
48
import org.openide.cookies.CloseCookie;
49
import org.openide.cookies.EditCookie;
50
import org.openide.cookies.EditorCookie;
51
import org.openide.cookies.OpenCookie;
52
import org.openide.cookies.PrintCookie;
53
import org.openide.cookies.SaveCookie;
54
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileLock;
56
import org.openide.loaders.DataObject;
57
import org.openide.loaders.MultiDataObject;
58
import org.openide.nodes.CookieSet;
59
import org.openide.nodes.Node.Cookie;
60
import org.openide.text.DataEditorSupport;
61
import org.openide.windows.CloneableOpenSupport;
65
* Basic editor support.
67
* @author Jaroslav Tulach
69
final class DefaultES extends DataEditorSupport
70
implements OpenCookie, EditCookie, EditorCookie.Observable, PrintCookie, CloseCookie, SaveAsCapable {
71
/** SaveCookie for this support instance. The cookie is adding/removing
72
* data object's cookie set depending on if modification flag was set/unset. */
73
private final SaveCookie saveCookie = new SaveCookie() {
74
/** Implements <code>SaveCookie</code> interface. */
75
public void save() throws IOException {
76
DefaultES.this.saveDocument();
80
private CookieSet set;
83
* @param obj data object to work on
84
* @param set set to add/remove save cookie from
86
DefaultES (DataObject obj, MultiDataObject.Entry entry, CookieSet set) {
87
super(obj, new Environment(obj, entry));
89
setMIMEType("text/plain"); // NOI18N
93
* Overrides superclass method. Adds adding of save cookie if the document has been marked modified.
94
* @return true if the environment accepted being marked as modified
95
* or false if it has refused and the document should remain unmodified
97
protected boolean notifyModified () {
98
if (!super.notifyModified())
106
/** Overrides superclass method. Adds removing of save cookie. */
107
protected void notifyUnmodified () {
108
super.notifyUnmodified();
113
/** Helper method. Adds save cookie to the data object. */
114
private void addSaveCookie() {
115
DataObject obj = getDataObject();
117
// Adds save cookie to the data object.
118
if(obj.getCookie(SaveCookie.class) == null) {
120
obj.setModified(true);
124
/** Helper method. Removes save cookie from the data object. */
125
private void removeSaveCookie() {
126
DataObject obj = getDataObject();
128
// Remove save cookie from the data object.
129
Cookie cookie = obj.getCookie(SaveCookie.class);
131
if(cookie != null && cookie.equals(saveCookie)) {
132
set.remove(saveCookie);
133
obj.setModified(false);
138
/** Nested class. Environment for this support. Extends
139
* <code>DataEditorSupport.Env</code> abstract class.
142
private static class Environment extends DataEditorSupport.Env {
143
private static final long serialVersionUID = 5451434321155443431L;
145
private MultiDataObject.Entry entry;
148
public Environment(DataObject obj, MultiDataObject.Entry entry) {
154
/** Implements abstract superclass method. */
155
protected FileObject getFile() {
156
return entry.getFile();
159
/** Implements abstract superclass method.*/
160
protected FileLock takeLock() throws IOException {
161
return entry.takeLock();
165
* Overrides superclass method.
166
* @return text editor support (instance of enclosing class)
168
public CloneableOpenSupport findCloneableOpenSupport() {
169
DataObject obj = getDataObject ();
171
if (obj instanceof DefaultDataObject) {
172
ret = (DefaultES)((DefaultDataObject)obj).getCookie (DefaultES.class, true);
174
ret = (DefaultES)getDataObject().getCookie(DefaultES.class);
177
// this is necessary as for large files, this methods sets flag that
178
// prevents UserQuestionException
179
super.findCloneableOpenSupport ();
183
} // End of nested Environment class.