use of org.eclipse.ui.IEditorInput in project xtext-xtend by eclipse.
the class XbaseEditorInputRedirectorTest method testOpenDerivedFileFromBin.
@Test
public void testOpenDerivedFileFromBin() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package mypack");
_builder.newLine();
_builder.append("class HelloXtend {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void doStuff() {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IFile fileInSrc = this.helper.createFileImpl((WorkbenchTestHelper.TESTPROJECT_NAME + "/src/mypack/HelloXtend.xtend"), _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package mypack");
_builder_1.newLine();
_builder_1.append("class HelloXtend {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def void doStuff() {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final IFile fileInBin = this.helper.createFileImpl((WorkbenchTestHelper.TESTPROJECT_NAME + "/bin/mypack/HelloXtend.xtend"), _builder_1.toString());
FileEditorInput _fileEditorInput = new FileEditorInput(fileInBin);
final IEditorInput result = this.redirector.findOriginalSource(_fileEditorInput);
Assert.assertEquals(fileInSrc, ResourceUtil.getFile(result));
FileEditorInput _fileEditorInput_1 = new FileEditorInput(fileInSrc);
final IEditorInput result2 = this.redirector.findOriginalSource(_fileEditorInput_1);
Assert.assertEquals(fileInSrc, ResourceUtil.getFile(result2));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.
the class STLink2SourceSupport method openFileImpl.
private static boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) {
if (sourceLoc == null || "??".equals(sourceLoc.toString())) {
// $NON-NLS-1$
return false;
}
try {
IEditorInput editorInput = getEditorInput(sourceLoc, project);
IWorkbenchPage p = CUIPlugin.getActivePage();
if (p != null) {
if (editorInput == null) {
p.openEditor(new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber), STCSourceNotFoundEditor.ID, true);
} else {
IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true);
if (lineNumber > 0 && editor instanceof ITextEditor) {
IDocumentProvider provider = ((ITextEditor) editor).getDocumentProvider();
IDocument document = provider.getDocument(editor.getEditorInput());
try {
int start = document.getLineOffset(lineNumber - 1);
((ITextEditor) editor).selectAndReveal(start, 0);
IWorkbenchPage page = editor.getSite().getPage();
page.activate(editor);
return true;
} catch (BadLocationException x) {
// ignore
}
}
}
}
} catch (PartInitException e) {
}
return false;
}
use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Opens the specified file in an editor (or selects an already open
* editor) and highlights the specified line.
* @param result - result of performing source lookup with a org.eclipse.debug.core.model.ISourceLocator
* @param line - line number to select, 0 to not select a line
* @throws PartInitException - Failed to open editor
* @throws BadLocationException - Line number not valid in file
* @see DebugUITools#lookupSource(Object, org.eclipse.debug.core.model.ISourceLocator)
*/
public static void openEditorAndSelect(ISourceLookupResult result, int line) throws PartInitException, BadLocationException {
IEditorInput input = result.getEditorInput();
String editorID = result.getEditorId();
if (input == null || editorID == null) {
// Consult the CDT DebugModelPresentation
Object sourceElement = result.getSourceElement();
if (sourceElement != null) {
// Resolve IResource in case we get a LocalFileStorage object
if (sourceElement instanceof LocalFileStorage) {
IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
URI fileURI = URIUtil.toURI(filePath);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = root.findFilesForLocationURI(fileURI);
if (files.length > 0) {
// Take the first match
sourceElement = files[0];
}
}
IDebugModelPresentation pres = DebugUITools.newDebugModelPresentation(CDebugCorePlugin.getUniqueIdentifier());
input = pres.getEditorInput(sourceElement);
editorID = pres.getEditorId(input, sourceElement);
pres.dispose();
}
}
if (input != null && editorID != null) {
// Open the editor
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditor(activePage, input, editorID);
// Select the line
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
if (line > 0) {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
// zero-indexed
IRegion lineRegion = document.getLineInformation(line - 1);
textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength());
}
}
}
}
use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.
the class ChartExportTest method testChartExportPNG.
@Test
public void testChartExportPNG() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testDefaults");
IEditorInput input = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();
assertTrue("input must be ChartEditorInput", input instanceof ChartEditorInput);
Composite control = ((ChartEditorInput) input).getChart().getChartControl();
if (control.getSize().x == 0 || control.getSize().y == 0) {
// Manually resize the composite to non-zero width/height so it can be saved
control.setSize(10, 10);
}
SaveChartAction saveChartAction = (SaveChartAction) getToolbarAction(MassifViewPart.SAVE_CHART_ACTION);
assertNotNull(saveChartAction);
for (IPath path : paths) {
saveAsPath(saveChartAction, path);
}
}
use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.
the class DoubleClickTest method checkFile.
private IEditorPart checkFile(CachegrindFile file) {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IEditorInput input = editor.getEditorInput();
IFileEditorInput fileInput = (IFileEditorInput) input;
IResource expectedResource = proj.getProject().findMember(file.getName());
File expectedFile = expectedResource.getLocation().toFile();
File actualFile = fileInput.getFile().getLocation().toFile();
assertEquals(expectedFile, actualFile);
return editor;
}
Aggregations