Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to find MPart for currently open editor
How to find MPart for currently open editor [message #997393] Mon, 07 January 2013 09:43 Go to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

how can I find the currently opened editor by using EModelService?

Ralph
Re: How to find MPart for currently open editor [message #997843 is a reply to message #997393] Tue, 08 January 2013 21:24 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hi

what I do...

in my editor part contrib class @PostConstruct I use an injected MApplication and get its context, there I register "this"

appl.getContext().put( MyEditor.class, this );


I use a part listener to update the current registered editor every time it is activated.

IPartListener partListener = new IPartListener() {
	public void partVisible(MPart part) {}
	public void partHidden(MPart part) {}
	public void partDeactivated(MPart part) {}
	public void partBroughtToTop(MPart part) { registerObject(part); }
	public void partActivated(MPart part) {	registerObject(part); }
};
private void registerObject(MPart part) {
	if( part.getContext().get( MyEditor.class) != MyEditor.this ){
		return;
	}
	appl.getContext().set( MyEditor.class, MyEditor.this );
}


In the @PreDestroy

if( MyEditor.this == appl.getContext().get( MyEditor.class )){
	appl.getContext().set( MyEditor.class, null );
}
partService.removePartListener(partListener);


Frank
Re: How to find MPart for currently open editor [message #998189 is a reply to message #997843] Wed, 09 January 2013 14:29 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

Is this equivivalent to

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()


? Looks like I missed something here Sad

Ralph
Re: How to find MPart for currently open editor [message #998364 is a reply to message #997393] Wed, 09 January 2013 21:37 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
With the above you can use

@Inject
public void setEditor( @Optional MyEditor editor ){
  //...
}


to get the current editor of type MyEditor injected.
Re: How to find MPart for currently open editor [message #1002395 is a reply to message #998364] Fri, 18 January 2013 13:58 Go to previous messageGo to next message
Eclipse UserFriend
Try

@Inject
@Active
MPart part;

Re: How to find MPart for currently open editor [message #1002723 is a reply to message #1002395] Sat, 19 January 2013 08:08 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

this will also return a view or am I wrong?

Ralph
Re: How to find MPart for currently open editor [message #1002934 is a reply to message #1002723] Sat, 19 January 2013 22:16 Go to previous message
Eclipse UserFriend
It will return the active MPart. In e4 there's no such thing as a "view" in the 3.x meaning. Everything is a part.
Previous Topic:Properties view (or other "standard" view) in pure eclipse e4 perspective
Next Topic:Image Registry / Icons
Goto Forum:
  


Current Time: Fri Apr 26 19:49:25 GMT 2024

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

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

Back to the top