Search in sources :

Example 6 with IOutlineNode

use of org.eclipse.xtext.ui.editor.outline.IOutlineNode in project xtext-xtend by eclipse.

the class XtendOutlinePage method getInitiallyExpandedNodes.

@Override
protected List<IOutlineNode> getInitiallyExpandedNodes() {
    IOutlineNode rootNode = getTreeProvider().createRoot(getXtextDocument());
    List<IOutlineNode> result = newArrayList(rootNode);
    for (IOutlineNode firstLevelNode : rootNode.getChildren()) if (firstLevelNode instanceof EObjectNode)
        result.add(firstLevelNode);
    return result;
}
Also used : EObjectNode(org.eclipse.xtext.ui.editor.outline.impl.EObjectNode) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 7 with IOutlineNode

use of org.eclipse.xtext.ui.editor.outline.IOutlineNode in project xtext-xtend by eclipse.

the class XtendOutlineWithEditorLinker method selectInTreeView.

@Override
public void selectInTreeView(final ISelection selection) {
    if (((selection instanceof ITextSelection) && (!this.treeViewer.getTree().isDisposed()))) {
        final ITextSelection textSelection = ((ITextSelection) selection);
        int _offset = textSelection.getOffset();
        int _length = textSelection.getLength();
        final TextRegion selectedTextRegion = new TextRegion(_offset, _length);
        final Object input = this.treeViewer.getInput();
        if ((input instanceof IOutlineNode)) {
            final List<IOutlineNode> matchingNodes = CollectionLiterals.<IOutlineNode>newArrayList();
            this.findNodesInRange(((IOutlineNode) input), selectedTextRegion, matchingNodes);
            boolean _isEmpty = matchingNodes.isEmpty();
            boolean _not = (!_isEmpty);
            if (_not) {
                final Function1<IOutlineNode, Integer> _function = (IOutlineNode it) -> {
                    return Integer.valueOf(it.getFullTextRegion().getLength());
                };
                final Integer smallestMatch = IterableExtensions.<Integer>min(ListExtensions.<IOutlineNode, Integer>map(matchingNodes, _function));
                final Function1<IOutlineNode, Boolean> _function_1 = (IOutlineNode it) -> {
                    int _length_1 = it.getFullTextRegion().getLength();
                    return Boolean.valueOf((_length_1 == (smallestMatch).intValue()));
                };
                final Iterable<IOutlineNode> nodesToBeSelected = IterableExtensions.<IOutlineNode>filter(matchingNodes, _function_1);
                boolean _isEmpty_1 = IterableExtensions.isEmpty(nodesToBeSelected);
                boolean _not_1 = (!_isEmpty_1);
                if (_not_1) {
                    Object[] _array = IterableExtensions.<IOutlineNode>toList(nodesToBeSelected).toArray();
                    StructuredSelection _structuredSelection = new StructuredSelection(_array);
                    this.treeViewer.setSelection(_structuredSelection);
                }
            }
        }
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegion(org.eclipse.xtext.util.TextRegion) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 8 with IOutlineNode

use of org.eclipse.xtext.ui.editor.outline.IOutlineNode in project xtext-xtend by eclipse.

the class XtendOutlineWithEditorLinker method findNodesInRange.

protected void findNodesInRange(final IOutlineNode input, final ITextRegion selectedTextRegion, final List<IOutlineNode> nodes) {
    final ITextRegion textRegion = input.getFullTextRegion();
    if (((textRegion == null) || textRegion.contains(selectedTextRegion))) {
        nodes.add(input);
    }
    List<IOutlineNode> _children = input.getChildren();
    for (final IOutlineNode child : _children) {
        this.findNodesInRange(child, selectedTextRegion, nodes);
    }
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Example 9 with IOutlineNode

use of org.eclipse.xtext.ui.editor.outline.IOutlineNode in project xtext-xtend by eclipse.

the class OpenEditorTest method testOpenFromOutline.

@Test
public void testOpenFromOutline() throws Exception {
    XtextEditor bazXtendEditor = workbenchTestHelper.openEditor("outlinetest/Baz.xtend", "package outlinetest class Baz extends Foo { int baz }");
    IOutlineTreeProvider.ModeAware tp = (IOutlineTreeProvider.ModeAware) treeProvider;
    tp.setCurrentMode(tp.getOutlineModes().get(1));
    IOutlineNode outlineRoot = treeProvider.createRoot(bazXtendEditor.getDocument());
    IOutlineNode bazNode = outlineRoot.getChildren().get(1);
    assertEquals("Baz - outlinetest", bazNode.getText().toString());
    assertTrue(bazNode.getChildren().size() > 2);
    IOutlineNode baz = bazNode.getChildren().get(0);
    assertEquals("baz : int - Baz", baz.getText().toString());
    outlineNodeElementOpener.open(baz, bazXtendEditor.getInternalSourceViewer());
    assertActiveEditor("org.eclipse.xtend.core.Xtend", "Baz.xtend", "baz");
    IOutlineNode foo = bazNode.getChildren().get(1);
    assertEquals("foo : int - Foo", foo.getText().toString());
    outlineNodeElementOpener.open(foo, bazXtendEditor.getInternalSourceViewer());
    assertActiveEditor("org.eclipse.xtend.core.Xtend", "Foo.xtend", "foo");
    IOutlineNode bar = bazNode.getChildren().get(2);
    assertEquals("bar : int - Bar", bar.getText().toString());
    outlineNodeElementOpener.open(bar, bazXtendEditor.getInternalSourceViewer());
    assertActiveEditor(JavaUI.ID_CU_EDITOR, "Bar.java", "bar");
}
Also used : XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IOutlineTreeProvider(org.eclipse.xtext.ui.editor.outline.IOutlineTreeProvider) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode) Test(org.junit.Test)

Example 10 with IOutlineNode

use of org.eclipse.xtext.ui.editor.outline.IOutlineNode in project xtext-xtend by eclipse.

the class AbstractOutlineTests method newAssertBuilder.

protected AssertBuilder newAssertBuilder(XtendFile xtendFile) throws Exception, CoreException {
    XtextDocument document = documentProvider.get();
    document.setInput((XtextResource) xtendFile.eResource());
    IOutlineNode root = treeProvider.createRoot(document);
    AssertBuilder assertBuilder = new AssertBuilder(root);
    return assertBuilder;
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode)

Aggregations

IOutlineNode (org.eclipse.xtext.ui.editor.outline.IOutlineNode)13 EObjectNode (org.eclipse.xtext.ui.editor.outline.impl.EObjectNode)4 StyledString (org.eclipse.jface.viewers.StyledString)2 EStructuralFeatureNode (org.eclipse.xtext.ui.editor.outline.impl.EStructuralFeatureNode)2 ITextRegion (org.eclipse.xtext.util.ITextRegion)2 EObject (org.eclipse.emf.ecore.EObject)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 IXtendOutlineContext (org.eclipse.xtend.ide.common.outline.IXtendOutlineContext)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)1 IOutlineTreeProvider (org.eclipse.xtext.ui.editor.outline.IOutlineTreeProvider)1 DocumentRootNode (org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode)1 TextRegion (org.eclipse.xtext.util.TextRegion)1 Test (org.junit.Test)1