Obtaining project info in a Wizard [message #169355] |
Tue, 09 May 2006 15: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 #169419 is a reply to message #169392] |
Thu, 11 May 2006 14:15 |
Eclipse User |
|
|
|
Originally posted by: dmsubs._nospam_consertum.com
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.02942 seconds