本文整理匯總了Java中org.eclipse.core.resources.IWorkspaceRoot.getFile方法的典型用法代碼示例。如果您正苦於以下問題:Java IWorkspaceRoot.getFile方法的具體用法?Java IWorkspaceRoot.getFile怎麽用?Java IWorkspaceRoot.getFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.core.resources.IWorkspaceRoot
的用法示例。
在下文中一共展示了IWorkspaceRoot.getFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getIFileFromResource
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
private IFile getIFileFromResource() {
Resource linkTargetResource = linkTarget.eResource();
if (linkTargetResource == null) {
return null;
}
URI resourceURI = linkTargetResource.getURI();
if (linkTargetResource.getResourceSet() != null && linkTargetResource.getResourceSet().getURIConverter() != null) {
resourceURI = linkTargetResource.getResourceSet().getURIConverter().normalize(resourceURI);
}
if (resourceURI.isPlatformResource()) {
String platformString = resourceURI.toPlatformString(true);
if (platformString != null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
return root.getFile(new Path(platformString));
}
}
return null;
}
示例2: FlexExistingDeployArtifactStagingDelegate
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
public FlexExistingDeployArtifactStagingDelegate(IPath deployArtifact, IPath appEngineDirectory) {
super(appEngineDirectory);
Preconditions.checkNotNull(deployArtifact);
Preconditions.checkArgument(!deployArtifact.isEmpty());
Preconditions.checkArgument(deployArtifact.isAbsolute());
Preconditions.checkArgument(appEngineDirectory.isAbsolute());
this.deployArtifact = deployArtifact;
// Compute SchedulingRule; will be the artifact itself, if inside the workspace.
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
if (workspaceRoot.getLocation().isPrefixOf(deployArtifact)) {
IPath relativeToWorkspace = deployArtifact.makeRelativeTo(workspaceRoot.getLocation());
schedulingRule = workspaceRoot.getFile(relativeToWorkspace);
} else {
schedulingRule = null; // Outside the workspace; we can't lock it.
}
}
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-eclipse,代碼行數:18,代碼來源:FlexExistingDeployArtifactStagingDelegate.java
示例3: createFileInPath
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
public static File createFileInPath(String fileName, IPath path){
path = path.append(fileName);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IFile outputFile = workspaceRoot.getFile(path);
File file = new File(outputFile.getLocationURI());
if(!file.exists())
try {
if(!file.createNewFile()){
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
return file;
}
示例4: getSelectedOuputFileLocation
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Return the passed parameters (a folder and a file) as an absolute OS path
* file
*
* @param containerFullPath
* @param filename
* @return
*/
public static String getSelectedOuputFileLocation(IPath path, String filename) {
IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
IFile resource = wroot.getFile(path);
String location = resource.getRawLocation().makeAbsolute().toString();
File targetDir = new File(location);
String outputFileName = new File(targetDir, filename).getAbsolutePath();
return outputFileName;
}
示例5: getContents
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Returns the content of the given buffer.
*
* @param buffer
* @return the content of the given buffer.
* @throws CoreException
*/
private static InputStream getContents(ITextFileBuffer buffer) throws CoreException {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IFile file = workspaceRoot.getFile(buffer.getLocation());
if (file.exists() && buffer.isSynchronized()) {
return file.getContents();
}
return buffer.getFileStore().openInputStream(EFS.NONE, null);
}
示例6: getFileForURI
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Returns the file that corresponds to the given URI. If the URI does not
* correspond to a file (e.g., because it is not a platform URI or because it is
* <code>null</code>), <code>null</code> is returned.
*/
public IFile getFileForURI(URI uri) {
if (uri == null) {
return null;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
String platformString = uri.toPlatformString(true);
// If the URI is not a platform URI, we cannot determine the file.
if (platformString == null) {
return null;
}
Path path = new Path(platformString);
return workspaceRoot.getFile(path);
}
示例7: getFile
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Returns the owner file of the SSE model {@link IStructuredModel}.
*
* @param node
* the SSE model.
* @return
*/
public static final IFile getFile(IStructuredModel model) {
String baselocation = model.getBaseLocation();
if (baselocation != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath filePath = new Path(baselocation);
if (filePath.segmentCount() > 1) {
return root.getFile(filePath);
}
}
return null;
}
示例8: getFile
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
static IFile getFile(String filePath) {
IPath path = new Path(filePath);
if (path.segmentCount() > 1) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = root.getFile(path);
if (file != null && file.exists()) {
return file;
}
}
return null;
}
示例9: createFolderInPathFromCurrentOpenEditorFile
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
public static IPath createFolderInPathFromCurrentOpenEditorFile(String name){
IPath path = getPathFromCurrentOpenEditorFile();
path = path.append(name);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IFile file = workspaceRoot.getFile(path);
File oFile = new File(file.getLocationURI());
if(!oFile.mkdir()){
}
return path;
}
示例10: openEditorForFileExtension
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Opens the default editor for the given file extension side by side with the currently
* active editor
* @param File extension
*/
public void openEditorForFileExtension(String fileExtension){
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath path = getPathToEditorRelatedFileWithFileExtension(fileExtension);
// only open editor if a file exist with the same name as the feature model in same directory
if(workspaceRoot.exists(path)){
IFile constraintFile = workspaceRoot.getFile(path);
IEditorDescriptor desc = PlatformUI.getWorkbench().
getEditorRegistry().getDefaultEditor(constraintFile.getName());
if(desc == null){
System.err.println("No editor for file extension "+fileExtension+" exist");
return;
}
try {
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = workbenchPage.openEditor(new FileEditorInput(constraintFile), desc.getId());
MPart constraintEditorPart = editor.getSite().getService(MPart.class);
MPart editorPart = this.getSite().getService(MPart.class);
if (editorPart == null) {
return;
}
insertEditor(0.3f, EModelService.RIGHT_OF, editorPart, constraintEditorPart);
} catch (PartInitException e) {
e.printStackTrace();
}
}
}
示例11: absoluteEmfResourceToWorkspaceRelativeIResource
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* converts an absolute EMF Resource to a workspace relative Eclipse IResource.
*
* @param emfResource
* : C:\Workspace\Project\Model\model.abc
* @return : L/Project/Model/model.abc
*/
public static IResource absoluteEmfResourceToWorkspaceRelativeIResource(final Resource emfResource) {
final URI uri = emfResource.getURI();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot root = workspace.getRoot();
final String fileString = uri.toFileString();
final String rootString = root.getLocation().toString();
final String relativeString = fileString.substring(rootString.length());
final IResource iResource = root.getFile(new Path(relativeString));
return iResource;
}
示例12: saveLayout
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Saves all positions for each feature of the selected feature model into a layout file.
* The file has the same name as the feature model (with "*.hylaout" file extension) and the
* same directory as the feature model. The generated text file is layouted as follows:
* Each line marks a position (line separation with \n). Each of these lines contains of
* feature id, since date, until date, position. All values are separated by a comma.
*
* @param featureModel
*/
public static void saveLayout(DwFeatureModelWrapped featureModel){
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IFile file = workspaceRoot.getFile(new Path(featureModel.getModel().eResource().getURI().toPlatformString(true)));
IPath path = ((IPath)file.getFullPath().clone()).removeFileExtension().addFileExtension("hylayout");
String fileContent = "";
for(DwFeatureWrapped featureWrapped : featureModel.getFeatures(null)){
DwTemporalPosition position = featureWrapped.getFirstPosition();
do{
fileContent += featureWrapped.getWrappedModelElement().getId()+","+
(position.getValidSince() != null ? dateFormat.format(position.getValidSince()) : "null")+","+
(position.getValidUntil() != null ? dateFormat.format(position.getValidUntil()) : "null")+","+
position.getPosition().x()+","+
position.getPosition().y()+"\n";
position = position.getSuccessor();
}while(position != null);
}
file = workspaceRoot.getFile(path);
InputStream source = new ByteArrayInputStream(fileContent.getBytes());
try {
if(!file.exists()){
file.create(source, IResource.NONE, null);
}else{
file.setContents(source, IResource.FORCE, null);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
示例13: openConfigurationViewer
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
protected void openConfigurationViewer(String name){
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IFile file = workspaceRoot.getFile(Path.fromOSString(name));
workbench.getDisplay().syncExec(new Runnable(){
@Override
public void run() {
IEditorDescriptor desc = PlatformUI.getWorkbench().
getEditorRegistry().getDefaultEditor(name);
try {
workbenchPage.openEditor(new FileEditorInput(file), desc.getId());
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
示例14: getResourceFor
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Returns workspace resource for the given local file system <code>location</code>
* and which is a child of the given <code>parent</code> resource. Returns
* <code>parent</code> if parent's file system location equals to the given
* <code>location</code>. Returns <code>null</code> if <code>parent</code> is the
* workspace root.
*
* Resource does not have to exist in the workspace in which case resource
* type will be determined by the type of the local filesystem object.
*/
public static IResource getResourceFor(IResource parent, IPath location) {
if (parent == null || location == null) {
return null;
}
if (parent instanceof IWorkspaceRoot) {
return null;
}
if (!isManagedBySubclipse(parent.getProject())) {
return null;
}
if (!parent.getLocation().isPrefixOf(location)) {
return null;
}
int segmentsToRemove = parent.getLocation().segmentCount();
IPath fullPath = parent.getFullPath().append(location.removeFirstSegments(segmentsToRemove));
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(fullPath,true);
if (resource != null) {
return resource;
}
if (parent instanceof IFile) {
return null;
}
if (fullPath.isRoot()) {
return root;
} else if (fullPath.segmentCount() == 1) {
return root.getProject(fullPath.segment(0));
}
if (!location.toFile().exists()) {
if (location.toFile().getName().indexOf(".") == -1) {
return root.getFolder(fullPath);
}
}
if (location.toFile().isDirectory()) {
return root.getFolder(fullPath);
}
return root.getFile(fullPath);
}
示例15: toIResource
import org.eclipse.core.resources.IWorkspaceRoot; //導入方法依賴的package包/類
/**
* Returns the equivalent {@linkplain org.eclipse.core.resources.IResource
* Eclipse IResource} for an {@linkplain org.eclipse.emf.common.util.URI Ecore
* URI}, if available.
*
* <p>
* {@code uri} can be represented as IResource if {@code uri} is an
* {@linkplain URI#isPlatformResource() platform resource} (i.e. {@code uri}
* starts with {@code platform:/resource/}). Otherwise, this method returns
* {@code null}.
* </p>
*
* <p>
* This method ignores any {@linkplain URI#fragment() fragment} or
* {@linkplain URI#query() query} of {@code uri}.
* </p>
*
* <p>
* If the resulting IResource exists, this method returns the existing kind of
* IResource ({@linkplain org.eclipse.core.resources.IWorkspaceRoot
* IWorkspaceRoot}, {@linkplain org.eclipse.core.resources.IProject IProject},
* {@linkplain org.eclipse.core.resources.IFolder IFolder}, or
* {@linkplain org.eclipse.core.resources.IFile IFile}).
* </p>
*
* <p>
* If the resulting IResource does not exist, this method returns an IFile
* pointing to the place equivalent to {@code uri}.
* </p>
*
* <p>
* This method handles excess slashes (behind the platform resource identifiers)
* gracefully (i.e. ignores the slashes).<br/>
* Example: An URI of
* {@code platform:/resource/////MyProject///folder///deep/myFile.ext//} leads
* to an IFile for path {@code /MyProject/folder/deep/myFile.ext}.
* </p>
*
* <p>
* <b>Note:</b> This method treats {@code uri} as case-sensitive (on <i>all</i>
* platforms, including Windows). Therefore, if the workspace contained a file
* at {@code /MyProject/myFolder/myFile.ext} and we passed the URI
* {@code platform:/resource/MyProject/myFolder/mYfILE.ext} to this method, the
* result is an IFile for path {@code /MyProject/myFolder/mYfILE.ext}.
* {@link IResource#exists() result.exists()} will return {@code false}.
* </p>
*
* @param uri
* The Ecore URI to return as Eclipse IResource.
* @return {@code uri} as Eclipse IResource, if available; {@code null}
* otherwise.
*
* @throws IllegalArgumentException
* If {@code uri} is seriously ill-formatted.
*
* @since 0.1
*/
public static @Nullable IResource toIResource(final @NonNull URI uri) {
if (uri.isPlatformResource()) {
String platformString = uri.toPlatformString(true);
IPath path = Path.fromOSString(platformString);
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
if (workspaceRoot.exists(path)) {
return workspaceRoot.findMember(path);
} else {
return workspaceRoot.getFile(path);
}
}
return null;
}