Handle to Project [message #726051] |
Fri, 16 September 2011 09:24  |
Eclipse User |
|
|
|
I am writing a RelativePathService, I want to return all the Java source
paths that is available for the project as roots for searching the file
that will be assigned o the property having the RelativePathService.
Can anyone tell me how to do this ?
Also in the same scenario,
What is the best way to convert "/" to "." during serialization do we need
to do CustomXmlValueBinding ?
~ Kamesh
|
|
|
|
Re: Handle to Project [message #726090 is a reply to message #726068] |
Fri, 16 September 2011 10:30   |
Eclipse User |
|
|
|
Thanks Konstantin. No not java Types, Actually I am trying to browse for
Resource Bundles (*.properties) that is available in the classpath.
Also when I saw your reply for getting IProject , am now forced to ask me a
long standing query, how to do I access the model element inside the Service
classes or any other place ?
~Kamesh
~ Kamesh
"Konstantin Komissarchik" wrote in message
news:j4vjj9$v7l$1@news.eclipse.org...
> I am writing a RelativePathService, I want to return all the Java source
> paths that is available for the project as roots for searching the file
> that will be assigned o the property having the RelativePathService.
IProject proj = element.adapt( IProject.class );
IJavaProject jproj = JavaCore.create( proj );
for( IClasspathEntry entry : jproj.getRawClasspath() )
{
...
}
> What is the best way to convert "/" to "." during serialization do we need
> to do CustomXmlValueBinding ?
If you want the text box to show dots, but have slashes written to file,
then you need to write a custom binding. If you'd rather see dots in the
text box as well, but the problem is that the browse dialog is returning
slashes, see RelativePathService.convertToRelative/convertToAbsolute API.
I am assuming that you aren't trying to do this to browse for Java types, as
the framework has built-in support for that that is better than trying to
use RelativePathService.
- Konstantin
|
|
|
|
Re: Handle to Project [message #726105 is a reply to message #726090] |
Fri, 16 September 2011 11:14   |
Eclipse User |
|
|
|
I found the way the Service class provides the adapt() method which can be
used to make it to adapt to IProject :)
So let me rephrase my question what is the general way to get model element
if I I have,
1. ModelElementType
2.ModelProperty
~ Kamesh
"Kamesh Sampath" wrote in message news:j4vld6$1p2$1@news.eclipse.org...
Thanks Konstantin. No not java Types, Actually I am trying to browse for
Resource Bundles (*.properties) that is available in the classpath.
Also when I saw your reply for getting IProject , am now forced to ask me a
long standing query, how to do I access the model element inside the Service
classes or any other place ?
~Kamesh
~ Kamesh
"Konstantin Komissarchik" wrote in message
news:j4vjj9$v7l$1@news.eclipse.org...
> I am writing a RelativePathService, I want to return all the Java source
> paths that is available for the project as roots for searching the file
> that will be assigned o the property having the RelativePathService.
IProject proj = element.adapt( IProject.class );
IJavaProject jproj = JavaCore.create( proj );
for( IClasspathEntry entry : jproj.getRawClasspath() )
{
...
}
> What is the best way to convert "/" to "." during serialization do we need
> to do CustomXmlValueBinding ?
If you want the text box to show dots, but have slashes written to file,
then you need to write a custom binding. If you'd rather see dots in the
text box as well, but the problem is that the browse dialog is returning
slashes, see RelativePathService.convertToRelative/convertToAbsolute API.
I am assuming that you aren't trying to do this to browse for Java types, as
the framework has built-in support for that that is better than trying to
use RelativePathService.
- Konstantin
|
|
|
|
Re: Handle to Project [message #726207 is a reply to message #726105] |
Fri, 16 September 2011 15:20   |
Eclipse User |
|
|
|
"IProject proj = element.adapt( IProject.class );
IJavaProject jproj = JavaCore.create( proj );
for( IClasspathEntry entry : jproj.getRawClasspath() )
{
...
}"
Based on the above logic I wrote the the logic to make the roots as follows,
ProjectRelativePathService
.....
roots.add( new Path(iClasspathEntry.getPath() ).toPortableString() ));
.....
and my model property definition
// *** ResourceBundle ***
@Type( base = Path.class )
@MustExist
@ValidFileSystemResourceType( FileSystemResourceType.FILE )
@Service( impl = ProjectRelativePathService.class )
@FileExtensions( expr = "properties" )
ValueProperty PROP_RESOURCE_BUNDLE = new ValueProperty( TYPE,
"ResourceBundle" );
Value<Path> getResourceBundle();
void setResourceBundle( String value );
void setResourceBundle( Path value );
When I run my editor, and click on the browse I see just text for the
classpath entries and no file or folders displayed, but it has files and
folders + filters for .properties file. Not sure what mistake am making.
I also tried doing the following way but same result,
for ( IClasspathEntry iClasspathEntry : cpEntries ) {
if ( IClasspathEntry.CPE_SOURCE ==
iClasspathEntry.getEntryKind() ) {
IPath projectPath =
ResourcesPlugin.getWorkspace().getRoot().getLocation();
System.out.println( "Portable String" +
projectPath.append(
iClasspathEntry.getPath() ).toPortableString() );
File file = new File( projectPath.append(
iClasspathEntry.getPath() ).toPortableString() );
roots.add( new Path( file.getAbsolutePath() ) );
}
}
Can you please clarify what mistake am making ??
~ Kamesh
"Kamesh Sampath" wrote in message news:j4vo4d$4js$1@news.eclipse.org...
I found the way the Service class provides the adapt() method which can be
used to make it to adapt to IProject :)
So let me rephrase my question what is the general way to get model element
if I I have,
1. ModelElementType
2.ModelProperty
~ Kamesh
"Kamesh Sampath" wrote in message news:j4vld6$1p2$1@news.eclipse.org...
Thanks Konstantin. No not java Types, Actually I am trying to browse for
Resource Bundles (*.properties) that is available in the classpath.
Also when I saw your reply for getting IProject , am now forced to ask me a
long standing query, how to do I access the model element inside the Service
classes or any other place ?
~Kamesh
~ Kamesh
"Konstantin Komissarchik" wrote in message
news:j4vjj9$v7l$1@news.eclipse.org...
> I am writing a RelativePathService, I want to return all the Java source
> paths that is available for the project as roots for searching the file
> that will be assigned o the property having the RelativePathService.
IProject proj = element.adapt( IProject.class );
IJavaProject jproj = JavaCore.create( proj );
for( IClasspathEntry entry : jproj.getRawClasspath() )
{
...
}
> What is the best way to convert "/" to "." during serialization do we need
> to do CustomXmlValueBinding ?
If you want the text box to show dots, but have slashes written to file,
then you need to write a custom binding. If you'd rather see dots in the
text box as well, but the problem is that the browse dialog is returning
slashes, see RelativePathService.convertToRelative/convertToAbsolute API.
I am assuming that you aren't trying to do this to browse for Java types, as
the framework has built-in support for that that is better than trying to
use RelativePathService.
- Konstantin
|
|
|
|
|
|
|
Re: Handle to Project [message #726309 is a reply to message #726219] |
Sat, 17 September 2011 03:40  |
Eclipse User |
|
|
|
<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>I am not sure what is the reason - My project was WebProject, as you
said the ClasspathEntry was not returning the absolute path, hence I resorted
your suggestion of using Workspace API and did as follows,</DIV>
<DIV> </DIV>
<DIV></DIV>
<DIV>for ( IClasspathEntry iClasspathEntry : cpEntries ) {</DIV>
<DIV>
if ( IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind() ) {</DIV>
<DIV>
IWorkspace workspace = ResourcesPlugin.getWorkspace();</DIV>
<DIV>
IWorkspaceRoot wroot = workspace.getRoot();</DIV>
<DIV>
IPath entryPath = wroot.getFolder( iClasspathEntry.getPath()
).getLocation();</DIV>
<DIV>
roots.add( new Path( entryPath.toPortableString() ) );</DIV>
<DIV>
}</DIV>
<DIV> }</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>After this I was able to get all my folders for browsing and filtered by my
@FilterExtensions.</DIV>
<DIV> </DIV>
<DIV>~ Kamesh</DIV>
<DIV> </DIV>
<DIV>"Konstantin Komissarchik" wrote in message
news:j50anj$ocm$1@news.eclipse.org... </DIV>
<DIV> </DIV>
<DIV>> roots.add( new Path(iClasspathEntry.getPath() ).toPortableString()
));</DIV>
<DIV> </DIV>
<DIV>Unless your project setup is very unusual, this will not produce absolute
paths that are required for roots. More like "/proj/src". You will need to
convert this path to an IFolder using IWorkspace API then call getLocation() on
IFolder to produce an absolute path that's required.</DIV>
<DIV> </DIV>
<DIV>- Konstantin</DIV></DIV></DIV></BODY></HTML>
|
|
|
Powered by
FUDForum. Page generated in 0.06571 seconds