How to get active project name? [message #84697] |
Sun, 29 June 2003 05:43 |
Eclipse User |
|
|
|
Originally posted by: takuyay.hawaii.edu
I am wondering if you can help me how to get active project name from
Eclipse platform?
I have tried to use IWorkspace.getroot() and IWorkspacerRoot.getProjects()
which looks like:
IWorkspaceRoot root = MyPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
However, root.getProjects() returns all the projects listed in the Eclipse
so that I am not sure
which of them is the active project name.
The other way I did is to use ITextEditor.getTileToolTip() method to cut the
project off manually. This is actually I could get the active project name.
though....
Is there more elegant way to get project name?
I appreciate any related comments.
Thank you in advance.
Takuya
|
|
|
|
|
Re: How to get active project name? [message #85582 is a reply to message #85267] |
Mon, 30 June 2003 15:59 |
Eclipse User |
|
|
|
Originally posted by: burner.zclipse.org
On Mon, 30 Jun 2003 15:27:15 +0200, Asaf wrote:
> Another thing. If you are not using navigator but resources are opened
> in editor you can ask for getActiveEditor() :
>
> IEditorPart editorPart =
> getSite().getWorkbenchWindow().getActivePage().getActiveEdit or();
>
> if(editorPart != null)
> {
> IFileEditorInput input =
(IFileEditorInput)editorPart.getEditorInput() ;
This isn't always a valid cast. It's entirely possible for the active
editor to be editing something that isn't a file in the workbench. Think
of examining a file in a CVS repository before checking the module. It
might also be invalid when the active editor is displaying a classes in
jars, but I could be wrong on that.
Anyway, the point is that the question is faulty. There is no concept of
"active project". You can look at all the things you've suggested, but
it's entirely possible that the result at the end is null (especially when
you consider the user might be using the CVS repository browser).
mike
> IFile file = input.getFile();
> IProject activeProject = file.getProject(); String
> activeProjectName = activeProject .getName();
> }
>
>
> Hope you got help you needed
> Asaf.
>
>
>
|
|
|
Re: How to get active project name? [message #86146 is a reply to message #85582] |
Tue, 01 July 2003 08:22 |
Asaf Messages: 59 Registered: July 2009 |
Member |
|
|
Hello Michael, regarding what you said:
"> Anyway, the point is that the question is faulty. There is no concept of
> 'active project'. You can look at all the things you've suggested"
That's true if nothing is selected in Resource Navigator. But if there is
any project that is active from the point of view of the Eclipse platform no
project is Activef from Eclipse point of view, that's it.
That case you popup dialog to user and ask to choose resource in Navigator.
By default there is always 1 selected resource or more in navigator.
Farthere more , method i suggested that finds active resource in navigator
realy does the job.
Here is my point:
1. All Eclipse active menus are tiegtly attacheck to active selection in
resource navigator or Java package explorer.
Small test : Select any resource which is not Project in Resource
Navigator. Goto "Project" Menu. You will see
that "Rebuild Project" option is disalbed
Now click on resource which is Project type. repeat test and you will
see: "Rebuild Project" option is enabled.
2. Try to right click in navigator on any resource, you will discover that
project properties are active only when you right click on Project will give
the project properties and will make it active project
3. Goto "Project" Menu choose properties while any resource you'd like is
selecterd in navigator.
You will see that project properties belong to the project container of
that selected resource.
4. When choose run from "Run" menu the project container of the selected
resource in the resource navigator is the project that Eclipse platform will
run.
I guess there are more test you can run that proofs my point. I am sure you
got the point, in life that how it works.
That's true that there is no Active-Project concept in Eclipse. The maximum
close concept is active winow.
Yet, Eclipse does give its interpretation for active Project through its
behavior.
I followed this behavior into Eclipse sources and thats how I came up with
the solution I published in this news group.
Thanks for your replay,
Asaf
"Michael R Head" <burner@zclipse.org> wrote in message
news:pan.2003.06.30.15.59.36.358487@zclipse.org...
> On Mon, 30 Jun 2003 15:27:15 +0200, Asaf wrote:
>
>
> > Another thing. If you are not using navigator but resources are opened
> > in editor you can ask for getActiveEditor() :
> >
> > IEditorPart editorPart =
> > getSite().getWorkbenchWindow().getActivePage().getActiveEdit or();
> >
> > if(editorPart != null)
> > {
> > IFileEditorInput input =
> (IFileEditorInput)editorPart.getEditorInput() ;
>
> This isn't always a valid cast. It's entirely possible for the active
> editor to be editing something that isn't a file in the workbench. Think
> of examining a file in a CVS repository before checking the module. It
> might also be invalid when the active editor is displaying a classes in
> jars, but I could be wrong on that.
>
> Anyway, the point is that the question is faulty. There is no concept of
> "active project". You can look at all the things you've suggested, but
> it's entirely possible that the result at the end is null (especially when
> you consider the user might be using the CVS repository browser).
>
> mike
>
> > IFile file = input.getFile();
> > IProject activeProject = file.getProject(); String
> > activeProjectName = activeProject .getName();
> > }
> >
> >
> > Hope you got help you needed
> > Asaf.
> >
> >
> >
|
|
|
Re: How to get active project name? [message #86190 is a reply to message #85267] |
Tue, 01 July 2003 08:30 |
Eclipse User |
|
|
|
Originally posted by: takuyay.hawaii.edu
Hi Asaf.
Thank you so much for your detail code!
> IEditorPart editorPart =
> getSite().getWorkbenchWindow().getActivePage().getActiveEdit or();
>
> if(editorPart != null)
> {
> IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput()
;
> IFile file = input.getFile();
> IProject activeProject = file.getProject();
> String activeProjectName = activeProject .getName();
> }
This helped a lot and This is what I wanted.
This is more clever way, isn't it :)
Takuya
"Asaf" <asafr@cerylion.net> wrote in message
news:bdpaes$i9n$1@rogue.oti.com...
> Hello Takuya. The active project in eclipse is usally the project owner of
> the active component in the navigator.
> Suppose your havn't override the navigator extension and you are using the
> defualt ResourceNavigator of Eclipse
> (org.eclipse.ui.views.navigator.ResourceNavigator).
> Suppose your plugin named "MyPlugin" and you have in it method named
> getDefault() that returns instance of it, you can copy next code into your
> viewer of plugin object with your changes:
>
> IViewPart [] parts =
>
MyPlugin.getDefault().getWorkbench().getActiveWorkbenchWindo w().getActivePag
> e().getViews();
> IProject activeProject = null;
>
> for(int i=0;i<parts.length;i++)
> {
> if(parts[i] instanceof ResourceNavigator)
> {
> ResourceNavigator navigator = (ResourceNavigator)parts[i];
> StructuredSelection sel =
> (StructuredSelection)navigator.getTreeViewer().getSelection( );
> IResource resource = (IResource)sel.getFirstElement();
> activeProject = resource.getProject();
> break;
> }
> }
>
> String activeProjectName = activeProject .getName();
>
> I must admit that this is kind or architatual whole in Eclipse not knowing
> what is active project platform looking at.
> You might see other answers like:
> "You can find the current selection by calling getSelectionService()
> from"
> "IWorkbenchWindow() and then calling getSelection(). "
>
> from OTI. This is probably worng answer, since not allways last thing you
> select is file in resource navigator, sometimes it is just item from list
in
> viewer.
>
> Another thing. If you are not using navigator but resources are opened in
> editor you can ask for getActiveEditor() :
>
> IEditorPart editorPart =
> getSite().getWorkbenchWindow().getActivePage().getActiveEdit or();
>
> if(editorPart != null)
> {
> IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput()
;
> IFile file = input.getFile();
> IProject activeProject = file.getProject();
> String activeProjectName = activeProject .getName();
> }
>
>
> Hope you got help you needed
> Asaf.
>
>
>
>
>
>
>
>
>
>
>
>
>
> "Takuya Yamashita" <takuyay@hawaii.edu> wrote in message
> news:bdluak$brp$1@rogue.oti.com...
> > I am wondering if you can help me how to get active project name from
> > Eclipse platform?
> >
> > I have tried to use IWorkspace.getroot() and
IWorkspacerRoot.getProjects()
> > which looks like:
> >
> > IWorkspaceRoot root = MyPlugin.getWorkspace().getRoot();
> > IProject[] projects = root.getProjects();
> >
> > However, root.getProjects() returns all the projects listed in the
Eclipse
> > so that I am not sure
> > which of them is the active project name.
> >
> > The other way I did is to use ITextEditor.getTileToolTip() method to cut
> the
> > project off manually. This is actually I could get the active project
> name.
> > though....
> >
> > Is there more elegant way to get project name?
> >
> > I appreciate any related comments.
> > Thank you in advance.
> >
> > Takuya
> >
> >
> >
>
>
|
|
|
Re: How to get active project name? [message #86205 is a reply to message #84730] |
Tue, 01 July 2003 08:35 |
Eclipse User |
|
|
|
Originally posted by: takuyay.hawaii.edu
Hi adam
What I meant was that which is the project name of the editor file, which is
currenty opened (or edited) on the top of the Text editor part.
Asaf gave me what I wanted in the other thread.
Many thnaks.
Takuya
"Adam Kiezun" <adam.kiezun@gmx.net.remove> wrote in message
news:bdmebt$oqt$1@rogue.oti.com...
> >I am wondering if you can help me how to get active project name from
> >Eclipse platform?
>
>
> what do you mean by 'active' ?
>
> a.
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.09021 seconds