How do I get the name of the current eclipse project? I'm in a GMF view and need the projectname when some submenu of the popup menu ist used.
getWorkbench(). getActiveWorkbenchWindow(). getActivePage(). getViews(); Your GMF plugin name can be found in your .
In Eclipse, if the Project Explorer pane is not already open, click the Show View icon in the lower left corner of Eclipse, then click Project Explorer. In the Project Explorer pane, right-click your project name, then click Properties.
To rename the project, simply right-click the project and select "Refactor/Rename...". Fill in the new name and click OK.
This GMF class has a straightforward answer, if you have access to the ResourcesPlugin name:
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(myBundleName);
The generic answer (from a potentially outdated code) could be like (if you have an editor opened):
IEditorPart editorPart =
getSite().getWorkbenchWindow().getActivePage().getActiveEditor();
if(editorPart != null)
{
IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ;
IFile file = input.getFile();
IProject activeProject = file.getProject();
String activeProjectName = activeProject.getName();
//... use activeProjectName
}
If no editor is opened:
IViewPart [] parts =
MyPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With