use of name.graf.emanuel.testfileeditor.model.TestFile in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class Editor method createSourceViewer.
@Override
protected ISourceViewer createSourceViewer(final Composite parent, final IVerticalRuler ruler, final int styles) {
final ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
getSourceViewerDecorationSupport(viewer);
final IEditorInput input = getEditorInput();
final IDocument document = getDocumentProvider().getDocument(input);
file = new TestFile((FileEditorInput) input, getDocumentProvider());
file.parse();
document.addDocumentListener(new IDocumentListener() {
@Override
public void documentChanged(final DocumentEvent event) {
file.parse();
}
@Override
public void documentAboutToBeChanged(final DocumentEvent event) {
}
});
return viewer;
}
use of name.graf.emanuel.testfileeditor.model.TestFile in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class VirtualLineNumberRuler method update.
@Override
public void update(final Observable o, final Object arg) {
if (o instanceof TestFile) {
final List<Integer> startLineNumbers = new ArrayList<>();
final List<Integer> endLineNumbers = new ArrayList<>();
final TestFile file = (TestFile) o;
final IDocument document = getEditor().getDocumentProvider().getDocument(getEditor().getEditorInput());
final Test[] tests = file.getTests();
try {
for (final Test test : tests) {
final Node[] files = test.getChildren();
Position nodePosition = test.getPosition();
int realLine = document.getLineOfOffset(nodePosition.offset);
endLineNumbers.add(realLine + 1);
for (final Node testNode : files) {
nodePosition = testNode.getPosition();
realLine = document.getLineOfOffset(nodePosition.offset) + 1;
if (testNode instanceof File) {
final String name = testNode.toString();
if (name.endsWith(".cpp") || name.endsWith(".h") || name.endsWith(".hpp")) {
startLineNumbers.add(realLine);
} else {
endLineNumbers.add(realLine);
}
} else if (testNode instanceof Expected) {
startLineNumbers.add(realLine);
} else {
endLineNumbers.add(realLine);
}
}
}
} catch (final BadLocationException e) {
e.printStackTrace();
}
modelLineToRulerLineMap.clear();
int largestNumber = 0;
final int lines = document.getNumberOfLines() + 1;
boolean inFile = false;
int rulerLine = 1;
for (int line = 1; line < lines; ++line) {
if (startLineNumbers.contains(line)) {
inFile = true;
rulerLine = 1;
continue;
} else if (endLineNumbers.contains(line)) {
inFile = false;
} else if (inFile) {
if (rulerLine > largestNumber) {
largestNumber = rulerLine;
}
modelLineToRulerLineMap.put(line - 1, rulerLine++);
}
}
maxDigits = Integer.toString(largestNumber).length();
redraw();
}
}
use of name.graf.emanuel.testfileeditor.model.TestFile in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class VirtualLineNumberRuler method createControl.
@Override
public Control createControl(final CompositeRuler parentRuler, final Composite parentControl) {
fparentRuler = parentRuler;
textWidget = parentRuler.getTextViewer();
final TestFile file = textEditor.getAdapter(TestFile.class);
file.addObserver(this);
update(file, null);
final RGB foreground = getColor(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR);
final RGB background = getColor(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
setForeground(EditorsPlugin.getDefault().getSharedTextColors().getColor(foreground));
setBackground(EditorsPlugin.getDefault().getSharedTextColors().getColor(background));
final Control fCanvas = super.createControl(parentRuler, parentControl);
fMouseHandler = new MouseHandler();
fCanvas.addMouseListener(fMouseHandler);
fCanvas.addMouseMoveListener(fMouseHandler);
fCanvas.addMouseWheelListener(fMouseHandler);
return fCanvas;
}
use of name.graf.emanuel.testfileeditor.model.TestFile in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class JumpToRTSHandler method jump.
private void jump() {
if (className != null) {
IType cls = null;
try {
cls = project.findType(className);
} catch (JavaModelException e) {
return;
}
try {
IFile file = project.getProject().getFile(getTestFileName(cls));
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
FileEditorInput input = new FileEditorInput(file);
IDocumentProvider provider = new TextFileDocumentProvider();
provider.connect(input);
IDocument document = provider.getDocument(input);
TestFile testFile = new TestFile(input, provider);
testFile.parse();
IEditorDescriptor defaultEditor = workbench.getEditorRegistry().getDefaultEditor(file.getName());
String editorId = defaultEditor.getId();
if (!className.equals(testName)) {
for (Test test : testFile.getTests()) {
if (test.toString().equals(testName)) {
int line = document.getLineOfOffset(test.getPosition().getOffset());
IMarker lineMarker = file.createMarker(IMarker.TEXT);
lineMarker.setAttribute(IMarker.LINE_NUMBER, line + 1);
lineMarker.setAttribute(IDE.EDITOR_ID_ATTR, editorId);
IDE.openEditor(page, lineMarker);
lineMarker.delete();
return;
}
}
} else {
IDE.openEditor(page, file);
}
} catch (CoreException | BadLocationException | NullPointerException e) {
e.printStackTrace();
MessageDialog.openError(shell, "Jump to RTS", "Failed to find associated RTS file.");
}
}
}
Aggregations