Home » Archived » IMP » Access to Project or ParseController
Access to Project or ParseController [message #23630] |
Fri, 08 August 2008 19:43 |
Eclipse User |
|
|
|
Originally posted by: mcriley.CohesionForce.com
When initializing a ParseController instance, a filePath and project (and
message handler) are provided.
From within my plug-in I need to get a handle to either the project that
the parse controller was initialized with, or the parse controller itself,
on which I can call getProject().
I could trivially modify the ParseController class to make this available,
but I don't like modifying auto-generated code, for obvious regenerative
reasons.
Would appreciate any advice.
Marc A. Criley
CohesionForce, Inc.
|
|
| |
Re: Access to Project or ParseController [message #24005 is a reply to message #23630] |
Mon, 25 August 2008 16:43 |
Stan Sutton Messages: 121 Registered: July 2009 |
Senior Member |
|
|
This would be a good topic for a programming tip or FAQ.
As you note, the project is available from the ParseController.
You can get the ParseController from the editor (i.e., each instance of
UniversalEditor can tell you what parse controller it's using).
This is a snippet of code that shows how the UniversalEditor gets the
project that it uses to initialize the ParseController:
if (fLanguageServiceManager.getParseController() != null) {
// Initialize the parse controller now, ...
IEditorInput editorInput= getEditorInput();
IFile file= EditorInputUtils.getFile(editorInput);
IPath filePath= EditorInputUtils.getPath(editorInput);
try {
ISourceProject srcProject= (file != null) ?
ModelFactory.open(file.getProject()) : null;
fLanguageServiceManager.getParseController().
initialize(filePath, srcProject, fAnnotationCreator);
} catch (ModelException e) {
ErrorHandler.reportError(...);
}
}
If you have the editor you can use this approach to get the project
without getting the parse controller, if that seems more convenient.
If you don't happen to have an instance of the current editor handy, you
can get that by the following approach:
IWorkbenchPage p=
RuntimePlugin.getInstance().getWorkbench().
getActiveWorkbenchWindow().getActivePage();
IEditorPart editor= p.getActiveEditor();
UniversalEditor ue= (UniversalEditor) editor;
If you look into UniversalEditor.getParseController(), you'll see that
the editor gets the pase controller (and other services) from an
instance of LanguageServiceManager. LanguageServiceManager maintains a
static mapping from each editor to it's associated
LanguageServiceManager instance. If you get the LangaugeServiceManager
instance for an editor, you can use it to access the instances of all of
the editors services.
Regards,
Stan
Marc A. Criley wrote:
> When initializing a ParseController instance, a filePath and project
> (and message handler) are provided.
>
> From within my plug-in I need to get a handle to either the project
> that the parse controller was initialized with, or the parse controller
> itself, on which I can call getProject().
>
> I could trivially modify the ParseController class to make this
> available, but I don't like modifying auto-generated code, for obvious
> regenerative reasons.
>
> Would appreciate any advice.
>
> Marc A. Criley
> CohesionForce, Inc.
>
>
|
|
| |
Re: Access to Project or ParseController [message #573126 is a reply to message #23630] |
Mon, 25 August 2008 16:43 |
Stan Sutton Messages: 121 Registered: July 2009 |
Senior Member |
|
|
This would be a good topic for a programming tip or FAQ.
As you note, the project is available from the ParseController.
You can get the ParseController from the editor (i.e., each instance of
UniversalEditor can tell you what parse controller it's using).
This is a snippet of code that shows how the UniversalEditor gets the
project that it uses to initialize the ParseController:
if (fLanguageServiceManager.getParseController() != null) {
// Initialize the parse controller now, ...
IEditorInput editorInput= getEditorInput();
IFile file= EditorInputUtils.getFile(editorInput);
IPath filePath= EditorInputUtils.getPath(editorInput);
try {
ISourceProject srcProject= (file != null) ?
ModelFactory.open(file.getProject()) : null;
fLanguageServiceManager.getParseController().
initialize(filePath, srcProject, fAnnotationCreator);
} catch (ModelException e) {
ErrorHandler.reportError(...);
}
}
If you have the editor you can use this approach to get the project
without getting the parse controller, if that seems more convenient.
If you don't happen to have an instance of the current editor handy, you
can get that by the following approach:
IWorkbenchPage p=
RuntimePlugin.getInstance().getWorkbench().
getActiveWorkbenchWindow().getActivePage();
IEditorPart editor= p.getActiveEditor();
UniversalEditor ue= (UniversalEditor) editor;
If you look into UniversalEditor.getParseController(), you'll see that
the editor gets the pase controller (and other services) from an
instance of LanguageServiceManager. LanguageServiceManager maintains a
static mapping from each editor to it's associated
LanguageServiceManager instance. If you get the LangaugeServiceManager
instance for an editor, you can use it to access the instances of all of
the editors services.
Regards,
Stan
Marc A. Criley wrote:
> When initializing a ParseController instance, a filePath and project
> (and message handler) are provided.
>
> From within my plug-in I need to get a handle to either the project
> that the parse controller was initialized with, or the parse controller
> itself, on which I can call getProject().
>
> I could trivially modify the ParseController class to make this
> available, but I don't like modifying auto-generated code, for obvious
> regenerative reasons.
>
> Would appreciate any advice.
>
> Marc A. Criley
> CohesionForce, Inc.
>
>
|
|
|
Goto Forum:
Current Time: Thu Dec 26 10:39:00 GMT 2024
Powered by FUDForum. Page generated in 0.03317 seconds
|