Search in sources :

Example 1 with Visitor

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);
            }
        }
    }
}
Also used : Visitor(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem.Visitor) ArrayList(java.util.ArrayList) IInteractionElement(org.eclipse.mylyn.context.core.IInteractionElement) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 2 with Visitor

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()]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Visitor(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem.Visitor) ArrayList(java.util.ArrayList) ITextSelection(org.eclipse.jface.text.ITextSelection) Point(org.eclipse.swt.graphics.Point) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Aggregations

ArrayList (java.util.ArrayList)2 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)2 Visitor (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem.Visitor)2 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IInteractionElement (org.eclipse.mylyn.context.core.IInteractionElement)1 Point (org.eclipse.swt.graphics.Point)1