Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365169 - DiagramEditorInternal's selectionChanged() method doesn't support FormEditor-based multipage editors
Summary: DiagramEditorInternal's selectionChanged() method doesn't support FormEditor-...
Status: CLOSED FIXED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 0.8.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: Juno M4 Theme_bugs Indigo SR2
Keywords:
Depends on: 336488
Blocks:
  Show dependency tree
 
Reported: 2011-11-30 04:03 EST by Felix Velasco CLA
Modified: 2012-06-29 04:14 EDT (History)
1 user (show)

See Also:
michael.wenz: indigo+
michael.wenz: iplog+
michael.wenz: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Felix Velasco CLA 2011-11-30 04:03:52 EST
Build Identifier: 

FormEditor (from package org.eclipse.ui.forms.editor) extends MultiPageEditorPart, overriding the getSelectedPage() so it only returns the current page if it's an instance of IFormPage.
In order to retrieve the current page, FormEditor changes the visibility of getActiveEditor to public.

In selectionChanged(), as recommended in bug#332964, getSelectedPage() is used to support Multipage editors. However, it the editor is based in FormEditor, this method returns null for the graphiti editor.

A more general approach would be using getAdapter(DiagramEditorInternal.class), since MultiPageEditorPart's implementation first checks the currently active editor, and this behavior is respected by subclasses.

Reproducible: Always
Comment 1 Michael Wenz CLA 2011-11-30 04:28:45 EST
Should be postponed until https://bugs.eclipse.org/bugs/show_bug.cgi?id=336488 is resolved
Comment 2 Felix Velasco CLA 2011-11-30 05:12:29 EST
For the change in HEAD, I understand it goes after the bug#336488 revolution :)

However, could this be done independently in the 0.8 branch? I understand #336488 won't be ported back to 0.8.2, will it?
Comment 3 Michael Wenz CLA 2011-11-30 07:57:07 EST
(In reply to comment #2)
> However, could this be done independently in the 0.8 branch? I understand
> #336488 won't be ported back to 0.8.2, will it?

That's correct. And surely we can do this change independently in 0.8. Availability would be with the Graphiti 0.8.2 release as part of Indigo SR2 end or February 2012. Ok?
Comment 4 Felix Velasco CLA 2011-11-30 08:41:29 EST
Sure, great!
Comment 5 Michael Wenz CLA 2011-12-01 03:52:05 EST
Planned for Indigo SR2
Comment 6 Felix Velasco CLA 2011-12-01 07:09:50 EST
Looking deeper in the code, I think the original logic is flawed. Currently, the code is:

	boolean editorIsActive = getSite().getPage().isPartVisible(this);
--> If we are the current editor, go ahead
	if (!editorIsActive) {
		// Check if we are a page of the active multipage editor
--> However, if we are not....
		IEditorPart activeEditor = getSite().getPage().getActiveEditor();
		if (activeEditor != null) {
--> Almost certainly there's an active editor (i.e. a java editor), so we enter here

			// Check if the top level editor if it is active
			editorIsActive = getSite().getPage().isPartVisible(activeEditor);
--> And here editorIsActive becomes true, because we just find activeEditor as the visible editor

			if (activeEditor instanceof MultiPageEditorPart) {
--> If it's NOT a MultiPageEditorPart, editorIsActive remains true, so the graphiti diagram (or the 20 different opened diagrams) updates if selection (once again, think java editor)

				Object selectedPage = ((MultiPageEditorPart) activeEditor).getSelectedPage();
				if (!(selectedPage instanceof DiagramEditorInternal)) {
--> Only if the active editor is a multipart, and its active page is not a graphiti diagram (any graphiti editor, not only this one) do editorIsActive become false
					// Editor is active but the diagram sub editor is not
					// its active page
					editorIsActive = false;
				}
			}
		}
	}


Proposed solution:


boolean editorIsActive = getSite().getPage().isPartVisible(this);
if (!editorIsActive) {
	// Check if we are a page of the active multipage editor
	IEditorPart activeEditor = getSite().getPage().getActiveEditor();
	if (activeEditor != null) {
		// Check if the top level editor is a multipage editor, and its active page is this
		if (activeEditor instanceof MultiPageEditorPart) {
			Object selectedPage = activeEditor.getAdapter(DiagramEditorInternal.class);
			if (selectedPage == this) {
				// Editor is active but the diagram sub editor is not
				// its active page
				editorIsActive = true;
			}
		}
	}
}
Comment 7 Tim Kaiser CLA 2011-12-12 07:19:31 EST
solved in master and b0_8_x branch
Comment 8 Michael Wenz CLA 2011-12-14 07:34:35 EST
Bookkeeping, marked coding cotribution as IP log relevant
Comment 9 Michael Wenz CLA 2012-04-11 10:45:51 EDT
Bookkeeping: Set target release: 0.8.2
Comment 10 Michael Wenz CLA 2012-06-29 04:14:05 EDT
Part of Graphiti 0.9.0 (Eclipse Juno)