Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » get my current project object.
get my current project object. [message #193450] Mon, 18 June 2007 06:03 Go to next message
Eclipse UserFriend
Originally posted by: oren_b1.verifone.com

Hello,

How can I get the project object of the currently opened project on eclipse?

Thanks

Oren.
Re: get my current project object. [message #193505 is a reply to message #193450] Mon, 18 June 2007 23:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nzhong.amazon.com

I am not sure of a generic way. When I need to get hold of the project
object when developing a plug-in, the extension points's interface method
passes an ICProject parameter to me.

"oren barzilai" <oren_b1@verifone.com> wrote in message
news:f55l9b$ne8$1@build.eclipse.org...
> Hello,
>
> How can I get the project object of the currently opened project on
> eclipse?
>
> Thanks
>
> Oren.
>
Re: get my current project object. [message #193535 is a reply to message #193505] Tue, 19 June 2007 04:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: oren_b1.verifone.com

I can get hold on my project obj during creation process, But after I
restart the eclipse I can't find a way to get hold on my project object
again.

Let's say that currently there is 2 open projects on my workspace, I need a
method like "getCurrentlyActiveProject()" I can't think of any other way
because I don't know on which project the user is currently working on, I
don't even know the project's name.

Any idea? anyone?

"Nan Zhong" <nzhong@amazon.com> wrote in message
news:f57k7t$if4$1@build.eclipse.org...

>I am not sure of a generic way. When I need to get hold of the project
>object when developing a plug-in, the extension points's interface method
>passes an ICProject parameter to me.
>
> "oren barzilai" <oren_b1@verifone.com> wrote in message
> news:f55l9b$ne8$1@build.eclipse.org...
>> Hello,
>>
>> How can I get the project object of the currently opened project on
>> eclipse?
>>
>> Thanks
>>
>> Oren.
>>
>
>
Re: get my current project object. [message #193569 is a reply to message #193535] Tue, 19 June 2007 14:32 Go to previous messageGo to next message
Eclipse UserFriend
oren barzilai wrote:
> I can get hold on my project obj during creation process, But after I
> restart the eclipse I can't find a way to get hold on my project object
> again.
>
> Let's say that currently there is 2 open projects on my workspace, I need a
> method like "getCurrentlyActiveProject()" I can't think of any other way
> because I don't know on which project the user is currently working on, I
> don't even know the project's name.
>
> Any idea? anyone?

You can get the currently selected one, but that will only tell you when
one is actually selected. It's possible to be logically working in a
project (e.g. editing a file) without actually having the project
selected in the project explorer. Without knowing what you are doing I
can't comment as to whether this heuristic (selection) works for your
situation or not, or if there is more to your workflow.

===========================

Chris Recoskie
Team Lead, IBM CDT Team
IBM Toronto
http://www.eclipse.org/cdt
Re: get my current project object. [message #193800 is a reply to message #193569] Fri, 22 June 2007 04:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dmsubs.NOSPAM.consertum.com

You can get the currently selected IResource, and from that you can get the project:

private IContainer getProject(IResource resource) {
IContainer container = null;
if (resource != null) {
int type = resource.getType();
switch (type) {
case IResource.FILE :
container = resource.getParent();
break;
case IResource.FOLDER :
container = resource.getProject();
break;
case IResource.PROJECT :
container = (IContainer) resource;
break;
case IResource.ROOT :
break;
}
}
return container;
}

--
Derek


Chris Recoskie wrote:
> oren barzilai wrote:
>> I can get hold on my project obj during creation process, But after I
>> restart the eclipse I can't find a way to get hold on my project
>> object again.
>>
>> Let's say that currently there is 2 open projects on my workspace, I
>> need a method like "getCurrentlyActiveProject()" I can't think of any
>> other way because I don't know on which project the user is currently
>> working on, I don't even know the project's name.
>>
>> Any idea? anyone?
>
> You can get the currently selected one, but that will only tell you when
> one is actually selected. It's possible to be logically working in a
> project (e.g. editing a file) without actually having the project
> selected in the project explorer. Without knowing what you are doing I
> can't comment as to whether this heuristic (selection) works for your
> situation or not, or if there is more to your workflow.
>
> ===========================
>
> Chris Recoskie
> Team Lead, IBM CDT Team
> IBM Toronto
> http://www.eclipse.org/cdt
Re: get my current project object. [message #193913 is a reply to message #193800] Mon, 25 June 2007 10:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: oren_b1.verifone.com

But how do I get the currently selected resource?


"Derek Morris" <dmsubs@NOSPAM.consertum.com> wrote in message
news:f5fvkf$tdq$1@build.eclipse.org...
> You can get the currently selected IResource, and from that you can get
> the project:
>
> private IContainer getProject(IResource resource) {
> IContainer container = null;
> if (resource != null) {
> int type = resource.getType();
> switch (type) {
> case IResource.FILE :
> container = resource.getParent();
> break;
> case IResource.FOLDER :
> container = resource.getProject();
> break;
> case IResource.PROJECT :
> container = (IContainer) resource;
> break;
> case IResource.ROOT :
> break;
> }
> }
> return container;
> }
>
> --
> Derek
>
>
> Chris Recoskie wrote:
>> oren barzilai wrote:
>>> I can get hold on my project obj during creation process, But after I
>>> restart the eclipse I can't find a way to get hold on my project object
>>> again.
>>>
>>> Let's say that currently there is 2 open projects on my workspace, I
>>> need a method like "getCurrentlyActiveProject()" I can't think of any
>>> other way because I don't know on which project the user is currently
>>> working on, I don't even know the project's name.
>>>
>>> Any idea? anyone?
>>
>> You can get the currently selected one, but that will only tell you when
>> one is actually selected. It's possible to be logically working in a
>> project (e.g. editing a file) without actually having the project
>> selected in the project explorer. Without knowing what you are doing I
>> can't comment as to whether this heuristic (selection) works for your
>> situation or not, or if there is more to your workflow.
>>
>> ===========================
>>
>> Chris Recoskie
>> Team Lead, IBM CDT Team
>> IBM Toronto
>> http://www.eclipse.org/cdt
Re: get my current project object. [message #193943 is a reply to message #193913] Mon, 25 June 2007 11:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dmsubs.NOSPAM.consertum.com

Here is some code that should help you get on your way...

public static final String S_C_PROJECTS_VIEW = "org.eclipse.cdt.ui.CView";

IStructuredSelection ssel = null;
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
if (activeWindow != null) {
ISelection sel = activeWindow.getSelectionService()
.getSelection(S_C_PROJECTS_VIEW);
if (sel instanceof IStructuredSelection) {
ssel = (IStructuredSelection) sel;
}
IResource resource = null;
Object obj = ssel.getFirstElement();
if (obj instanceof IResource)
resource = (IResource) obj;
else if (obj instanceof IBinaryContainer) {
IBinaryContainer bincon = (IBinaryContainer) obj;
resource = bincon.getUnderlyingResource();
} else if (obj instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) obj;
resource = (IResource) adaptable.getAdapter(IResource.class);
}
}

--
Derek


oren barzilai wrote:
> But how do I get the currently selected resource?
>
>
> "Derek Morris" <dmsubs@NOSPAM.consertum.com> wrote in message
> news:f5fvkf$tdq$1@build.eclipse.org...
>> You can get the currently selected IResource, and from that you can get
>> the project:
>>
>> private IContainer getProject(IResource resource) {
>> IContainer container = null;
>> if (resource != null) {
>> int type = resource.getType();
>> switch (type) {
>> case IResource.FILE :
>> container = resource.getParent();
>> break;
>> case IResource.FOLDER :
>> container = resource.getProject();
>> break;
>> case IResource.PROJECT :
>> container = (IContainer) resource;
>> break;
>> case IResource.ROOT :
>> break;
>> }
>> }
>> return container;
>> }
>>
>> --
>> Derek
>>
>>
>> Chris Recoskie wrote:
>>> oren barzilai wrote:
>>>> I can get hold on my project obj during creation process, But after I
>>>> restart the eclipse I can't find a way to get hold on my project object
>>>> again.
>>>>
>>>> Let's say that currently there is 2 open projects on my workspace, I
>>>> need a method like "getCurrentlyActiveProject()" I can't think of any
>>>> other way because I don't know on which project the user is currently
>>>> working on, I don't even know the project's name.
>>>>
>>>> Any idea? anyone?
>>> You can get the currently selected one, but that will only tell you when
>>> one is actually selected. It's possible to be logically working in a
>>> project (e.g. editing a file) without actually having the project
>>> selected in the project explorer. Without knowing what you are doing I
>>> can't comment as to whether this heuristic (selection) works for your
>>> situation or not, or if there is more to your workflow.
>>>
>>> ===========================
>>>
>>> Chris Recoskie
>>> Team Lead, IBM CDT Team
>>> IBM Toronto
>>> http://www.eclipse.org/cdt
>
>
Re: get my current project object. [message #193967 is a reply to message #193943] Mon, 25 June 2007 13:25 Go to previous message
Eclipse UserFriend
Originally posted by: oren_b1.verifone.com

Thanks.


"Derek Morris" <dmsubs@NOSPAM.consertum.com> wrote in message
news:f5oonr$nrq$1@build.eclipse.org...
> Here is some code that should help you get on your way...
>
> public static final String S_C_PROJECTS_VIEW = "org.eclipse.cdt.ui.CView";
>
> IStructuredSelection ssel = null;
> IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
> .getActiveWorkbenchWindow();
> if (activeWindow != null) {
> ISelection sel = activeWindow.getSelectionService()
> .getSelection(S_C_PROJECTS_VIEW);
> if (sel instanceof IStructuredSelection) {
> ssel = (IStructuredSelection) sel;
> }
> IResource resource = null;
> Object obj = ssel.getFirstElement();
> if (obj instanceof IResource)
> resource = (IResource) obj;
> else if (obj instanceof IBinaryContainer) {
> IBinaryContainer bincon = (IBinaryContainer) obj;
> resource = bincon.getUnderlyingResource();
> } else if (obj instanceof IAdaptable) {
> IAdaptable adaptable = (IAdaptable) obj;
> resource = (IResource) adaptable.getAdapter(IResource.class);
> }
> }
>
> --
> Derek
>
>
> oren barzilai wrote:
>> But how do I get the currently selected resource?
>>
>>
>> "Derek Morris" <dmsubs@NOSPAM.consertum.com> wrote in message
>> news:f5fvkf$tdq$1@build.eclipse.org...
>>> You can get the currently selected IResource, and from that you can get
>>> the project:
>>>
>>> private IContainer getProject(IResource resource) {
>>> IContainer container = null;
>>> if (resource != null) {
>>> int type = resource.getType();
>>> switch (type) {
>>> case IResource.FILE :
>>> container = resource.getParent();
>>> break;
>>> case IResource.FOLDER :
>>> container = resource.getProject();
>>> break;
>>> case IResource.PROJECT :
>>> container = (IContainer) resource;
>>> break;
>>> case IResource.ROOT :
>>> break;
>>> }
>>> }
>>> return container;
>>> }
>>>
>>> --
>>> Derek
>>>
>>>
>>> Chris Recoskie wrote:
>>>> oren barzilai wrote:
>>>>> I can get hold on my project obj during creation process, But after I
>>>>> restart the eclipse I can't find a way to get hold on my project
>>>>> object again.
>>>>>
>>>>> Let's say that currently there is 2 open projects on my workspace, I
>>>>> need a method like "getCurrentlyActiveProject()" I can't think of any
>>>>> other way because I don't know on which project the user is currently
>>>>> working on, I don't even know the project's name.
>>>>>
>>>>> Any idea? anyone?
>>>> You can get the currently selected one, but that will only tell you
>>>> when one is actually selected. It's possible to be logically working
>>>> in a project (e.g. editing a file) without actually having the project
>>>> selected in the project explorer. Without knowing what you are doing I
>>>> can't comment as to whether this heuristic (selection) works for your
>>>> situation or not, or if there is more to your workflow.
>>>>
>>>> ===========================
>>>>
>>>> Chris Recoskie
>>>> Team Lead, IBM CDT Team
>>>> IBM Toronto
>>>> http://www.eclipse.org/cdt
>>
Previous Topic:Dependency calculation using gcc 2.95.3
Next Topic:Lock editor
Goto Forum:
  


Current Time: Fri Nov 07 17:18:26 EST 2025

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

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

Back to the top