Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 15:34 Go to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

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 08:10 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
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 09:03 Go to previous message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 104
Registered: October 2011
Location: Berlin, Germany
Senior Member

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 11:02]

Report message to a moderator

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


Current Time: Tue Mar 19 10:17:03 GMT 2024

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

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

Back to the top