Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


oracle.ide.model
Class TextBufferTracker

java.lang.Object
  extended by oracle.ide.model.NodeListener
      extended by oracle.ide.model.TextBufferTracker

All Implemented Interfaces:
java.util.EventListener, TextBufferListener

public class TextBufferTracker
extends NodeListener
implements TextBufferListener

A tracker of changes to the TextBuffer of a TextNode. A client which needs to track regions in a text buffer across edits can get a tracker for the text node, store the tracker version along with the offsets and lengths of the regions, and then at any time use the tracker to adjust offsets and lengths to reflect subsequent edits.

The text buffer uses text differencing to minimize the tracking impact of text buffer reloads which do not significantly change the text (e.g., minor external edits or VCS checkouts). The handling depends somewhat on undocumented text buffer implementation details. In particular, the tracker assumes that between RELOAD_STARTED and RELOAD_ENDED, the text buffer will issue a single remove event for the old text (unless the old text is empty), followed by a single insert event for the new text (unless the new text is empty).

Text buffers that are managed by TextNode may be garbage collected and later reloaded into a new text buffer which retains the listeners of the original text buffer. In this case, the tracker assumes that between the RELOAD_STARTED and RELOAD_ENDED, it will only see the insert event and not the remove event. To distinguish this case from a normal reload starting from an empty buffer, the tracker uses its history of the buffer length.

A text node that is closed without saving has to be tracked as a reversion, because if it is reopened every thing will be out of sync otherwise. The dirty flag is cleared by the time the nodeClosed event is fired, so the nodeWillClose event is used.


Field Summary
static int DEFAULT_COMPARISON_LIMIT
           

 

Fields inherited from interface oracle.javatools.buffer.TextBufferListener
EDIT_BEGIN_ATTRIBUTE, EDIT_END_ATTRIBUTE, EOL_TYPE_ATTRIBUTE, MODIFIED_ATTRIBUTE, READ_ONLY_ATTRIBUTE, RELOAD_END_ATTRIBUTE, RELOAD_START_ATTRIBUTE

 

Method Summary
 boolean adjustOffsetLength(int offset, int length, int version, int[] adjusted)
          Adjusts a region of the tracked buffer to reflect modifications since a version.
 void attributeUpdate(TextBuffer buffer, int attribute)
          Provides notification regarding a change to one of the buffer attributes.
static TextBufferTracker createTrackerFromSnapshot(TextNode node, ReadTextBuffer snapshot, int comparisonLimit)
          Creates a text buffer tracker for a text node with a specified snapshot as its initial version and the current node contents as the current version.
static TextBufferTracker getTracker(TextNode node)
          Gets the text buffer tracker for a text node.
 java.net.URL getURL()
          Gets the URL of the tracked buffer.
 int getVersion()
          Gets the current version of the tracked buffer.
 void insertUpdate(TextBuffer buffer, int offset, int count, char[] text)
          Provides notification about an insertion into the TextBuffer.
 boolean isModified(int version)
          Gets whether the tracked buffer has been modified since a version.
 boolean isModified(int offset, int length, int version)
          Gets whether a region of the tracked buffer has been modified since a version.
 void nodeClosed(NodeEvent event)
          Called after a Node has been closed.
 void nodeDeleted(NodeEvent e)
          Called after a Node has been deleted from disk and removed from the NodeFactory cache.
 void nodeDirtyStateChanged(NodeEvent e, boolean dirty)
          Called when the dirty state of a Node has just changed.
 void nodeOpened(NodeEvent event)
          Called after a Node has been opened.
 void nodeRenamed(NodeEvent e, java.net.URL oldURL, java.net.URL newURL)
          Called after a Node has been renamed and recached under the new URL in the NodeFactory.
 void nodeReverted(NodeEvent e)
          Called when a Node has been reverted (reloaded) to its last saved state.
 void nodeSaved(NodeEvent e)
          Called after a Node has been saved.
 void nodeWillBeSaved(NodeEvent e)
          Called before a Node is about to be saved.
 void nodeWillClose(NodeEvent e)
          Called when a Node is about to be closed.
 void nodeWillOpen(NodeEvent e)
          Called when a Node is about to be opened.
 void removeUpdate(TextBuffer buffer, int offset, int count, char[] text)
          Provides notification about a removal from the TextBuffer.
 void replaceText(TextBuffer buffer, char[] fromText, char[] toText, int comparisonLimit)
           
 java.lang.String toString()
           

 

Methods inherited from class oracle.ide.model.NodeListener
invokeLaterIfNeeded

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Field Detail

DEFAULT_COMPARISON_LIMIT

public static final int DEFAULT_COMPARISON_LIMIT
See Also:
Constant Field Values

Method Detail

getTracker

public static TextBufferTracker getTracker(TextNode node)
Gets the text buffer tracker for a text node. One tracker is created per node.
Parameters:
node - The TextNode to track.

createTrackerFromSnapshot

public static TextBufferTracker createTrackerFromSnapshot(TextNode node,
                                                          ReadTextBuffer snapshot,
                                                          int comparisonLimit)
                                                   throws java.io.IOException
Creates a text buffer tracker for a text node with a specified snapshot as its initial version and the current node contents as the current version.

A particular use case for this is where a source node is a template which is expanded for use at runtime and offsets are reported from the expanded version and need to be mapped back to the source.

Parameters:
node - The TextNode to track.
Throws:
java.io.IOException

getURL

public java.net.URL getURL()
Gets the URL of the tracked buffer.
Returns:

getVersion

public int getVersion()
Gets the current version of the tracked buffer. Note that this is not the change id of the buffer.

adjustOffsetLength

public boolean adjustOffsetLength(int offset,
                                  int length,
                                  int version,
                                  int[] adjusted)
Adjusts a region of the tracked buffer to reflect modifications since a version.
Parameters:
offset - The offset of the region when the version was current.
length - The length of the region when the version was current.
version - The version from which to adjust.
adjusted - A two element int array for the adjusted offset and length.
Returns:
true if the region contains changes since the version.

isModified

public boolean isModified(int version)
Gets whether the tracked buffer has been modified since a version.
Parameters:
version - The version from which to compare.

isModified

public boolean isModified(int offset,
                          int length,
                          int version)
Gets whether a region of the tracked buffer has been modified since a version.
Parameters:
offset - The offset of the region when the version was current.
length - The length of the region when the version was current.
version - The version from which to compare.
Returns:
true if the region as been modified since the version.
See Also:
adjustOffsetLength(int, int, int, int[])

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

nodeWillOpen

public void nodeWillOpen(NodeEvent e)
Description copied from class: NodeListener
Called when a Node is about to be opened.
Overrides:
nodeWillOpen in class NodeListener
Parameters:
e - the object containing information about this event

nodeOpened

public void nodeOpened(NodeEvent event)
Description copied from class: NodeListener
Called after a Node has been opened.
Overrides:
nodeOpened in class NodeListener
Parameters:
event - the object containing information about this event

nodeDirtyStateChanged

public void nodeDirtyStateChanged(NodeEvent e,
                                  boolean dirty)
Description copied from class: NodeListener
Called when the dirty state of a Node has just changed.
Overrides:
nodeDirtyStateChanged in class NodeListener
Parameters:
e - the object containing information about this event
dirty - true if the Node's dirty flag has just been set; false if the Node's dirty flag has just been cleared.

nodeWillClose

public void nodeWillClose(NodeEvent e)
Description copied from class: NodeListener
Called when a Node is about to be closed.
Overrides:
nodeWillClose in class NodeListener
Parameters:
e - the object containing information about this event

nodeClosed

public void nodeClosed(NodeEvent event)
Description copied from class: NodeListener
Called after a Node has been closed.
Overrides:
nodeClosed in class NodeListener
Parameters:
event - the object containing information about this event

nodeWillBeSaved

public void nodeWillBeSaved(NodeEvent e)
Description copied from class: NodeListener
Called before a Node is about to be saved.
Overrides:
nodeWillBeSaved in class NodeListener
Parameters:
e - the object containing information about this event

nodeSaved

public void nodeSaved(NodeEvent e)
Description copied from class: NodeListener
Called after a Node has been saved.
Overrides:
nodeSaved in class NodeListener
Parameters:
e - the object containing information about this event

nodeReverted

public void nodeReverted(NodeEvent e)
Description copied from class: NodeListener
Called when a Node has been reverted (reloaded) to its last saved state.
Overrides:
nodeReverted in class NodeListener
Parameters:
e - the object containing information about this event

nodeDeleted

public void nodeDeleted(NodeEvent e)
Description copied from class: NodeListener
Called after a Node has been deleted from disk and removed from the NodeFactory cache.
Overrides:
nodeDeleted in class NodeListener
Parameters:
e - the object containing information about this event

nodeRenamed

public void nodeRenamed(NodeEvent e,
                        java.net.URL oldURL,
                        java.net.URL newURL)
Description copied from class: NodeListener
Called after a Node has been renamed and recached under the new URL in the NodeFactory.
Overrides:
nodeRenamed in class NodeListener
Parameters:
e - the object containing information about this event. Calling e.getNode() will return the old Node. To get the new Node, call NodeFactory.find(newURL). Both old and new Nodes remain available while NodeListeners are being called with the nodeRenamed event. In the case where renaming did not cause the Node type to change, both old Node and new Node will be the exact same object, so using the oldURL parameter is the only reliable way to know the URL of the Node before it was renamed. If the Node type did change, the old Node is removed from the NodeFactory cache immediately after all NodeListeners have been called with the nodeRenamed event.
oldURL - the old URL of the Node before the rename
newURL - the new URL of the Node after the rename

attributeUpdate

public void attributeUpdate(TextBuffer buffer,
                            int attribute)
Description copied from interface: TextBufferListener
Provides notification regarding a change to one of the buffer attributes. The possible attributes are defined in this interface.
Specified by:
attributeUpdate in interface TextBufferListener
Parameters:
buffer - the TextBuffer that changed.
attribute - the attribute that changed

insertUpdate

public void insertUpdate(TextBuffer buffer,
                         int offset,
                         int count,
                         char[] text)
Description copied from interface: TextBufferListener
Provides notification about an insertion into the TextBuffer.
Specified by:
insertUpdate in interface TextBufferListener
Parameters:
buffer - the TextBuffer that changed.
offset - the offset where the insert took place
count - the number of characters inserted (insertedData.length)
text - an array of the removed characters.

removeUpdate

public void removeUpdate(TextBuffer buffer,
                         int offset,
                         int count,
                         char[] text)
Description copied from interface: TextBufferListener
Provides notification about a removal from the TextBuffer.
Specified by:
removeUpdate in interface TextBufferListener
Parameters:
buffer - the TextBuffer that changed.
offset - the offset of the first removed character.
count - the number of characters removed (removedData.length)
text - an array of the removed characters

replaceText

public void replaceText(TextBuffer buffer,
                        char[] fromText,
                        char[] toText,
                        int comparisonLimit)

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


Copyright © 1997, 2012, Oracle. All rights reserved.