|
|
Re: IFile from EMF Resource [message #397097 is a reply to message #397093] |
Fri, 02 December 2005 11:24 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------030404060008020301020302
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
JF,
Here's how we do it in ValidateAction when we want to put markers on the
IFile:
protected IFile getFile()
{
Resource resource =
(Resource)domain.getResourceSet().getResources().get(0);
if (resource != null)
{
URI uri = resource.getURI();
uri = resource.getResourceSet().getURIConverter().normalize(uri);
String scheme = uri.scheme();
if ("platform".equals(scheme) && uri.segmentCount() > 1 &&
"resource".equals(uri.segment(0)))
{
StringBuffer platformResourcePath = new StringBuffer();
for (int j = 1, size = uri.segmentCount(); j < size; ++j)
{
platformResourcePath.append('/');
platformResourcePath.append(uri.segment(j));
}
return ResourcesPlugin.getWorkspace().getRoot().getFile(new
Path(platformResourcePath.toString()));
}
}
return null;
}
JF wrote:
> Hi,
>
> I have a EMF Resource and wish to convert it into an IFile.
>
> In the following example the file already exists and I have been
> editing the EMF Resource. However it would appear that the Eclipse
> Workspace does not understand the platform relative URI which it is
> given and the file is deemed not to exist.
>
> What am I doing wrong?
>
> Resource res.....
>
> URI uri = res.getURI();
> IPath path = new Path(uri.toString()); //Can't call
> uri.toFileString(); //as its a
> platform:// URI
> IFile file = MyResPlugin.getWorkspace().getRoot().getFile(path);
> if(file.exists)
> {
> //it doesn't - although I created res from a file.
>
--------------030404060008020301020302
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
JF,<br>
<br>
Here's how we do it in ValidateAction when we want to put markers on
the IFile:<br>
<blockquote><small>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03577 seconds