Obtaining project info in a Wizard [message #169355] |
Tue, 09 May 2006 11:14  |
Eclipse User |
|
|
|
Originally posted by: dmsubs._nospam_consertum.com
Hi,
I'm creating a wizard that inserts code into an existing project/source
file. The appropiate project/source file is selected before starting the
wizard. When the wizard starts, I get an ISelection passed in, which I
am using like this (which came from the plugin wizard):
if (selection != null && selection.isEmpty() == false
&& selection instanceof IStructuredSelection) {
IStructuredSelection ssel = (IStructuredSelection) selection;
if (ssel.size() > 1)
return;
Object obj = ssel.getFirstElement();
if (obj instanceof IResource)
{
IContainer project;
if (obj instanceof IContainer)
project = (IContainer) obj;
else
project = ((IResource) obj).getParent();
projectText.setText(project.getFullPath().toString());
}
}
However, the IResource is of type CProject.
How do I access the CProject from within the wizard?
Thanks,
---
Derek
|
|
|
|
|
Re: Obtaining project info in a Wizard [message #169551 is a reply to message #169419] |
Mon, 15 May 2006 02:30  |
Eclipse User |
|
|
|
You should not use class CProject directly because it's
an internal implementation class. Use interface ICProject
instead (package org.eclipse.cdt.core.model).
This is the public API of CProject.
Toni
Derek Morris wrote:
> That's helpful.
>
> Follow on question - where can I import a CProject from?
>
> --
> Derek
>
> Anton Leherbauer wrote:
>> CProject is an IAdaptable (as are all ICElements) and
>> you can adapt it to a IResource, e.g.
>>
>> [...]
>> IResource resource = null;
>> Object obj = ssel.getFirstElement();
>> if (obj instanceof IResource) {
>> resource = (IResource) obj;
>> } else if (obj instanceof IAdaptable) {
>> IAdaptable adapable = (IAdaptable) obj;
>> resource = (IResource) adaptable.getAdapter(IResource.class);
>> }
>> if (resource != null) {
>> [...]
>>
>> HTH,
>> Toni
>>
>> Derek wrote:
>>> Hi,
>>>
>>> I'm creating a wizard that inserts code into an existing
>>> project/source file. The appropiate project/source file is selected
>>> before starting the wizard. When the wizard starts, I get an
>>> ISelection passed in, which I am using like this (which came from the
>>> plugin wizard):
>>>
>>> if (selection != null && selection.isEmpty() == false
>>> && selection instanceof IStructuredSelection) {
>>> IStructuredSelection ssel = (IStructuredSelection) selection;
>>> if (ssel.size() > 1)
>>> return;
>>> Object obj = ssel.getFirstElement();
>>> if (obj instanceof IResource)
>>> {
>>> IContainer project;
>>> if (obj instanceof IContainer)
>>> project = (IContainer) obj;
>>> else
>>> project = ((IResource) obj).getParent();
>>> projectText.setText(project.getFullPath().toString());
>>> }
>>> }
>>>
>>> However, the IResource is of type CProject.
>>>
>>> How do I access the CProject from within the wizard?
>>>
>>> Thanks,
>>>
>>> ---
>>> Derek
|
|
|
Powered by
FUDForum. Page generated in 0.10495 seconds