Hi Matthias, thank you very much!
But setting the compartment's size to 0 does not makes it totally
invisible in my case, maybe because it has a Stack Layout...
So, I have a different solution: Suppose my metamodel has an EClass named
"C" having an EReference named "attribute" which is the Containemnt
Feature of the compartment named "AttributeCompartment" in the gmfgraph
file:
(i) add "view.setVisible(false);" in the end of the method
decorateView(...) in CAttributeCompartmentViewFactory.java:
protected void decorateView(View containerView, View view, IAdaptable
semanticAdapter, String semanticHint, int index, boolean persisted) {
..
view.setVisible(false);
}
(ii) create a method handleNotificationEvent(Notification event) in
CEdidPart.java:
protected void handleNotificationEvent(Notification event) {
getPrimaryShape().updateContents();
super.handleNotificationEvent(event);
}
(iii) create the method updateContents() inside the class CFigure in
CEdidPart.java (substitute "???" for the name of your GMF project):
private void updateContents() {
CEditPart ceditpart = CEditPart.this;
C element = (C) ceditpart.resolveSemanticElement();
EditPart compartmentEditPart =
getChildBySemanticHint(???.diagram.part.???VisualIDRegistry.getType(???.diagram.edit.parts.CAttributeCompartmentEditPart.VISUAL_ID));
if (compartmentEditPart != null) {
if (element.getAttribute().size() == 0) \\ where getAttribute() refers to
EReference "attribute".
((View) compartmentEditPart.getModel()).setVisible(false);
else
((View) compartmentEditPart.getModel()).setVisible(true);
}
}