本文整理汇总了Java中org.eclipse.core.filesystem.EFS类的典型用法代码示例。如果您正苦于以下问题:Java EFS类的具体用法?Java EFS怎么用?Java EFS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EFS类属于org.eclipse.core.filesystem包,在下文中一共展示了EFS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: editFile
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
public static IEditorPart editFile(File file, boolean preferIdeEditor) throws IOException, PartInitException {
if (file == null || !file.exists() || !file.isFile() || !file.canRead()) {
throw new IOException("Invalid file: '" + file + "'");
}
IWorkbench workBench = PlatformUI.getWorkbench();
IWorkbenchPage page = workBench.getActiveWorkbenchWindow().getActivePage();
IPath location = Path.fromOSString(file.getAbsolutePath());
IFileStore fileStore = EFS.getLocalFileSystem().getStore(location);
FileStoreEditorInput fileStoreEditorInput = new FileStoreEditorInput(fileStore);
String editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID;
if (preferIdeEditor) {
IEditorDescriptor editorDescriptor = workBench.getEditorRegistry().getDefaultEditor(file.getName());
if (editorDescriptor != null) {
editorId = editorDescriptor.getId();
}
}
return page.openEditor(fileStoreEditorInput, editorId);
}
示例2: saveOpenTmpSqlEditor
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
/**
* Saves the content as a temp-file, opens it using SQL-editor
* and ensures that UTF-8 is used for everything.
*/
public static void saveOpenTmpSqlEditor(String content, String filenamePrefix) throws IOException, CoreException {
Log.log(Log.LOG_INFO, "Creating file " + filenamePrefix); //$NON-NLS-1$
Path path = Files.createTempFile(filenamePrefix + '_', ".sql"); //$NON-NLS-1$
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
IFileStore externalFile = EFS.getLocalFileSystem().fromLocalFile(path.toFile());
IEditorInput input = new FileStoreEditorInput(externalFile);
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.openEditor(input, EDITOR.SQL);
if (part instanceof ITextEditor) {
IDocumentProvider prov = ((ITextEditor) part).getDocumentProvider();
if (prov instanceof TextFileDocumentProvider) {
((TextFileDocumentProvider) prov).setEncoding(input, ApgdiffConsts.UTF_8);
prov.resetDocument(input);
}
}
}
示例3: openManifestForProject
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
public static void openManifestForProject(IProject project) {
File fileToOpen = new File(project.getFile("META-INF/MANIFEST.MF")
.getLocation().toOSString());
if (fileToOpen.exists() && fileToOpen.isFile()) {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(
fileToOpen.toURI());
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditorOnFileStore(page, fileStore);
} catch (PartInitException e) {
// Put your exception handler here if you wish to
}
} else {
// Do something if the file does not exist
}
}
示例4: openFile
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
public static void openFile(File file) {
if (file.exists() && file.isFile()) {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(
file.toURI());
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditorOnFileStore(page, fileStore);
} catch (PartInitException e) {
// Put your exception handler here if you wish to
}
} else {
// Do something if the file does not exist
}
}
示例5: storeEditorInput
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
/**
* Storing FileStorageEditor input into Ifile
*
* Generate Container from xml
* @throws IOException
*/
@Override
public void storeEditorInput() throws IOException, CoreException {
logger.debug("storeEditorInput - Storing FileStorageEditor input into Ifile");
File file = new File(fileStorageEditorInput.getToolTipText());
FileOutputStream fsout = new FileOutputStream(file);
ByteArrayOutputStream arrayOutputStream=new ByteArrayOutputStream();
CanvasUtils.INSTANCE.fromObjectToXML(
eltGraphicalEditorInstance.getContainer(),arrayOutputStream);
fsout.write(arrayOutputStream.toByteArray());
arrayOutputStream.close();
fsout.close();
eltGraphicalEditorInstance.getCommandStack().markSaveLocation();
eltGraphicalEditorInstance.setDirty(false);
IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(file);
this.eltGraphicalEditorInstance.genrateTargetXml(null,fileStore,null);
}
示例6: openEditor
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
private Container openEditor(IPath jobFilePath) throws CoreException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (!isJobAlreadyOpen(jobFilePath)) {
if (ResourcesPlugin.getWorkspace().getRoot().getFile(jobFilePath).exists()) {
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(jobFilePath);
IDE.openEditor(page, iFile);
} else {
if (jobFilePath.toFile().exists()) {
IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(jobFilePath.toFile());
IEditorInput store = new FileStoreEditorInput(fileStore);
IDE.openEditorOnFileStore(page, fileStore);
}
}
return SubJobUtility.getCurrentEditor().getContainer();
}else
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error",
"Unable to open subjob : "+jobFilePath.lastSegment()+" Subjob is already open \n" +
"Please close the job and retry");
return null;
}
示例7: getEditorInput
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
@Override
public IEditorInput getEditorInput(Object element) {
if (element instanceof ILineBreakpoint) {
return new FileEditorInput((IFile) ((ILineBreakpoint) element).getMarker().getResource());
}
IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(element.toString()));
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = root.findFilesForLocationURI(fileStore.toURI());
if (files != null) {
for (IFile file : files) {
if (file.exists()) {
return new FileEditorInput(file);
}
}
}
return new FileStoreEditorInput(fileStore);
}
示例8: handleFileLink
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
private IHyperlink[] handleFileLink(IRegion lineInfo, GradleHyperLinkResult result) {
try {
File folder = editorFile.getParentFile();
String fileName = result.linkContent;
File target = new File(folder, fileName);
if (!target.exists()) {
target = new File(fileName);
}
if (!target.exists()) {
return null;
}
IFileStore fileStore = EFS.getLocalFileSystem().getStore(target.toURI());
if (fileStore==null){
return null;
}
IRegion urlRegion = new Region(lineInfo.getOffset() + result.linkOffsetInLine, result.linkLength);
GradleFileHyperlink gradleFileHyperlink = new GradleFileHyperlink(urlRegion, fileStore);
return new IHyperlink[] { gradleFileHyperlink };
} catch (RuntimeException e) {
return null;
}
}
示例9: getFile
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
/**
* Get a {@link File} from {@link IFile}.
*
* @param file
* the iFile
* @return the iFile
* @throws TurnusException
*/
public static File getFile(IFile file) throws TurnusException {
try {
java.net.URI uri = file.getLocationURI();
if (file.isLinked()) {
uri = file.getRawLocationURI();
}
File jfile = EFS.getStore(uri).toLocalFile(0, new NullProgressMonitor());
return jfile;
} catch (Exception e) {
throw new TurnusException("Impossible to obtain the File from \"" + file + "\"");
}
}
示例10: getFilePath
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
private IPath getFilePath(ITextEditor textEditor) {
IEditorInput editorInput = textEditor.getEditorInput();
IFile file = ResourceUtil.getFile(editorInput);
File localFile = null;
if (file != null) {
localFile = file.getLocation().toFile();
} else if (editorInput instanceof FileStoreEditorInput) {
FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
URI uri = fileStoreEditorInput.getURI();
IFileStore location = EFS.getLocalFileSystem().getStore(uri);
try {
localFile = location.toLocalFile(EFS.NONE, null);
} catch (CoreException e) {
// ignore
}
}
if (localFile == null) {
return null;
} else {
return Path.fromOSString(localFile.toString());
}
}
示例11: isFolder
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
/**
* Determines if the listed item is a file or a folder.
*
* @param file
* @param monitor
* @return
* @throws CoreException
*/
private static boolean isFolder(IFileStore file, IProgressMonitor monitor) throws CoreException
{
// if we are an IContainer, folder == true;
// if we are an IFile, folder == false
// if neither, then check info for isDirectory()
IResource resource = (IResource) file.getAdapter(IResource.class);
if (resource instanceof IContainer)
{
return true;
}
if (!(resource instanceof IFile) && file.fetchInfo(EFS.NONE, monitor).isDirectory())
{
return true;
}
return false;
}
示例12: toFileStores
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
protected Set<IFileStore> toFileStores(IProgressMonitor monitor)
{
SubMonitor sub = SubMonitor.convert(monitor, files.size());
Set<IFileStore> fileStores = new HashSet<IFileStore>(files.size());
for (IFile file : files)
{
try
{
IFileStore store = EFS.getStore(file.getLocationURI());
if (store == null)
{
continue;
}
fileStores.add(store);
}
catch (CoreException e)
{
IdeLog.logError(IndexPlugin.getDefault(), e);
}
finally
{
sub.worked(1);
}
}
return fileStores;
}
示例13: move
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
/**
* The default implementation of {@link IFileStore#move(IFileStore, int, IProgressMonitor)}. This
* implementation performs a move by using other primitive methods. Subclasses may override this
* method.
*/
public void move(IFileStore destination, int options, IProgressMonitor monitor)
throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
monitor.beginTask(NLS.bind(Messages.moving, destination.toString()), 100);
copy(destination, options & EFS.OVERWRITE, Policy.subMonitorFor(monitor, 70));
delete(EFS.NONE, Policy.subMonitorFor(monitor, 30));
} catch (CoreException e) {
// throw new error to indicate failure occurred during a move
String message = NLS.bind(Messages.couldNotMove, toString());
Policy.error(EFS.ERROR_WRITE, message, e);
} finally {
monitor.done();
}
}
示例14: setAttribute
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
public void setAttribute(int attribute, boolean value) {
if (attribute == EFS.ATTRIBUTE_READ_ONLY && isAttributeSuported(EFS.ATTRIBUTE_OWNER_WRITE)) {
if (value) {
clear(EFS.ATTRIBUTE_OWNER_WRITE | EFS.ATTRIBUTE_OTHER_WRITE | EFS.ATTRIBUTE_GROUP_WRITE);
set(EFS.ATTRIBUTE_IMMUTABLE);
} else {
set(EFS.ATTRIBUTE_OWNER_WRITE | EFS.ATTRIBUTE_OWNER_READ);
clear(EFS.ATTRIBUTE_IMMUTABLE);
}
} else if (attribute == EFS.ATTRIBUTE_EXECUTABLE
&& isAttributeSuported(EFS.ATTRIBUTE_OWNER_EXECUTE)) {
if (value) set(EFS.ATTRIBUTE_OWNER_EXECUTE);
else
clear(
EFS.ATTRIBUTE_OWNER_EXECUTE
| EFS.ATTRIBUTE_GROUP_EXECUTE
| EFS.ATTRIBUTE_OTHER_EXECUTE);
} else {
if (value) set(attribute);
else clear(attribute);
}
}
示例15: copy
import org.eclipse.core.filesystem.EFS; //导入依赖的package包/类
public void copy(IFileStore destFile, int options, IProgressMonitor monitor)
throws CoreException {
if (destFile instanceof LocalFile) {
File source = file;
File destination = ((LocalFile) destFile).file;
// handle case variants on a case-insensitive OS, or copying between
// two equivalent files in an environment that supports symbolic links.
// in these nothing needs to be copied (and doing so would likely lose data)
try {
if (source.getCanonicalFile().equals(destination.getCanonicalFile())) {
// nothing to do
return;
}
} catch (IOException e) {
String message = NLS.bind(Messages.couldNotRead, source.getAbsolutePath());
Policy.error(EFS.ERROR_READ, message, e);
}
}
// fall through to super implementation
super.copy(destFile, options, monitor);
}