Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » get the active project
get the active project [message #336237] Tue, 02 June 2009 14:08 Go to next message
Elad is currently offline Elad
Messages: 7
Registered: July 2009
Junior Member
Hello.

I use this code to get the active project.
but I have an error with the "activeProject" variable.
The error says - "Cannot refer to a non-final variable activeProject
inside an inner class defined in a different method"

but when I add "final" to the var, another error appear -

"The final local variable activeProject cannot be assigned, since it is
defined in an enclosing type".
Can you please help me with that.




IProject activeProject = null;
PlatformUI.getWorkbench().getDisplay().syncExec(
new Runnable() {
public void run() {
IWorkbenchWindow window = PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow();
if ( window != null ) {
IWorkbenchPage page = window.getActivePage();
if ( page != null ) {
IEditorPart editor = page.getActiveEditor();
if ( editor != null ) {
IEditorInput input = editor.getEditorInput();
if ( input instanceof IFileEditorInput ) {
IFileEditorInput fileInput = (IFileEditorInput) input;
activeProject = fileInput.getFile().getProject();
}
}
}
}
}
} );



Elad
Re: get the active project [message #336238 is a reply to message #336237] Tue, 02 June 2009 14:13 Go to previous message
Elad is currently offline Elad
Messages: 7
Registered: July 2009
Junior Member
I figured out the problem.
I took the "IProject activeProject = null;" and moved it inside the main
class declaration.

Thanks anyway :)
Previous Topic:Moving table items
Next Topic:Add New Wizards to the File>New shortcut
Goto Forum:
  


Current Time: Mon Jul 28 14:31:33 EDT 2014

Powered by FUDForum. Page generated in 0.03214 seconds