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 04:43 Go to next message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
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 16:24 Go to previous messageGo to next message
Frank Benoit is currently offline Frank Benoit
Messages: 47
Registered: July 2009
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 09:29 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
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 16:37 Go to previous messageGo to next message
Frank Benoit is currently offline Frank Benoit
Messages: 47
Registered: July 2009
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 08:58 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 596
Registered: December 2010
Senior Member

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 03:08 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
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 17:16 Go to previous message
Sopot Cela is currently offline Sopot Cela
Messages: 596
Registered: December 2010
Senior Member

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: Tue Jul 29 19:02:28 EDT 2014

Powered by FUDForum. Page generated in 0.01640 seconds