Skip to main content



      Home
Home » Eclipse Projects » GEF » Under which circumstances can an existing EditPart be absent from the registry?(I have a case where an existing EditPart isn't in the EditPartRegistry)
icon2.gif  Under which circumstances can an existing EditPart be absent from the registry? [message #1408616] Fri, 15 August 2014 11:34 Go to next message
Eclipse UserFriend
In one of my EditPart's refreshVisuals() method, I'm looping through the EditPartRegistry for purposes of hit-testing... During some testing I've found that some of the EditParts "present" in the editor (i.e. ones whose figure is visible in the editor) cannot be found in the registry. Below is a code snippet. How can this possibly be? Is not every EditPart automatically registered? May I be looping while some EditParts are still being registered? I'd have thought when an EditPart "has" a figure it would be in the registry...

for (Object part : getViewer().getEditPartRegistry().values()) {
  if (part instanceof ThisPart || part instanceof ThatPart) {
    if (part instanceof ThisPart && ((ThisPart) part).getModel().getName().equals("ThisName")) {
      System.out.println("FOUND this with bounds " +((ThisPart) part).getFigure().getBounds());
    }
  }
}
Re: Under which circumstances can an existing EditPart be absent from the registry? [message #1409485 is a reply to message #1408616] Mon, 18 August 2014 04:10 Go to previous messageGo to next message
Eclipse UserFriend
Did you check that there are not two edit parts referring to the same model element? It could happen if a model element is included in two model children or incoming/outgoing model connections lists.
Re: Under which circumstances can an existing EditPart be absent from the registry? [message #1413314 is a reply to message #1409485] Thu, 28 August 2014 05:03 Go to previous message
Eclipse UserFriend
Hi Alexander,

Many thanks for you reply! I've solved this problem now. Unfortunately I forgot to mention that I'd needed to do the hit-testing on opening the editor. It is all too understandable that at this point (in refreshVisuals() of an arbitrary EditPart) not all EditParts will be in the registry Embarrassed .

My (admittedly very hacky) solution involves getting a count of all model elements which are eligible for hit-testing in refreshVisuals(), and checking this count against the number of EditParts in the registry which are of a type which can "hold" these model elements. This way I can react to the registry being completed (for these types of elements) and perform a one-time re-layout of the whole diagram which is relatively performant as I can access the "complete" EditPartRegistry.

Below is some code for anyone who isn't clever enough to do this properly (like myself), but will ping this thread once s/he has found a better solution.

int nodes = 0;
nodes = nodes + superElement.getAllTypeOneElements().size();
nodes = nodes + superElement.getAllTypeTwoElements().size();
int partCounter = 0;
for (Object value : getViewer().getEditPartRegistry().values()) {
  if (value instanceof TypeOneEditPart || value instanceof TypeTwoEditPart) {
    partCounter++;
  }
}
if (nodes == partCounter) {
  System.out.println("This EditPart is the last one to be added to the registry, which is now complete!");
  Layouter.pleaseLayoutTheDiagramProperlyJustThisOnce();
}

[Updated on: Mon, 08 September 2014 07:02] by Moderator

Previous Topic:Getting coordinates from automatic layout
Next Topic:[Zest] - order in which GraphNode and GraphConnections are drawn
Goto Forum:
  


Current Time: Sun Jul 13 05:55:58 EDT 2025

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

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

Back to the top