Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » IMP » Access to Project or ParseController
Access to Project or ParseController [message #23630] Fri, 08 August 2008 19:43 Go to next message
Eclipse UserFriend
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 #23718 is a reply to message #23630] Fri, 15 August 2008 18:16 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 #24005 is a reply to message #23630] Mon, 25 August 2008 16:43 Go to previous message
Stan Sutton is currently offline Stan SuttonFriend
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 #572963 is a reply to message #23630] Fri, 15 August 2008 18:16 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 16:43 Go to previous message
Stan Sutton is currently offline Stan SuttonFriend
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.
>
>
Previous Topic:PrefSpec Wizard Not Working?
Next Topic:Preference change listener
Goto Forum:
  


Current Time: Thu Mar 28 14:29:03 GMT 2024

Powered by FUDForum. Page generated in 0.03173 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top