org.openide.loaders 7.10.1

org.openide.text
Class DataEditorSupport

java.lang.Object
  extended by org.openide.windows.CloneableOpenSupport
      extended by org.openide.text.CloneableEditorSupport
          extended by org.openide.text.DataEditorSupport

public class DataEditorSupport
extends CloneableEditorSupport

Support for associating an editor and a Swing Document to a data object.


Nested Class Summary
static class DataEditorSupport.Env
          Environment that connects the data object and the CloneableEditorSupport.
 
Nested classes/interfaces inherited from class org.openide.text.CloneableEditorSupport
CloneableEditorSupport.Pane
 
Field Summary
 
Fields inherited from class org.openide.text.CloneableEditorSupport
EDITOR_MODE
 
Fields inherited from class org.openide.windows.CloneableOpenSupport
allEditors, env
 
Constructor Summary
DataEditorSupport(DataObject obj, CloneableEditorSupport.Env env)
          Editor support for a given data object.
 
Method Summary
static String annotateName(String label, boolean html, boolean modified, boolean readOnly)
          Marks up a tab name according to modified and read-only status.
protected  boolean canClose()
          Checks whether is possible to close support components.
static CloneableEditorSupport create(DataObject obj, MultiDataObject.Entry entry, CookieSet set)
          Factory method to create simple CloneableEditorSupport for a given entry of a given DataObject.
protected  StyledDocument createStyledDocument(EditorKit kit)
          Let's the super method create the document and also annotates it with Title and StreamDescription properties.
protected  String documentID()
           
static DataObject findDataObject(Line l)
          Support method that extracts a DataObject from a Line.
 DataObject getDataObject()
          Getter of the data object that this support is associated with.
protected  void initializeCloneableEditor(CloneableEditor editor)
          Annotates the editor with icon from the data object and also sets appropriate selected node.
protected  void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit)
           
protected  String messageHtmlName()
           
protected  String messageLine(Line line)
          Computes display name for a line based on the name of the associated DataObject and the line number.
protected  String messageName()
          Constructs message that should be used to name the editor component.
protected  String messageOpened()
          Message to display when an object has been opened.
protected  String messageOpening()
          Message to display when an object is being opened.
protected  String messageSave()
          Constructs message that should be displayed when the data object is modified and is being closed.
protected  String messageToolTip()
          Text to use as tooltip for component.
protected  void notifyClosed()
          Called when closed all components.
 StyledDocument openDocument()
           
 void saveAs(FileObject folder, String fileName)
          Save the document under a new file name and/or extension.
 void saveDocument()
          Saves document.
protected  void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream)
           
static String toolTip(FileObject file, boolean modified, boolean readOnly)
          Constructs a tool tip possibly marked up with document modified and read-only status.
 
Methods inherited from class org.openide.text.CloneableEditorSupport
addChangeListener, addPropertyChangeListener, asynchronousOpen, close, createCloneableEditor, createCloneableTopComponent, createEditorKit, createPane, createPositionRef, createUndoRedoManager, firePropertyChange, getDocument, getEditorKit, getInputStream, getLineSet, getOpenedPanes, getUndoRedo, isDocumentLoaded, isModified, notifyModified, notifyUnmodified, open, openAt, prepareDocument, print, reloadDocument, removeChangeListener, removePropertyChangeListener, setMIMEType, updateTitles, wrapEditorComponent
 
Methods inherited from class org.openide.windows.CloneableOpenSupport
close, edit, openCloneableTopComponent, view
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataEditorSupport

public DataEditorSupport(DataObject obj,
                         CloneableEditorSupport.Env env)
Editor support for a given data object. The file is taken from the data object and is updated if the object moves or renames itself.

Parameters:
obj - object to work with
env - environment to pass to
Method Detail

create

public static CloneableEditorSupport create(DataObject obj,
                                            MultiDataObject.Entry entry,
                                            CookieSet set)
Factory method to create simple CloneableEditorSupport for a given entry of a given DataObject. The common use inside DataObject looks like this:
  getCookieSet().add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), getCookieSet()));
 

Parameters:
obj - the data object
entry - the entry to read and write from
set - cookie set to add remove additional cookies (currently only SaveCookie)
Returns:
a subclass of DataEditorSupport that implements at least OpenCookie, EditCookie, EditorCookie.Observable, PrintCookie, CloseCookie
Since:
5.2

getDataObject

public final DataObject getDataObject()
Getter of the data object that this support is associated with.

Returns:
data object passed in constructor

messageOpening

protected String messageOpening()
Message to display when an object is being opened.

Specified by:
messageOpening in class CloneableOpenSupport
Returns:
the message or null if nothing should be displayed

messageOpened

protected String messageOpened()
Message to display when an object has been opened.

Specified by:
messageOpened in class CloneableOpenSupport
Returns:
the message or null if nothing should be displayed

messageSave

protected String messageSave()
Constructs message that should be displayed when the data object is modified and is being closed.

Specified by:
messageSave in class CloneableEditorSupport
Returns:
text to show to the user

annotateName

public static String annotateName(String label,
                                  boolean html,
                                  boolean modified,
                                  boolean readOnly)
Marks up a tab name according to modified and read-only status. Done for subclasses automatically in messageName() and messageHtmlName() but useful for other editor-like windows.

Behavior currently varies according to the system property nb.tabnames.html.

Parameters:
label - incoming label (null not permitted, so take care with Node.getHtmlDisplayName())
html - if true, label may include HTML markup (with or without initial <html>), and result may as well
modified - mark up the label as for a document which is modified in memory
readOnly - mark up the label as for a document based on a read-only file
Returns:
a possibly marked-up label
Since:
org.openide.loaders 7.7

messageName

protected String messageName()
Constructs message that should be used to name the editor component.

Specified by:
messageName in class CloneableEditorSupport
Returns:
name of the editor

messageHtmlName

protected String messageHtmlName()
Overrides:
messageHtmlName in class CloneableEditorSupport

documentID

protected String documentID()
Overrides:
documentID in class CloneableEditorSupport

toolTip

public static String toolTip(FileObject file,
                             boolean modified,
                             boolean readOnly)
Constructs a tool tip possibly marked up with document modified and read-only status. Done for subclasses automatically in messageToolTip() but useful for other editor-like windows.

Behavior currently varies according to the system property nb.tabnames.html.

Parameters:
file - a file representing the tab
modified - mark up the tool tip as for a document which is modified in memory
readOnly - mark up the tool tip as for a document based on a read-only file
Returns:
a tool tip
Since:
org.openide.loaders 7.7

messageToolTip

protected String messageToolTip()
Text to use as tooltip for component.

Specified by:
messageToolTip in class CloneableEditorSupport
Returns:
text to show to the user

messageLine

protected String messageLine(Line line)
Computes display name for a line based on the name of the associated DataObject and the line number.

Overrides:
messageLine in class CloneableEditorSupport
Parameters:
line - the line object to compute display name for
Returns:
display name for the line like "MyFile.java:243"
Since:
4.3

initializeCloneableEditor

protected void initializeCloneableEditor(CloneableEditor editor)
Annotates the editor with icon from the data object and also sets appropriate selected node. But only in the case the data object is valid. This implementation also listen to display name and icon changes of the node and keeps editor top component up-to-date. If you override this method and not call super, please note that you will have to keep things synchronized yourself.

Overrides:
initializeCloneableEditor in class CloneableEditorSupport
Parameters:
editor - the editor that has been created and should be annotated

notifyClosed

protected void notifyClosed()
Called when closed all components. Overrides superclass method, also unregisters listening on node delegate.

Overrides:
notifyClosed in class CloneableEditorSupport

createStyledDocument

protected StyledDocument createStyledDocument(EditorKit kit)
Let's the super method create the document and also annotates it with Title and StreamDescription properties.

Overrides:
createStyledDocument in class CloneableEditorSupport
Parameters:
kit - kit to user to create the document
Returns:
the document annotated by the properties

canClose

protected boolean canClose()
Checks whether is possible to close support components. Overrides superclass method, adds checking for read-only property of saving file and warns user in that case.

Overrides:
canClose in class CloneableEditorSupport

loadFromStreamToKit

protected void loadFromStreamToKit(StyledDocument doc,
                                   InputStream stream,
                                   EditorKit kit)
                            throws IOException,
                                   BadLocationException
Overrides:
loadFromStreamToKit in class CloneableEditorSupport
Throws:
IOException
BadLocationException

saveFromKitToStream

protected void saveFromKitToStream(StyledDocument doc,
                                   EditorKit kit,
                                   OutputStream stream)
                            throws IOException,
                                   BadLocationException
Overrides:
saveFromKitToStream in class CloneableEditorSupport
Throws:
IOException
BadLocationException

openDocument

public StyledDocument openDocument()
                            throws IOException
Overrides:
openDocument in class CloneableEditorSupport
Throws:
IOException

saveDocument

public void saveDocument()
                  throws IOException
Saves document. Overrides superclass method, adds checking for read-only property of saving file and warns user in that case.

Overrides:
saveDocument in class CloneableEditorSupport
Throws:
IOException

findDataObject

public static DataObject findDataObject(Line l)
Support method that extracts a DataObject from a Line. If the line is created by a DataEditorSupport then associated DataObject can be accessed by this method.

Parameters:
l - line object
Returns:
data object or null
Since:
4.3

saveAs

public void saveAs(FileObject folder,
                   String fileName)
            throws IOException
Save the document under a new file name and/or extension.

Parameters:
folder - New folder to save the DataObject to.
fileName - New file name to save the DataObject to.
Throws:
IOException - If the operation failed
Since:
6.3

org.openide.loaders 7.10.1

Built on April 11 2010.  |  Portions Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.