How to calculate figure's size including all sub figures (that have separate edit parts) in GEF?

StackOverflow https://stackoverflow.com/questions/12370382

  •  01-07-2021
  •  | 
  •  

Question

I'm trying to draw diagram that contains a single entity which holds multiple elements inside.

My MVC structure looks something like this:
Model: contains EntityModel.java and ElementModel.java which represents my model objects.
View: EntityFigure.java and ElementFigure.java
Controller: EntityEditPart.java and ElementEditPart.java

I'm overriding getModelChildren() in EntityEditPart.java to return list of ElementModel.java so that is how GEF knows that an element "belongs" to an entity.

Since I would like to calculate my entity's figure size and include the embedded elements in this calculation, I cannot call entityFigure.getPreferredSize() during createFigure() in EntityEditPart.java since at this point - the elements figures do not exists (createFigure() in ElementEditPart.java is not invoked yet).

I'm looking for a place to set my entity figure after all child figures were created.
I though about overriding addNotify() in ElementEditPart.java, however, it is being called after creating a specific inner element and not after all elements created.

Any ideas?

Hope I was clear enough...

Était-ce utile?

La solution

You can do it in an extension of

 refreshChildren()

method of an edit part, since all the child creation is done in refreshChildren() of superclass's (AbstractEditPart) refresh method:

public void refresh() {
    refreshVisuals();
    refreshChildren();
}

Or, you can just extend

refresh()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top