|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.struts;
import java.io.IOException;
import java.util.ResourceBundle;
import org.openide.cookies.*;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.text.DataEditorSupport;
import org.openide.windows.CloneableOpenSupport;
import org.openide.windows.CloneableTopComponent;
import org.openide.text.CloneableEditorSupport;
import org.openide.TopManager;
import org.openide.NotifyDescriptor;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
/** Support for editing a data object as text.
*
* @author mk115033
*/
// Replace OpenCookie with EditCookie or maybe ViewCookie as desired:
public class StrutsEditorSupport extends DataEditorSupport implements EditorCookie, EditCookie, CloseCookie, PrintCookie {
/** Create a new editor support.
* @param obj the data object whose primary file will be edited as text
*/
public StrutsEditorSupport(StrutsConfigDataObject obj) {
super(obj, new StrutsEnv(obj));
// Set a MIME type as needed, e.g.:
setMIMEType("text/xml"); // NOI18N
}
/** Called when the document is modified.
* Here, adding a save cookie to the object and marking it modified.
* @return true if the modification is acceptable
*/
protected boolean notifyModified() {
if (! super.notifyModified()) {
return false;
}
StrutsConfigDataObject obj = (StrutsConfigDataObject) getDataObject();
if (obj.getCookie(SaveCookie.class) == null) {
obj.setModified(true);
// You must implement this method on the object:
obj.addSaveCookie(new Save());
}
if (!obj.isPanelChanged()) obj.updatePanel();
return true;
}
/** Called when the document becomes unmodified.
* Here, removing the save cookie from the object and marking it unmodified.
*/
protected void notifyUnmodified() {
StrutsConfigDataObject obj = (StrutsConfigDataObject) getDataObject();
SaveCookie save = (SaveCookie) obj.getCookie(SaveCookie.class);
if (save != null) {
// You must implement this method on the object:
obj.removeSaveCookie(save);
obj.setModified(false);
}
super.notifyUnmodified();
}
/** A save cookie to use for the editor support.
* When saved, saves the document to disk and marks the object unmodified.
*/
private class Save implements SaveCookie {
public void save() throws IOException {
saveDocument();
getDataObject().setModified(false);
}
}
/** Should test whether all data is saved, and if not, prompt the user
* to save.
*
* @return
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.