use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class OpenSourceFileAction method openAnnotatedSourceFile.
public static void openAnnotatedSourceFile(IProject project, IFile binary, SourceFile sourceFile, IPath realLocation, int lineNumber) {
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
IWorkbenchPage page = CUIPlugin.getActivePage();
if (page != null) {
IFileStore fs = getFileStore(project, realLocation);
if (fs == null && !realLocation.isAbsolute() && binary != null) {
IPath p = binary.getProjectRelativePath().removeLastSegments(1);
fs = getFileStore(project, p.append(realLocation));
}
if (fs == null) {
try {
page.openEditor(new STAnnotatedSourceNotFoundEditorInput(project, sourceFile, realLocation, lineNumber), STAnnotatedSourceNotFoundEditor.ID, true);
} catch (PartInitException e) {
Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
Activator.getDefault().getLog().log(s);
}
} else {
try {
IEditorPart editor = IDE.openEditorOnFileStore(page, fs);
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);
} catch (BadLocationException e) {
// ignore
}
IWorkbenchPage p = editor.getSite().getPage();
p.activate(editor);
}
} catch (PartInitException e) {
Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
Activator.getDefault().getLog().log(s);
}
}
}
});
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class KernelSourceTreeTest method testBuildKernelTree.
@Test
public void testBuildKernelTree() {
TreeNode t;
// Null
String direct = null;
String[] excluded = null;
kst.buildKernelTree(direct, excluded);
assertNull("Null directory", kst.getTree());
// Empty string for directory
direct = "";
kst.buildKernelTree(direct, excluded);
assertNull("Empty string directory", kst.getTree());
// Missing folder
direct = "/noSuchDirectory/";
kst.buildKernelTree(direct, excluded);
assertEquals("Missing directory", 0, kst.getTree().getChildCount());
// Inaccessible
direct = "/root/";
kst.buildKernelTree(direct, excluded);
assertEquals("Inaccessable directory", 0, kst.getTree().getChildCount());
// No .c or .h files
direct = "/bin/";
kst.buildKernelTree(direct, excluded);
t = kst.getTree();
assertEquals("Bin folder item count", 0, t.getChildCount());
assertTrue("Bin folder name", "bin".equals(t.toString()));
assertTrue("Bin has file", t.getData() instanceof IFileStore);
excluded = new String[] { ".git" };
// No .c or .h files
direct = "/tmp/";
kst.buildKernelTree(direct, excluded);
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class ErrorLineMatcher method matchFound.
@Override
public void matchFound(PatternMatchEvent event) {
try {
String line = console.getDocument().get(event.getOffset(), event.getLength());
String file = line.substring(line.indexOf('/'));
// $NON-NLS-1$
String[] splitted = file.split(":");
Path path = new Path(splitted[0]);
if (path.toFile().exists()) {
IFileStore iFileStore = EFS.getLocalFileSystem().getStore(path);
FileHyperlink fileLink = new FileHyperlink(iFileStore, Integer.valueOf(splitted[1]));
console.addHyperlink(fileLink, line.indexOf('/') + event.getOffset(), file.length());
}
} catch (BadLocationException e1) {
return;
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class OpenFileHandler method runActions.
private void runActions(File file) {
successful = false;
IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
IWorkbenchPage page = window.getActivePage();
try {
IDE.openEditorOnFileStore(page, fileStore);
successful = true;
} catch (PartInitException e) {
ErrorDialog.openError(window.getShell(), // $NON-NLS-1$
Localization.getString("OpenFileHandler.Problem"), // $NON-NLS-1$
Localization.getString("OpenFileHandler.ProblemMessage"), new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, e.getMessage(), e));
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class ImageBuildPage method validate.
private void validate() {
boolean complete = true;
boolean error = false;
setMessage(null);
String name = nameText.getText();
if (name.length() > 0 && name.charAt(name.length() - 1) == ':') {
setErrorMessage(WizardMessages.getString(INVALID_ID));
error = true;
} else {
if (name.contains(":")) {
// $NON-NLS-1$
if (name.substring(name.indexOf(':') + 1).contains(":")) {
// $NON-NLS-1$
setErrorMessage(WizardMessages.getString(INVALID_ID));
error = true;
}
} else if (name.isEmpty()) {
setMessage(WizardMessages.getString(IMAGE_NAME_EMPTY), WARNING);
}
}
if (!error) {
String dir = directoryText.getText();
if (dir.length() == 0) {
editButton.setEnabled(false);
complete = false;
} else {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(dir));
IFileInfo info = fileStore.fetchInfo();
if (!info.exists()) {
error = true;
setErrorMessage(WizardMessages.getString(NONEXISTENT_DIRECTORY));
} else if (!info.isDirectory()) {
error = true;
setErrorMessage(WizardMessages.getString(INVALID_DIRECTORY));
} else if (!Files.isReadable(Paths.get(dir))) {
error = true;
setErrorMessage(WizardMessages.getString(UNREADABLE_DIRECTORY));
} else {
editButton.setEnabled(true);
// $NON-NLS-1$
IFileStore dockerStore = fileStore.getChild("Dockerfile");
if (!dockerStore.fetchInfo().exists()) {
complete = false;
setMessage(WizardMessages.getString(NO_DOCKER_FILE), IMessageProvider.INFORMATION);
} else {
lastDirectoryPath = dir;
}
}
}
}
if (!error) {
setErrorMessage(null);
} else {
editButton.setEnabled(false);
}
setPageComplete(complete && !error);
}
Aggregations