Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » FocusListener for Diagrams?
FocusListener for Diagrams? [message #774224] Tue, 03 January 2012 14:46 Go to next message
Stefan Naujokat is currently offline Stefan Naujokat
Messages: 2
Registered: December 2011
Junior Member
Hello everyone,

I have a TreeViewer that needs to filter its contents according to the currently displayed Diagram (more precisely, the linked BOs). Therefore, it needs to be notified when the user switches focus between open Diagrams. Can anyone point me in the right direction on how to achieve this?

Regards,
Stefan
Re: FocusListener for Diagrams? [message #774589 is a reply to message #774224] Wed, 04 January 2012 08:39 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1612
Registered: July 2009
Location: Walldorf, Germany
Senior Member
You might want to have a look at the Eclipse UI IPartListener and
IPartListener2 interfaces that get notified about part lifecycle events
(e.g. activation, bring to top...).

If that does not help the Graphiti diagram editor (class
DiagramEditorInternal) offers a setFocus method that you could overwrite to
trigger a notification of your TreeViewer.

Michael
Re: FocusListener for Diagrams? [message #777374 is a reply to message #774224] Tue, 10 January 2012 11:09 Go to previous messageGo to next message
Stefan Naujokat is currently offline Stefan Naujokat
Messages: 2
Registered: December 2011
Junior Member
Hi Michael,

thanks for the help. I decided to try both variants to learn more about Eclipse's and Graphiti's architectures.

I started with the second suggestion, but did not manage to tell Graphiti to use my DiagramEditor. I thought that I have to do something in my DiagramTypeProvider, similar to setFeatureProvider, but setDiagramEditor is private. Is there some example that shows how to replace the default DiagramEditor?

Anyhow, I succeeded with the part listener, but get a "discouraged access" warning about getDiagramTypeProvider being not accessible. Is there a better way to retrieve the Diagram (or linked BO) from the DiagramEditor?

	@Override
	public void partActivated(IWorkbenchPartReference partRef) {
		if (partRef.getId().equals("org.eclipse.graphiti.ui.editor.DiagramEditor")) {
			IWorkbenchPart part = partRef.getPart(false);
			if (part instanceof DiagramEditor) {				
				DiagramEditor editor = (DiagramEditor)part;
				Diagram diagram = editor.getDiagramTypeProvider().getDiagram();
				EObject myBO = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
				//TODO: notify TreeViewer which BO's diagram got activated
			}
		}
		
		
	}


-Stefan

Re: FocusListener for Diagrams? [message #777379 is a reply to message #777374] Tue, 10 January 2012 11:19 Go to previous message
Michael Wenz is currently offline Michael Wenz
Messages: 1612
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Stefan,

you need to register your editor to the Eclipse org.eclipse.ui.editors
extension point. After that you will be able to use the Eclipse methods with
your editor ID to open your editor, e.g.:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input,
editorId)

Regarding the warning: currently there's no other way, as the editor is not
part of the API. For our Juno version we reworked that part, so the usecase
is now supported via official APIs.

Michael
Previous Topic:Palette Layout
Next Topic:Problem with overdrawing
Goto Forum:
  


Current Time: Mon Oct 20 04:36:04 GMT 2014

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

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