Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gef-dev] Selection Problem when two GEF editor instances are running

My GEF editor is having problems with selection when I have two instances of it
running.  The problem arises when I switch from one instance of the editor to 
the other and click on a GEF object contained in the 2nd editor to select it.  
The clicked-on object gets its marquee around it -- so GEF seems to know about 
the selection -- but the Delete action, for example, may not be told about it.  
Often, in these situations Delete is not available in the menu bar, even though
there is a Delete action in my code that works in other situations.

It is, of course, probably something that I have missed out in setting up the 
editor. To try to get some clues I added code for testing to override the 
"selectionChanged" method from GEF's GraphicalEditor to see if I could see what
was happening:
------------------------------------------------------------
(from my Editor):

private static int count = 0;

public void selectionChanged(IWorkbenchPart part, ISelection selection){
   count++;
   System.out.println("====="+count+"\nActiveEditor: "+
      getSite().getPage().getActiveEditor().getTitle()+
      ", this: "+this.getTitle()+", part: "+part.getTitle());
   System.out.println("selectionChanged: "+part.getTitle()+", selection: "
        +selection);
   super.selectionChanged(part, selection);
}
------------------------------------------------------------

When I switched from one editor to the other, and again when I selected the 
object in the 2nd editor instance the "selectionChanged" object was invoked as 
I expected. However, the console output from this would often show that the 
passed in "part" and "this" were not the same thing.  "part" always seemed to 
match the activeEditor, but "this" was often the previous editor instance.  
Typical output from my "selectionChanged" would say:
------------------------------------------------------------
=====12
ActiveEditor: Vico Frontispiece, this: OCVE: Bar view, part: Vico Frontispiece
selectionChanged: Vico Frontispiece, selection: [ImageLinkableObjectPart( 
LinkableObject: rect:98,-17,140,18(67) )]
------------------------------------------------------------

It seemed to me that although the editor instance for "Vico Frontispiece" as 
the active editor (and, indeed, the owner of the selected "LinkableObject"), 
that the instance for "OCVE: Bar view" was being asked to handle it.

This would mean, in turn, that when the super.selectionChanged method was 
invoked:
------------------------------------------------------------
(from org.eclipse.gef.ui.parts.GraphicalEditor)

public void selectionChanged(IWorkbenchPart part, ISelection selection) {
   // If not the active editor, ignore selection changed.
   if (this.equals(getSite().getPage().getActiveEditor()))
      updateActions(selectionActions);
}

------------------------------------------------------------
"this" would not, indeed, not match the active editor, and the updateActions 
did not take place, and certainly not to the active editor.

Clearly there is a synchonization problem between the instances of my editor.  
Any thoughts on what I am doing wrong??

Thanks, in advance...              ... john bradley


Back to the top