Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Obtaining project info in a Wizard
Obtaining project info in a Wizard [message #169355] Tue, 09 May 2006 15:14 Go to next message
Eclipse UserFriend
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 #169392 is a reply to message #169355] Wed, 10 May 2006 12:38 Go to previous messageGo to next message
Anton Leherbauer is currently offline Anton LeherbauerFriend
Messages: 490
Registered: July 2009
Senior Member
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
Re: Obtaining project info in a Wizard [message #169419 is a reply to message #169392] Thu, 11 May 2006 14:15 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Obtaining project info in a Wizard [message #169551 is a reply to message #169419] Mon, 15 May 2006 06:30 Go to previous message
Anton Leherbauer is currently offline Anton LeherbauerFriend
Messages: 490
Registered: July 2009
Senior Member
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
Previous Topic:CDT with VC7
Next Topic:Indexer in CDT3.1
Goto Forum:
  


Current Time: Wed Jan 15 09:41:45 GMT 2025

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

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

Back to the top