KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > lexer > editorbridge > calc > CalcDataEditorSupport


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.lexer.editorbridge.calc;
21
22 import java.io.IOException JavaDoc;
23 import org.openide.cookies.EditorCookie;
24 import org.openide.cookies.EditCookie;
25 import org.openide.cookies.OpenCookie;
26 import org.openide.cookies.PrintCookie;
27 import org.openide.cookies.SaveCookie;
28 import org.openide.loaders.DataObject;
29 import org.openide.text.DataEditorSupport;
30
31 /**
32  * Calc editor support.
33  *
34  * @author Miloslav Metelka
35  * @version 1.00
36  */

37
38 class CalcDataEditorSupport extends DataEditorSupport
39 implements OpenCookie, EditCookie, EditorCookie, PrintCookie {
40     
41     private final Save save; // extra object to distinguish from other cookies
42

43     CalcDataEditorSupport(DataObject obj) {
44         super(obj, new DataEditorSupportEnv(obj));
45
46         save = new Save();
47         setMIMEType(CalcDataLoader.CALC_MIME_TYPE);
48     }
49
50     protected boolean notifyModified () {
51         if (!super.notifyModified ()) {
52             return false;
53         } else {
54             ((CalcDataObject)getDataObject()).enableSave(save);
55             return true;
56         }
57     }
58
59     protected void notifyUnmodified () {
60         super.notifyUnmodified ();
61         ((CalcDataObject)getDataObject()).disableSave(save);
62     }
63
64     private class Save implements SaveCookie {
65         
66         public void save() throws IOException JavaDoc {
67             saveDocument();
68             getDataObject().setModified(false);
69         }
70
71     }
72         
73 }
74
Popular Tags