Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

oracle.javatools.editor.folding
Class DefaultCodeFoldingModel

java.lang.Object
  extended by oracle.javatools.editor.folding.DefaultCodeFoldingModel
All Implemented Interfaces:
CodeFoldingModel

public class DefaultCodeFoldingModel
extends java.lang.Object
implements CodeFoldingModel

A simple data model that describes the collapsible source code blocks in the code editor. The collapsible code blocks are arranged in a tree hierarchy. Code blocks are expected to be discrete; a parent should fully contain each of its children, and siblings should not overlap.

Since:
10.1.3

Field Summary
protected  BasicDocument document
           
protected  javax.swing.event.EventListenerList listenerList
           
protected  ReadWriteLock lock
           
protected static int MAX_TOOLTIP_LENGTH
           
protected static java.lang.Object[] NO_BLOCKS
           
protected  DefaultFoldingBlock root
           
 
Constructor Summary
DefaultCodeFoldingModel(BasicDocument document)
           
 
Method Summary
 void addCodeFoldingModelListener(CodeFoldingModelListener listener)
          Adds a listener for changes to the data model.
protected  void fireStructureChanged(FoldingBlock block)
           
 java.lang.String getAbbreviatedText(java.lang.Object block)
          Returns the abbreviated text to be used in place of the specified folding block when the block is collapsed.
 java.util.Iterator getChildren(java.lang.Object parent)
          Returns an Iterator over the children of the specified folding block.
 CodeFoldingModelListener[] getCodeFoldingModelListeners()
           
 java.lang.Object[] getCollapsedBlocks()
          Returns the set of all collapsed blocks in the model; any collapsed block that also has a collapsed ancestor must be excluded from the return array.
protected  void getCollapsedDescendants(FoldingBlock block, java.util.Collection collapsed)
           
 BasicDocument getDocument()
           
protected  FoldingBlock getEnclosingDescendant(FoldingBlock block, int offset)
           
 java.lang.Object getFirstBlockAtLine(int line)
          Returns the first collapsible source code block at the specified line.
protected  FoldingBlock getFirstDescendantAtLine(FoldingBlock block, int line)
           
protected  int getLineCount()
           
protected  int getLineEndOffset(int line)
           
protected  int getLineFromOffset(int offset)
           
protected  int getLineStartOffset(int line)
           
 java.lang.Object getParent(java.lang.Object child)
          Returns the parent block for the specified folding block.
 java.lang.Object getRoot()
          Returns the root block in the data model.
 java.lang.Object getSmallestEnclosingBlock(int offset)
          Returns the smallest collapsible source code block that contains the specified character offset.
 int[] getTextOffsets(java.lang.Object block, int[] offsets)
          Stores the start and end character offsets of the specified block into the specified two-element integer array, and returns that array; if the specified array is null, a new array is allocated.
 java.lang.String getToolTipText(java.lang.Object block)
          Returns the tooltip text to display when the mouse is hovering over the specified source code block and the block is collapsed.
 void insertUpdate(int offset, int length)
           
protected  void insertUpdateChildren(DefaultFoldingBlock block, int offset, int length)
           
 boolean isExpanded(java.lang.Object block)
          Returns whether the specified folding block is expanded.
 void readLock()
          Acquires a read lock on the model.
 void readUnlock()
          Releases the previously acquired read lock on the model.
 void reload()
           
 void removeCodeFoldingModelListener(CodeFoldingModelListener listener)
          Removes a listener from the data model.
 void removeUpdate(int offset, int length)
           
protected  void removeUpdateChildren(DefaultFoldingBlock block, int offset, int length)
           
 void setExpanded(java.lang.Object block, boolean isExpanded)
          Sets whether the specified folding block should be expanded.
 void setRoot(java.lang.Object root)
           
protected  void writeLock()
           
protected  void writeUnlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_TOOLTIP_LENGTH

protected static final int MAX_TOOLTIP_LENGTH
See Also:
Constant Field Values

NO_BLOCKS

protected static final java.lang.Object[] NO_BLOCKS

root

protected DefaultFoldingBlock root

document

protected BasicDocument document

listenerList

protected javax.swing.event.EventListenerList listenerList

lock

protected ReadWriteLock lock
Constructor Detail

DefaultCodeFoldingModel

public DefaultCodeFoldingModel(BasicDocument document)
Method Detail

getDocument

public BasicDocument getDocument()

reload

public void reload()

setRoot

public void setRoot(java.lang.Object root)

getCodeFoldingModelListeners

public CodeFoldingModelListener[] getCodeFoldingModelListeners()

insertUpdate

public void insertUpdate(int offset,
                         int length)

removeUpdate

public void removeUpdate(int offset,
                         int length)

insertUpdateChildren

protected void insertUpdateChildren(DefaultFoldingBlock block,
                                    int offset,
                                    int length)

removeUpdateChildren

protected void removeUpdateChildren(DefaultFoldingBlock block,
                                    int offset,
                                    int length)

readLock

public void readLock()
Description copied from interface: CodeFoldingModel
Acquires a read lock on the model. If the lock is not available, then the current thread blocks until the lock is acquired. A lock must be acquired before querying the model.

Specified by:
readLock in interface CodeFoldingModel

readUnlock

public void readUnlock()
Description copied from interface: CodeFoldingModel
Releases the previously acquired read lock on the model. The lock should always be released after the client has completed querying the model.

Specified by:
readUnlock in interface CodeFoldingModel

getRoot

public java.lang.Object getRoot()
Description copied from interface: CodeFoldingModel
Returns the root block in the data model. This is typically an uncollapsible dummy node representing the contents of the entire source document.

The client must acquire a lock on the model before calling this method.

Specified by:
getRoot in interface CodeFoldingModel
Returns:
the root block, or null if there is no root block in the model

getSmallestEnclosingBlock

public java.lang.Object getSmallestEnclosingBlock(int offset)
Description copied from interface: CodeFoldingModel
Returns the smallest collapsible source code block that contains the specified character offset.

The client must acquire a lock on the model before calling this method.

Specified by:
getSmallestEnclosingBlock in interface CodeFoldingModel
Parameters:
offset - the target character offset
Returns:
the smallest block containing the specified offset, or null if the model is empty or the offset is invalid

getFirstBlockAtLine

public java.lang.Object getFirstBlockAtLine(int line)
Description copied from interface: CodeFoldingModel
Returns the first collapsible source code block at the specified line.

The client must acquire a lock on the model before calling this method.

Specified by:
getFirstBlockAtLine in interface CodeFoldingModel
Parameters:
line - the target line
Returns:
the first block at the specified line, or null if the model is empty or the offset is invalid

getCollapsedBlocks

public java.lang.Object[] getCollapsedBlocks()
Description copied from interface: CodeFoldingModel
Returns the set of all collapsed blocks in the model; any collapsed block that also has a collapsed ancestor must be excluded from the return array. If there are no collapsed blocks, an empty array should be returned.

The client must acquire a lock on the model before calling this method.

Specified by:
getCollapsedBlocks in interface CodeFoldingModel
Returns:
the array of collapsed blocks; the return value must not be null

getToolTipText

public java.lang.String getToolTipText(java.lang.Object block)
Description copied from interface: CodeFoldingModel
Returns the tooltip text to display when the mouse is hovering over the specified source code block and the block is collapsed. The text should correspond to text from the source document.

The client must acquire a lock on the model before calling this method.

Specified by:
getToolTipText in interface CodeFoldingModel
Parameters:
block - the target source code block
Returns:
the tooltip text to display

getChildren

public java.util.Iterator getChildren(java.lang.Object parent)
Description copied from interface: CodeFoldingModel
Returns an Iterator over the children of the specified folding block. The return value may not be null; if the block contains no children, an empty Iterator should be returned.

The client must acquire a lock on the model before calling this method.

Specified by:
getChildren in interface CodeFoldingModel
Parameters:
parent - the parent folding block from this data source
Returns:
an iterator over the children of the block; the return value must not be null.

getParent

public java.lang.Object getParent(java.lang.Object child)
Description copied from interface: CodeFoldingModel
Returns the parent block for the specified folding block.

The client must acquire a lock on the model before calling this method.

Specified by:
getParent in interface CodeFoldingModel
Parameters:
child - the child folding block from this data source
Returns:
the parent block, or null if the specified block is the root

getTextOffsets

public int[] getTextOffsets(java.lang.Object block,
                            int[] offsets)
Description copied from interface: CodeFoldingModel
Stores the start and end character offsets of the specified block into the specified two-element integer array, and returns that array; if the specified array is null, a new array is allocated.

The client must acquire a lock on the model before calling this method.

Specified by:
getTextOffsets in interface CodeFoldingModel
Parameters:
block - a folding block from this data source
offsets - a two-element integer array; if null, a new array is allocated
Returns:
a two-element integer array, where the first integer is the start offset of the block and the second integer is is the end offset.

getAbbreviatedText

public java.lang.String getAbbreviatedText(java.lang.Object block)
Description copied from interface: CodeFoldingModel
Returns the abbreviated text to be used in place of the specified folding block when the block is collapsed. The length of the replacement text should be less than the length of uncollapsed text.

The client must acquire a lock on the model before calling this method.

Specified by:
getAbbreviatedText in interface CodeFoldingModel
Parameters:
block - a folding block from this data source
Returns:
the abbreviated text used in place of the collapsed folding block

isExpanded

public boolean isExpanded(java.lang.Object block)
Description copied from interface: CodeFoldingModel
Returns whether the specified folding block is expanded.

This method may be called without acquiring a lock on the model.

Specified by:
isExpanded in interface CodeFoldingModel
Parameters:
block - a folding block from this data source
Returns:
true if the folding block is expanded

setExpanded

public void setExpanded(java.lang.Object block,
                        boolean isExpanded)
Description copied from interface: CodeFoldingModel
Sets whether the specified folding block should be expanded.

This method may be called without acquiring a lock on the model.

Specified by:
setExpanded in interface CodeFoldingModel
Parameters:
block - a folding block from this data source
isExpanded - true if the folding block should be expanded

addCodeFoldingModelListener

public void addCodeFoldingModelListener(CodeFoldingModelListener listener)
Description copied from interface: CodeFoldingModel
Adds a listener for changes to the data model.

This method may be called without acquiring a lock on the model.

Specified by:
addCodeFoldingModelListener in interface CodeFoldingModel
Parameters:
listener - the listener to add

removeCodeFoldingModelListener

public void removeCodeFoldingModelListener(CodeFoldingModelListener listener)
Description copied from interface: CodeFoldingModel
Removes a listener from the data model.

This method may be called without acquiring a lock on the model.

Specified by:
removeCodeFoldingModelListener in interface CodeFoldingModel
Parameters:
listener - the listener to remove

writeLock

protected void writeLock()

writeUnlock

protected void writeUnlock()

getLineFromOffset

protected int getLineFromOffset(int offset)

getLineCount

protected int getLineCount()

getLineStartOffset

protected int getLineStartOffset(int line)

getLineEndOffset

protected int getLineEndOffset(int line)

getFirstDescendantAtLine

protected FoldingBlock getFirstDescendantAtLine(FoldingBlock block,
                                                int line)

getEnclosingDescendant

protected FoldingBlock getEnclosingDescendant(FoldingBlock block,
                                              int offset)

getCollapsedDescendants

protected void getCollapsedDescendants(FoldingBlock block,
                                       java.util.Collection collapsed)

fireStructureChanged

protected void fireStructureChanged(FoldingBlock block)

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

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