Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Project settings
Project settings [message #329183] Mon, 16 June 2008 15:23 Go to next message
Eclipse UserFriend
Originally posted by: ali.akar.geensys.com

Hi all,

I have a project with a nature. I want from my project creation wizard
to set the release version of my project. so, I added an
org.eclipse.swt.widget.Group that hold a Combo to select the version.

My Question is how can I write this setting in the poject/.settings ??
Which API ??

best regard's,
Re: Project settings [message #329196 is a reply to message #329183] Mon, 16 June 2008 16:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Ali Akar wrote:
> Hi all,
>
> I have a project with a nature. I want from my project creation wizard
> to set the release version of my project. so, I added an
> org.eclipse.swt.widget.Group that hold a Combo to select the version.
>
> My Question is how can I write this setting in the poject/.settings ??
> Which API ??

You can just get the IProject and call IProject.getFolder(".settings")
to get an IFolder. Then call IFolder.getFile(yourFileName) to get an
IFile reference. You probably want to make sure the IFolder exists and
create it if not, since not all projects have a .settings folder.
Once you have an IFile it is easy to use streams to read/write it.

You might want to encapsulate all of this in a class to make storing
things in your own .settings file easy.

Hope this helps,
Eric
Re: Project settings [message #329207 is a reply to message #329196] Mon, 16 June 2008 17:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ali.akar.geensys.com

Thanks for your answer,

I think by using a special API the task will be easier. There is a Class
named ProjectPreferences but I don't know how Eclipse use it to save
preference keys and values ? do you have any example ??

regards,

Eric Rizzo a écrit :
> Ali Akar wrote:
>> Hi all,
>>
>> I have a project with a nature. I want from my project creation wizard
>> to set the release version of my project. so, I added an
>> org.eclipse.swt.widget.Group that hold a Combo to select the version.
>>
>> My Question is how can I write this setting in the poject/.settings ??
>> Which API ??
>
> You can just get the IProject and call IProject.getFolder(".settings")
> to get an IFolder. Then call IFolder.getFile(yourFileName) to get an
> IFile reference. You probably want to make sure the IFolder exists and
> create it if not, since not all projects have a .settings folder.
> Once you have an IFile it is easy to use streams to read/write it.
>
> You might want to encapsulate all of this in a class to make storing
> things in your own .settings file easy.
>
> Hope this helps,
> Eric
Re: Project settings [message #329226 is a reply to message #329207] Mon, 16 June 2008 21:28 Go to previous message
Mark Melvin is currently offline Mark MelvinFriend
Messages: 118
Registered: July 2009
Senior Member
Hi Ali,

You are on the right track. Search for ProjectPreferences in the Eclipse
Online Help. Here is the blurb from that page:

--8<--

Project-scoped preference nodes
Since the project scope for preferences is not one of the standard runtime
scopes, the node representing a project-level preference must be obtained
specifically. From the root preference node, you must navigate to the
project-scoped preference. This can be achieved using the ProjectScope:

IScopeContext projectScope = new ProjectScope(MyProject);

Once the project scope for a particular is project is found, the
preference values can be obtained using the same mechanisms seen earlier.
Preferences are named using the string name of the preference. The names
are qualified with another string (often a plug-in id) that qualifies the
namespace of the preference. The following snippet gets a preference node
from the project scope. You'll notice that once the correct scope is
obtained, working with the nodes is no different than with nodes from
other scopes.

...
Preferences projectNode = projectScope.getNode("com.example.myplugin");
if (projectNode != null) {
value = projectNode.getBoolean("MyPreference", "true");
//do something with the value.
}
...

To save the value to a file in the project, the node is flushed. The
resources plug-in handles the logistics for managing the project-level
preferences file.

projectNode.flush();

--8<--

The above code will create a file called "com.example.myplugin.prefs" in
the .settings folder. You can call this whatever you want, but it will
have the .prefs extension.
There is more information available in the help under Platform Plug-in
Developer Guide > Programmer's Guide > Runtime overview > Runtime
Preferences.

Hope this helps,
Mark.


On Mon, 16 Jun 2008 13:09:08 -0400, Ali Akar <ali.akar@geensys.com> wrote:

> Thanks for your answer,
>
> I think by using a special API the task will be easier. There is a Class
> named ProjectPreferences but I don't know how Eclipse use it to save
> preference keys and values ? do you have any example ??
>
> regards,
>
> Eric Rizzo a écrit :
>> Ali Akar wrote:
>>> Hi all,
>>>
>>> I have a project with a nature. I want from my project creation wizard
>>> to set the release version of my project. so, I added an
>>> org.eclipse.swt.widget.Group that hold a Combo to select the version.
>>>
>>> My Question is how can I write this setting in the poject/.settings ??
>>> Which API ??
>> You can just get the IProject and call IProject.getFolder(".settings")
>> to get an IFolder. Then call IFolder.getFile(yourFileName) to get an
>> IFile reference. You probably want to make sure the IFolder exists and
>> create it if not, since not all projects have a .settings folder.
>> Once you have an IFile it is easy to use streams to read/write it.
>> You might want to encapsulate all of this in a class to make storing
>> things in your own .settings file easy.
>> Hope this helps,
>> Eric
Previous Topic:Update jars of "Plug-in for existing Jar archives"
Next Topic:How to get parent item for any subitem in Package Explorer?
Goto Forum:
  


Current Time: Fri Aug 23 08:22:07 GMT 2024

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

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

Back to the top