[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [cdt-dev] Finding selected project name in Project Explorervia Java code
|
Beth,
I can't find the package where the CommonPlugin class is. Any advice?
Thanks,
Daniele
-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Beth Tibbitts
Sent: martedì 8 aprile 2008 15.12
To: CDT General developers list.
Subject: Re: [cdt-dev] Finding selected project name in Project Explorervia 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