Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;

import com.nitorcreations.robotframework.eclipseide.Activator;
import com.nitorcreations.robotframework.eclipseide.PluginContext;
import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotFile;
import com.nitorcreations.robotframework.eclipseide.editors.outline.ParsedStringEntry;
import com.nitorcreations.robotframework.eclipseide.editors.outline.RobotOutlinePage;

/**
* https://robotframework.googlecode.com/hg/doc/userguide/ RobotFrameworkUserGuide.html?r=2.6.1 http:/
Expand All @@ -46,6 +53,8 @@ public class RobotFrameworkTextfileEditor extends TextEditor {

private ColorManager colorManager;

private RobotOutlinePage outlinePage;

@Override
protected void doSetInput(IEditorInput input) throws CoreException {
handleClosePossiblyOpenDocument();
Expand Down Expand Up @@ -100,7 +109,7 @@ public IDocument getEditedDocument() {
}

public IFile getEditedFile() {
return (IFile) getEditorInput().getAdapter(IFile.class);
return getEditorInput().getAdapter(IFile.class);
}

@Override
Expand Down Expand Up @@ -140,6 +149,44 @@ protected void initializeEditor() {
setSourceViewerConfiguration(new RobotSourceViewerConfiguration(colorManager, getPreferenceStore()));
setDocumentProvider(new FileDocumentProvider());
}

@Override
public Object getAdapter(Class required) {
if (IContentOutlinePage.class.equals(required)) {
if (outlinePage == null) {
outlinePage = new RobotOutlinePage(getDocumentProvider());
outlinePage.addSelectionChangedListener(new RobotOutlineSelectionChangedListener(this));
if (getEditorInput() != null)
outlinePage.setInput(getEditorInput());
}
return outlinePage;
}
return super.getAdapter(required);
}

private final class RobotOutlineSelectionChangedListener implements ISelectionChangedListener {
private final ITextEditor textEditor;

public RobotOutlineSelectionChangedListener(ITextEditor textEditor) {
this.textEditor = textEditor;
}

@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();

// so far, we only support the selection of one entry at a time - see RobotOutlinePage#getTreeStyle()
Object domain = selection.getFirstElement();
if (domain instanceof ParsedStringEntry) {
ParsedStringEntry lineEntry = (ParsedStringEntry) domain;
int startCharPos = lineEntry.getStartCharPos();
int endCharPos = lineEntry.getEndCharPos();
textEditor.selectAndReveal(startCharPos, endCharPos - startCharPos);
}
}
}
}
}

// 190312 1720 xxxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.nitorcreations.robotframework.eclipseide.editors.outline;

import com.nitorcreations.robotframework.eclipseide.structure.ParsedString;

public class ParsedStringEntry {
final RootCategoryEntry parent;
final ParsedString parsedString;

public ParsedStringEntry(RootCategoryEntry parent, ParsedString parsedString) {
this.parent = parent;
this.parsedString = parsedString;
}

public RootCategoryEntry getParent() {
assert parent != null;
return parent;
}

public int getStartCharPos() {
return parsedString.getArgCharPos();
}

public int getEndCharPos() {
return parsedString.getArgEndCharPos();
}

@Override
public String toString() {
return parsedString.getValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.nitorcreations.robotframework.eclipseide.editors.outline;

import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.texteditor.IDocumentProvider;

import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotFile;
import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotLine;
import com.nitorcreations.robotframework.eclipseide.structure.ParsedString;

final class RobotOutlineContentProvider implements IContentProvider, ITreeContentProvider {

private final IDocumentProvider documentProvider;

public RobotOutlineContentProvider(IDocumentProvider documentProvider) {
this.documentProvider = documentProvider;
}

@Override
public void dispose() {

}

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// System.out.println("InputChanged V " + viewer + " DP " + documentProvider + " EI " +
// robotContentOutlinePage.editorInput);
System.out.println("V " + viewer);
System.out.println("OLD: " + oldInput);
System.out.println("NEW: " + newInput);
}

@Override
public Object[] getElements(Object inputElement) {
System.out.println("getElements() " + inputElement);
IDocument document = documentProvider.getDocument(inputElement);
RobotFile rf = RobotFile.get(document);
Set<ParsedString> testCases = new LinkedHashSet<ParsedString>();
Set<ParsedString> keywords = new LinkedHashSet<ParsedString>();
Set<ParsedString> variables = new LinkedHashSet<ParsedString>();
for (RobotLine line : rf.getLines()) {
switch (line.type) {
case TESTCASE_TABLE_TESTCASE_BEGIN:
testCases.add(line.arguments.get(0));
break;
case KEYWORD_TABLE_KEYWORD_BEGIN:
keywords.add(line.arguments.get(0));
break;
case VARIABLE_TABLE_LINE:
variables.add(line.arguments.get(0));
break;
}
}
return new Object[] {//
new RootCategoryEntry(inputElement, "Test cases", testCases), //
new RootCategoryEntry(inputElement, "Keywords", keywords),//
new RootCategoryEntry(inputElement, "Variables", variables),//
};
}

@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof RootCategoryEntry) {
return ((RootCategoryEntry) parentElement).getEntries().toArray();
}
return new Object[0];
}

@Override
public Object getParent(Object element) {
if (element instanceof ParsedStringEntry) {
return ((ParsedStringEntry) element).getParent();
}
return null;
}

@Override
public boolean hasChildren(Object element) {
return element instanceof RootCategoryEntry;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.nitorcreations.robotframework.eclipseide.editors.outline;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;

public class RobotOutlinePage extends ContentOutlinePage {

private final IDocumentProvider documentProvider;
private IEditorInput editorInput;

public RobotOutlinePage(IDocumentProvider documentProvider) {
this.documentProvider = documentProvider;
}

public void setInput(IEditorInput editorInput) {
this.editorInput = editorInput;
}

@Override
public void createControl(Composite parent) {
super.createControl(parent);
TreeViewer viewer = getTreeViewer();
viewer.setContentProvider(new RobotOutlineContentProvider(documentProvider));
viewer.setLabelProvider(new LabelProvider()); // we could use custom label provider here to get fancy icons

if (editorInput != null) {
viewer.setInput(editorInput);
}
}

@Override
public void selectionChanged(SelectionChangedEvent event) {
super.selectionChanged(event);

// TODO Jump to selection
}

@Override
protected int getTreeStyle() {
return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.nitorcreations.robotframework.eclipseide.editors.outline;

import java.util.LinkedHashSet;
import java.util.Set;

import com.nitorcreations.robotframework.eclipseide.structure.ParsedString;

public class RootCategoryEntry {
final Object input;
final String category;
final Set<ParsedStringEntry> entries;

public RootCategoryEntry(Object input, String category, Set<ParsedString> parsedStrings) {
this.input = input;
this.category = category;
this.entries = new LinkedHashSet<ParsedStringEntry>(parsedStrings.size());
for (ParsedString parsedString : parsedStrings) {
ParsedStringEntry entry = new ParsedStringEntry(this, parsedString);
entries.add(entry);
}
}

public Object getInput() {
return input;
}

public Set<ParsedStringEntry> getEntries() {
return entries;
}

@Override
public String toString() {
return category;
}
}