which api is usefull for retriving the the project details from with the plugin? [message #166707] |
Wed, 30 June 2004 17:30  |
Eclipse User |
|
|
|
Originally posted by: salgavkarNOSPAM.NOSPAMyahoo.com
Hi,
When i select some java source code from the code window, my plugin
should display the project details - such as project name, java source
file name, java class name, and the statement block - of this selected
text. Also note that the selected text may belong to any project.
question: what is the correct way of obtaining the project details from
within the plugin?
i would appreciate any help in this regard, including the pointers to API
that might be of some use.
Thanks.
-salgavkar.
|
|
|
|
Re: which api is usefull for retriving the the project details from with the plugin? [message #167059 is a reply to message #166740] |
Fri, 02 July 2004 20:56   |
Eclipse User |
|
|
|
Originally posted by: salgavkarNOSPAM.NOSPAMyahoo.com
Sunay Yaldiz wrote:
> salgavkar wrote:
> > Hi,
> > When i select some java source code from the code window, my plugin
> > should display the project details - such as project name, java source
> > file name, java class name, and the statement block - of this selected
> > text. Also note that the selected text may belong to any project.
> >
> > question: what is the correct way of obtaining the project details from
> > within the plugin?
> >
> > i would appreciate any help in this regard, including the pointers to API
> > that might be of some use.
> >
> > Thanks.
> >
> > -salgavkar.
> >
> org.eclipse.jdt.core is the package where you can find almost all of the
> necessary classes for Java Projects.
> In Eclipse Help, the "JDT Plugin developer guide" has also some useful
> code snippets under title "Manipulating Java Code". I would start by
> checking "JDT Plugin Developer Guide" chapter.
> Sunay
Hi Sunay,
Thanks for your reply. Could u tell me if i am on the right path? I have
used the following code.
if (selection instanceof ITextSelection) {
ITextSelection ts = (ITextSelection) selection;
System.out.println("Selected text is <" + ts.getText() + ">");
}
if (selection.isEmpty() ==false) {
IWorkbenchWindow activewindow = PlatformUI.getWorkbench
().getActiveWorkbenchWindow();
if (activewindow != null) {
IWorkbenchPart part = activewindow.getPartService
().getActivePart();
if (part instanceof IEditorPart) {
IEditorInput input = ((IEditorPart) part).getEditorInput();
if (input instanceof IFileEditorInput) {
StructuredSelection ss = new StructuredSelection
(((IFileEditorInput) input).getFile());
if (ss.isEmpty() == false)
System.out.println (ss.toString() );
}
}
}
}else
System.out.println ("nothing is selected");
Offcourse all this just gets the selected text and the file that this
selected text belongs to. Is there anyother way to extracted the project
details of selected text?
Thanks,
Salgavkar
|
|
|
Re: which api is usefull for retriving the the project details from with the plugin? [message #167151 is a reply to message #167059] |
Mon, 05 July 2004 04:41  |
Eclipse User |
|
|
|
Originally posted by: sunay.yaldiz.gentleware.com
salgavkar wrote:
> Sunay Yaldiz wrote:
>
>
>>salgavkar wrote:
>>
>>>Hi,
>>>When i select some java source code from the code window, my plugin
>>>should display the project details - such as project name, java source
>>>file name, java class name, and the statement block - of this selected
>>>text. Also note that the selected text may belong to any project.
>>>
>>>question: what is the correct way of obtaining the project details from
>>>within the plugin?
>>>
>>>i would appreciate any help in this regard, including the pointers to API
>>>that might be of some use.
>>>
>>>Thanks.
>>>
>>>-salgavkar.
>>>
>
>
>>org.eclipse.jdt.core is the package where you can find almost all of the
>>necessary classes for Java Projects.
>
>
>>In Eclipse Help, the "JDT Plugin developer guide" has also some useful
>>code snippets under title "Manipulating Java Code". I would start by
>>checking "JDT Plugin Developer Guide" chapter.
>
>
>>Sunay
>
>
>
> Hi Sunay,
> Thanks for your reply. Could u tell me if i am on the right path? I have
> used the following code.
>
> if (selection instanceof ITextSelection) {
> ITextSelection ts = (ITextSelection) selection;
> System.out.println("Selected text is <" + ts.getText() + ">");
> }
> if (selection.isEmpty() ==false) {
> IWorkbenchWindow activewindow = PlatformUI.getWorkbench
> ().getActiveWorkbenchWindow();
> if (activewindow != null) {
> IWorkbenchPart part = activewindow.getPartService
> ().getActivePart();
> if (part instanceof IEditorPart) {
> IEditorInput input = ((IEditorPart) part).getEditorInput();
> if (input instanceof IFileEditorInput) {
> StructuredSelection ss = new StructuredSelection
> (((IFileEditorInput) input).getFile());
> if (ss.isEmpty() == false)
> System.out.println (ss.toString() );
> }
> }
> }
> }else
> System.out.println ("nothing is selected");
>
> Offcourse all this just gets the selected text and the file that this
> selected text belongs to. Is there anyother way to extracted the project
> details of selected text?
>
> Thanks,
>
> Salgavkar
>
>
I also would do it like this. I don't think there is a very different
way. In any case one has to check for selections, get the active editor
etc. But maybe there is another way I am not aware of.
For getting the project details, you can start with getting the project
the file belongs to by
IFile selectedFile = ...;
IJavaProject javaProject = (IJavaProject)selectedFile.getProject();
//then get the related information about the project...
Sunay
|
|
|
Powered by
FUDForum. Page generated in 0.28178 seconds