views:

807

answers:

1

I want to modify an Eclipse workspace programatically from within a plugin (adding existing projects is my main request). Also I want to modify CDT options (environment, indexer options) from within that plugin.

Does anyone know how to best do this or can point me to good documentations on that topic?

EDIT: Actually I don't want to modify CDT project settings but some of the global CDT settings (actually I want to disable the indexer).

+1  A: 

It depends the kind of modification you are after.

For instance, adding a project is best illustrated by this thread.

String theProjName = "Test";
String theLocation = "/some/test/project";

try {
    IWorkspaceRoot theRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject theProject = theRoot.getProject(theProjName);
    IProjectDescription theDesc =       theProject.getWorkspace().newProjectDescription(theProjName);
        theDesc.setLocation(new Path(theLocation));
    theProject.create(theDesc, new NullProgressMonitor());
    if (theProject.exists()) {
        theProject.open(new NullProgressMonitor());
    }
} catch (CoreException err) {
    err.printStackTrace();
}

You could also want to open an editor:

IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
   if (dw != null) {
   IWorkbenchPage page = dw.getActivePage();
   if (page != null) {
    IDE.openEditor(page, file, true);        
   }
}
} catch (PartInitException e) {

}

More generally, eclipse.dev.org can be a good source for pointers on that topic.


Since 2004, CDT has options you can modify through the Preference Setting Store (ICSettingsStorage). May be that can help.


Regarding the Indexer, beware of the Discovery Preferences.
I am not sure there is an Indexer API, but you may look at the sources for further clues.

VonC
Is it possible to mark answers as "half solutions"? Because your answer is good but I also need the CDT options part. But maybe I could remove the CDT part from my question and make a new one :-)Do you see any chance you could add the CDT stuff?
rstevens
@rstevens: The details are a bit foggy but one way to setup the CDT project settings is to create a New Project Wizard which extends the CDT one and add additional settings to the new CDT project (which could be importing existing projects into workspace I think). It can be a bit tricky to get everything in place though, it's been a while since I did something like that. If you want to edit/change the settings dynamically in the plug-in I suggest you extend the CDT preference page or something like that. It would probably give you access to the settings.
Subtwo
@rstevens: Sorry about the vague description but it's been a while and I'm not entirely sure what you're main objective is.
Subtwo
@rstevens: I will check the CDT part later today, but for now, my answer should certainly not be "selected" ;) May be someone will have a more complete post later on today.
VonC
rstevens