Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Finding selected project name in Project Explorer via Java code

How about this?  May be a bit round-about but seems to work whether the
selection is a project, a leaf node (file) or container (folder in
between).  May not work on some of the indirect resources like include
files etc., however.

      protected void sampleGetSelectedProject() {
            ISelectionService ss=CommonPlugin.getDefault().getWorkbench
().getActiveWorkbenchWindow().getSelectionService();
            String projExpID = "org.eclipse.ui.navigator.ProjectExplorer";
            ISelection sel = ss.getSelection(projExpID);
            Object selectedObject=sel;
            if(sel instanceof IStructuredSelection) {
                  selectedObject=
((IStructuredSelection)sel).getFirstElement();
            }
            if} (selectedObject instanceof IAdaptable) {
                  IResource res = (IResource) ((IAdaptable) selectedObject)
                              .getAdapter(IResource.class.);
                  IProject project = res.getProject();
                  System.out.println(."Project found: "+project.getName());
            }
      }}

..Beth

Beth Tibbitts  (859) 243-4981  (TL 545-4981)
High Productivity Tools / Parallel Tools  http://eclipse.org/ptp
IBM T.J.Watson Research Center
Mailing Address:  IBM Corp., 745 West New Circle Road, Lexington, KY 40511


                                                                           
             "Daniele Palmas"                                              
             <Daniele.Palmas@t                                             
             elit.com>                                                  To 
             Sent by:                  <cdt-dev@xxxxxxxxxxx>               
             cdt-dev-bounces@e                                          cc 
             clipse.org                                                    
                                                                   Subject 
                                       [cdt-dev] Finding selected project  
             04/08/08 03:05 AM         name in Project Explorer via        
                                       Java code                           
                                                                           
             Please respond to                                             
               "CDT General                                                
             developers list."                                             
             <cdt-dev@eclipse.                                             
                   org>                                                    
                                                                           
                                                                           




Greetings,

I am trying to extend the cdt plugin with a new button: when the user
clicks on this button there starts a process which updates some files of a
project. However I would like to know which project is selected in the
Project Explorer so I can update only the files of the chosen project. If I
make this process via external tool I can use the environment variable $
{project_name}: is there a way I can find the same information via Java
code?

Thanks in advance,
Daniele Palmas_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




Back to the top