Home » Archived » IMP » Access to Project or ParseController
Access to Project or ParseController [message #23630] |
Fri, 08 August 2008 15: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 12:43  |
Eclipse User |
|
|
|
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 #572963 is a reply to message #23630] |
Fri, 15 August 2008 14:16  |
Eclipse User |
|
|
|
Hi Marc
You don't say where your starting.
You must have some context otherwise how would you know which
of five different languages in five different open editors you care
about.
Assuming that you are interested in the active editor, this will be a
UniversalEditor that you can get at via
((UniversalEditor)PlatformUI.getWorkbench().getActiveWorkben chWindow().getActivePage().getActiveEditor()).getParseContro ller();
to.
However, you should find that you have better context available from some
method that was invoked in your plugin.
Regards
Ed Willink
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 12:43  |
Eclipse User |
|
|
|
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: Mon Jul 07 01:44:35 EDT 2025
Powered by FUDForum. Page generated in 0.09251 seconds
|