use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.
the class ReconcilerTest method testMultipleReconcilers.
@Test
public void testMultipleReconcilers() throws Exception {
secondFile = project.getFile("bar.txt");
secondFile.create(new ByteArrayInputStream("".getBytes()), true, null);
secondEditor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(secondFile), "org.eclipse.ui.genericeditor.GenericEditor");
performTestOnEditor(ReconcilerStrategyFirst.SEARCH_TERM, secondEditor, ReconcilerStrategySecond.REPLACEMENT);
}
use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.
the class ReconcilerTest method testMultipleEditors.
@Test
public void testMultipleEditors() throws Exception {
secondProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
secondProject.create(null);
secondProject.open(null);
secondFile = secondProject.getFile("foo.txt");
secondFile.create(new ByteArrayInputStream("bar 'bar'".getBytes()), true, null);
secondEditor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(secondFile), "org.eclipse.ui.genericeditor.GenericEditor");
performTestOnEditor(ReconcilerStrategyFirst.SEARCH_TERM, editor, ReconcilerStrategyFirst.REPLACEMENT);
}
use of org.eclipse.ui.part.FileEditorInput in project linuxtools by eclipse.
the class ContentAssistTests method getResults.
protected ICompletionProposal[] getResults(IFile file, int offset) throws Exception {
disableContributions();
// call the ContentAssistProcessor
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
FileEditorInput editorInput = new FileEditorInput(file);
IEditorPart editorPart = page.openEditor(editorInput, "org.eclipse.cdt.ui.editor.CEditor");
CEditor editor = (CEditor) editorPart;
@SuppressWarnings("unused") IAction completionAction = editor.getAction("ContentAssistProposal");
String contentType = editor.getViewer().getDocument().getContentType(offset);
ContentAssistant assistant = new ContentAssistant();
CContentAssistProcessor processor = new CContentAssistProcessor(editor, assistant, contentType);
return processor.computeCompletionProposals(editor.getViewer(), offset);
}
use of org.eclipse.ui.part.FileEditorInput in project linuxtools by eclipse.
the class SpecStructureCreator method parseSpecfile.
private void parseSpecfile(DocumentRangeNode root, IDocument doc, IFile file) {
SpecfileParser parser = new SpecfileParser();
// FIXME: error markers do not show
if (file != null) {
FileEditorInput fei = new FileEditorInput(file);
// without it, the compare editor is blank
try {
SpecfileEditor.getSpecfileDocumentProvider().disconnect(fei);
SpecfileEditor.getSpecfileDocumentProvider().connect(fei);
} catch (CoreException e) {
SpecfileLog.logError(e);
}
parser.setErrorHandler(new SpecfileErrorHandler(fei, doc));
parser.setTaskHandler(new SpecfileTaskHandler(fei, doc));
Specfile specfile = parser.parse(doc);
String id = specfile.getName();
// Be a child under parent node of specfileSectionRoot (would be
// rootNode)
SpecNode fileNode = new SpecNode((DocumentRangeNode) root.getParentNode(), 1, id, doc, 0, doc.getLength());
for (SpecfileSection sec : specfile.getSections()) {
try {
addNode(root, doc, sec.getName(), doc.getLineOffset(sec.getLineNumber()), doc.getLineOffset(sec.getSectionEndLine()) - doc.getLineOffset(sec.getLineNumber()), 2);
} catch (BadLocationException e) {
SpecfileLog.logError(e);
}
}
// Be a child under the parent file node
for (SpecfilePackage sPackage : specfile.getPackages().getPackages()) {
try {
SpecNode pNode = addNode(fileNode, doc, sPackage.getPackageName(), doc.getLineOffset(sPackage.getLineNumber()), doc.getLineOffset(sPackage.getSectionEndLine()) - doc.getLineOffset(sPackage.getLineNumber()), 3);
for (SpecfileSection section : sPackage.getSections()) {
addNode(pNode, doc, section.getName(), doc.getLineOffset(section.getLineNumber()), doc.getLineOffset(section.getSectionEndLine()) - doc.getLineOffset(section.getLineNumber()), 4);
}
} catch (BadLocationException e) {
SpecfileLog.logError(e);
}
}
}
}
use of org.eclipse.ui.part.FileEditorInput in project linuxtools by eclipse.
the class SourcesFileHyperlinkDetector method detectHyperlinks.
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
if (region == null || textViewer == null) {
return null;
}
if (editor == null) {
editor = this.getAdapter(SpecfileEditor.class);
if (editor == null) {
return null;
}
}
IDocument document = textViewer.getDocument();
int offset = region.getOffset();
if (document == null) {
return null;
}
IRegion lineInfo;
String line;
try {
lineInfo = document.getLineInformationOfOffset(offset);
line = document.get(lineInfo.getOffset(), lineInfo.getLength());
} catch (BadLocationException ex) {
return null;
}
List<IHyperlink> tempHList = new ArrayList<>();
// !! it feels like there is duplicate code, fix that !!
if (editor.getEditorInput() instanceof FileEditorInput) {
IFile original = ((FileEditorInput) editor.getEditorInput()).getFile();
if (line.startsWith(SOURCE_IDENTIFIER) || line.startsWith(PATCH_IDENTIFIER) || line.startsWith(URL_IDENTIFIER)) {
int delimiterIndex = line.indexOf(':') + 1;
String identifierValue = line.substring(delimiterIndex).trim();
boolean validURL = RPMUtils.isValidUrl(identifierValue);
// if valid URL, get its file name; else make file name the original identifier value
String fileName = validURL ? RPMUtils.getURLFilename(identifierValue) : identifierValue;
String resolvedFileName = UiUtils.resolveDefines(editor.getSpecfile(), fileName);
boolean fileExists = RPMUtils.fileExistsInSources(original, resolvedFileName);
if (region.getOffset() > lineInfo.getOffset() + line.indexOf(identifierValue)) {
IRegion fileNameRegion = new Region(lineInfo.getOffset() + line.indexOf(identifierValue), identifierValue.length());
if (fileExists) {
// add "Open" file option
tempHList.add(new SourcesFileHyperlink(original, resolvedFileName, fileNameRegion));
} else {
if (line.startsWith(PATCH_IDENTIFIER) && !identifierValue.endsWith("/")) {
// $NON-NLS-1$
// add "Create" patch option using filename
tempHList.add(new SourcesFileCreateHyperlink(original, resolvedFileName, fileNameRegion));
}
}
// if valid URL and has a valid file
if (validURL && !identifierValue.endsWith("/")) {
// $NON-NLS-1$
// add "Download" option
tempHList.add(new SourcesFileDownloadHyperlink(original, UiUtils.resolveDefines(editor.getSpecfile(), identifierValue), fileNameRegion));
}
}
}
}
return tempHList.isEmpty() ? null : tempHList.toArray(new IHyperlink[tempHList.size()]);
}
Aggregations