use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem.Visitor in project mylyn.docs by eclipse.
the class ActiveFoldingListener method updateFolding.
private void updateFolding(boolean elementsDeleted) {
if (!foldingStructure.isFoldingEnabled()) {
return;
}
if (!foldingEnabled || !ContextCore.getContextManager().isContextActive()) {
foldingStructure.expandAll();
} else {
OutlineItem outline = (OutlineItem) part.getAdapter(OutlineItem.class);
if (outline != null) {
final List<OutlineItem> toExpand = new ArrayList<OutlineItem>();
outline.accept(new Visitor() {
public boolean visit(OutlineItem item) {
String identifier = bridge.getHandleIdentifier(item);
IInteractionElement element = ContextCore.getContextManager().getElement(identifier);
if (element != null && element.getInterest().isInteresting()) {
toExpand.add(item);
}
return true;
}
});
if (toExpand.isEmpty()) {
foldingStructure.collapseAll(elementsDeleted);
} else {
foldingStructure.expandElementsExclusive(toExpand, elementsDeleted);
}
}
}
}
use of org.eclipse.mylyn.wikitext.parser.outline.OutlineItem.Visitor in project mylyn.docs by eclipse.
the class AnchorCompletionProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
if (outline == null) {
return null;
}
ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
// adjust offset to end of normalized selection
if (selection.getOffset() == offset) {
offset = selection.getOffset() + selection.getLength();
}
final String prefix = extractPrefix(viewer, offset);
if (prefix == null) {
return null;
}
final List<CompletionProposal> suggestions = new ArrayList<>(20);
final int prefixOffset = offset - prefix.length();
outline.accept(new Visitor() {
public boolean visit(OutlineItem item) {
if (item != outline) {
String id = item.getId();
if (id != null && id.length() > 0) {
suggestions.add(createProposal(prefix, prefixOffset, id));
}
}
return true;
}
});
if (suggestions.isEmpty()) {
return null;
}
Collections.sort(suggestions, PROPOSAL_COMPARATOR);
return suggestions.toArray(new ICompletionProposal[suggestions.size()]);
}
Aggregations