[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: How to make a Compartment become invisible when it is empty?

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);
}
}


Best regards
Alessander Botti Benevides