001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.testtools;
021:
022: /*
023: * XTestDataObject.java
024: *
025: * Created on May 2, 2002, 4:10 PM
026: */
027:
028: import java.io.IOException;
029:
030: import org.openide.cookies.CloseCookie;
031: import org.openide.cookies.EditCookie;
032: import org.openide.cookies.EditorCookie;
033: import org.openide.cookies.OpenCookie;
034: import org.openide.cookies.PrintCookie;
035: import org.openide.cookies.SaveCookie;
036: import org.openide.filesystems.FileObject;
037: import org.openide.filesystems.FileLock;
038: import org.openide.nodes.Node.Cookie;
039: import org.openide.text.DataEditorSupport;
040: import org.openide.windows.CloneableOpenSupport;
041:
042: /** Editor Support class for XTest Workspace Build Script
043: * @author <a href="mailto:adam.sotona@sun.com">Adam Sotona</a> */
044: public final class XTestEditorSupport extends DataEditorSupport
045: implements OpenCookie, EditCookie, EditorCookie.Observable,
046: PrintCookie, CloseCookie {
047:
048: /** SaveCookie for this support instance. The cookie is adding/removing
049: * data object's cookie set depending on if modification flag was set/unset. */
050: private final SaveCookie saveCookie = new SaveCookie() {
051: /** Implements <code>SaveCookie</code> interface. */
052: public void save() throws IOException {
053: XTestEditorSupport.this .saveDocument();
054: XTestEditorSupport.this .getDataObject().setModified(false);
055: }
056: };
057:
058: /** Constructor. */
059: XTestEditorSupport(XTestDataObject obj) {
060: super (obj, new Environment(obj));
061:
062: setMIMEType("text/xml"); // NOI18N
063: }
064:
065: /** Overrides superclass method. Adds adding of save cookie if the document has been marked modified.
066: * @return true if the environment accepted being marked as modified
067: * or false if it has refused and the document should remain unmodified */
068: protected boolean notifyModified() {
069: if (!super .notifyModified())
070: return false;
071:
072: ((XTestDataObject) getDataObject()).addSaveCookie(saveCookie);
073:
074: return true;
075: }
076:
077: /** Overrides superclass method. Adds removing of save cookie. */
078: protected void notifyUnmodified() {
079: super .notifyUnmodified();
080:
081: ((XTestDataObject) getDataObject())
082: .removeSaveCookie(saveCookie);
083: }
084:
085: /** Nested class. Environment for this support. Extends <code>DataEditorSupport.Env</code> abstract class. */
086: private static class Environment extends DataEditorSupport.Env {
087:
088: /** Constructor.
089: * @param obj XTestDataObject */
090: public Environment(XTestDataObject obj) {
091: super (obj);
092: }
093:
094: /** Implements abstract superclass method.
095: * @return FileObject */
096: protected FileObject getFile() {
097: return getDataObject().getPrimaryFile();
098: }
099:
100: /** Implements abstract superclass method.
101: * @throws IOException IOException
102: * @return FileLock */
103: protected FileLock takeLock() throws IOException {
104: return ((XTestDataObject) getDataObject())
105: .getPrimaryEntry().takeLock();
106: }
107:
108: /** Overrides superclass method.
109: * @return CloneableOpenSupport instance of enclosing class */
110: public CloneableOpenSupport findCloneableOpenSupport() {
111: return (XTestEditorSupport) ((XTestDataObject) getDataObject())
112: .getCookie(XTestEditorSupport.class);
113: }
114: } // End of nested Environment class.
115:
116: }
|