Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » IFile from EMF Resource
IFile from EMF Resource [message #397092] Fri, 02 December 2005 10:52 Go to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Hi,
Re: IFile from EMF Resource [message #397093 is a reply to message #397092] Fri, 02 December 2005 10:58 Go to previous messageGo to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
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.
Re: IFile from EMF Resource [message #397097 is a reply to message #397093] Fri, 02 December 2005 11:24 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:XMLMerge?
Next Topic:UML Graphical Entry Plug-in and XMI export
Goto Forum:
  


Current Time: Fri Apr 26 01:09:26 GMT 2024

Powered by FUDForum. Page generated in 0.03577 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top