public final class FoldOperation extends Object
There are three main services - creation of a new fold
and adding or removing it from the hierarchy.
Adding and removing of the folds requires a valid transaction
that can be obtained by FoldOperation.openTransaction()
.
Modifier and Type | Method and Description |
---|---|
Fold |
addToHierarchy(FoldType type,
int startOffset,
int endOffset,
Boolean collapsed,
FoldTemplate template,
String displayOverride,
Object extraInfo,
FoldHierarchyTransaction transaction)
Adds a fold to the hierarchy.
|
Fold |
addToHierarchy(FoldType type,
String description,
boolean collapsed,
int startOffset,
int endOffset,
int startGuardedLength,
int endGuardedLength,
Object extraInfo,
FoldHierarchyTransaction transaction)
Deprecated.
please use
FoldOperation.addToHierarchy(org.netbeans.api.editor.fold.FoldType, int, int, java.lang.Boolean, org.netbeans.api.editor.fold.FoldTemplate, java.lang.String, java.lang.Object, org.netbeans.spi.editor.fold.FoldHierarchyTransaction) .
This form of call does not support automatic state assignment and fold templates. |
Iterator<Fold> |
foldIterator()
Enumerates all Folds defined by this Operation, in the document-range order.
|
Object |
getExtraInfo(Fold fold)
Return extra info object passed to fold at time of its creation.
|
FoldHierarchy |
getHierarchy()
Get the hierarchy for which this fold operations works.
|
boolean |
isAddedOrBlocked(Fold fold)
Check whether the fold is currently present in the hierarchy or blocked.
|
boolean |
isBlocked(Fold fold)
Is the given fold blocked by another fold?
|
static boolean |
isBoundsValid(int startOffset,
int endOffset,
int startGuardedLength,
int endGuardedLength)
This static method can be used to check whether the bounds
of the fold that is planned to be added are valid.
|
boolean |
isEndDamaged(Fold fold)
Check whether the ending guarded area of the fold
is damaged by a document modification.
|
boolean |
isReleased()
Informs that the manager was released.
|
boolean |
isStartDamaged(Fold fold)
Check whether the starting guarded area of the fold
is damaged by a document modification.
|
FoldHierarchyTransaction |
openTransaction()
Open a new transaction over the fold hierarchy.
|
boolean |
owns(Fold fold)
Check whether this fold operation has produced the given fold.
|
void |
removeFromHierarchy(Fold fold,
FoldHierarchyTransaction transaction)
Remove the fold that is either present in the hierarchy or blocked
by another fold.
|
Map<FoldInfo,Fold> |
update(Collection<FoldInfo> infos,
Collection<Fold> removed,
Collection<FoldInfo> created)
Performs refresh of folding information.
|
public Fold addToHierarchy(FoldType type, String description, boolean collapsed, int startOffset, int endOffset, int startGuardedLength, int endGuardedLength, Object extraInfo, FoldHierarchyTransaction transaction) throws BadLocationException
FoldOperation.addToHierarchy(org.netbeans.api.editor.fold.FoldType, int, int, java.lang.Boolean, org.netbeans.api.editor.fold.FoldTemplate, java.lang.String, java.lang.Object, org.netbeans.spi.editor.fold.FoldHierarchyTransaction)
.
This form of call does not support automatic state assignment and fold templates.
The fold is logically bound to the fold manager that uses this fold operation.
The fold can only be removed by this fold operation.
type
- type of the fold to be assigned to the fold.description
- textual description of the fold that will be displayed
once the fold becomes collapsed.collapsed
- whether the fold should initially be collapsed or expanded.startOffset
- starting offset of the fold. The fold creates swing position
for the offset.endOffset
- ending offset of the fold. The fold creates swing position
for the offset.startGuardedLength
- >=0 initial guarded area of the fold (starting at the start offset).
If the guarded area is modified the fold will be removed automatically.endGuardedLength
- >=0 ending guarded area of the fold (ending at the end offset).
If the guarded area is modified the fold will be removed automatically.extraInfo
- arbitrary extra information specific for the fold being created.
It's not touched or used by the folding infrastructure in any way.
null can be passed if there is no extra information.
The extra info of the existing fold can be obtained by
FoldOperation.getExtraInfo(org.netbeans.api.editor.fold.Fold)
.
BadLocationException
public Fold addToHierarchy(FoldType type, int startOffset, int endOffset, Boolean collapsed, FoldTemplate template, String displayOverride, Object extraInfo, FoldHierarchyTransaction transaction) throws BadLocationException
null
can be passed to indicate the infrastructure should
assign collapsed state based on e.g. user preferences. The exact assignment algorithm is left unspecified. Callers
are recommended not to assign collapsed/expanded state explicitly.
Usually, it's OK to pass null for collapsed, template and possibly extraInfo.
Events produced by this add- call will be fired when the 'transaction' is committed. However fold hierarch will
be changed immediately.type
- type of the fold, cannot be null
startOffset
- starting offsetendOffset
- end offsetcollapsed
- the initial collapsed state; if null
, the state will be assigned automatically.template
- the FoldTemplate to use instead of default template of the type. null
, if the type's template should be used.extraInfo
- arbitrary extra information specific for the fold being created.
It's not touched or used by the folding infrastructure in any way.
null can be passed if there is no extra information.
The extra info of the existing fold can be obtained by
FoldOperation.getExtraInfo(org.netbeans.api.editor.fold.Fold)
.
transaction
- the transaction that manages events, cannot be null.BadLocationException
public static boolean isBoundsValid(int startOffset, int endOffset, int startGuardedLength, int endGuardedLength)
startOffset < endOffset
startGuardedLength >= 0
endGuardedLength >= 0
startOffset + startGuardedLength <= endOffset - endGuardedLength
public void removeFromHierarchy(Fold fold, FoldHierarchyTransaction transaction)
fold
- fold to be removedtransaction
- non-null transaction under which the fold should be removed.public boolean owns(Fold fold)
fold
- non-null fold.addToHierarchy()
method)
or false otherwise.public Object getExtraInfo(Fold fold)
public boolean isStartDamaged(Fold fold)
fold
- fold to check. The fold must be managed by this fold operation.public boolean isEndDamaged(Fold fold)
fold
- fold to check. The fold must be managed by this fold operation.public FoldHierarchyTransaction openTransaction()
FoldHierarchyTransaction transaction = operation.openTransaction(); try { ... } finally { transaction.commit(); }
public boolean isAddedOrBlocked(Fold fold)
public boolean isBlocked(Fold fold)
public FoldHierarchy getHierarchy()
public boolean isReleased()
FoldManager
should be still operational.
Once released, the FoldManager (and its Operation) will not be used again by the infrastructure.public Iterator<Fold> foldIterator()
FoldHierarchy.lock()
. The Iterator may
be only used until that lock is released. After releasing the lock, the Iterator
may fail.public Map<FoldInfo,Fold> update(Collection<FoldInfo> infos, Collection<Fold> removed, Collection<FoldInfo> created) throws BadLocationException
FoldOperation.isBlocked(org.netbeans.api.editor.fold.Fold)
.
If the removed
or created
parameters are not null, the removed Fold instances, or the FoldInfos
that created new Folds will be put into those collection as a supplemental return value. The caller may then
update its own data with respect to the changes and the current Fold set.
Note: The method may be only called under FoldHierarchy.lock()
. This implies the document is also read-locked.
The caller must check whether a modification happen in between the FoldInfos were produced at the
document + hierarchy lock. The method creates and commits its own FoldTransaction
- they are not reentrant,
so do not call the method under a transaction.infos
- current state of folds that should be updated to the hierarchyremoved
- Collection that will receive Folds, which have been removed from the hierarchy, or null
, if the caller
does not want to receive the informationcreated
- Collection that will receive FoldInfos that created new Folds in the hierarchy, null
means
the caller is not interested in the creation information.null
, if the manager has been
released.BadLocationException