CSS to hide empty compartments on class diagrams [message #1768909] |
Mon, 24 July 2017 16:38  |
Eclipse User |
|
|
|
I'm using Papyrus 3.0.0, coming from heavy use of PlantUML, which has a wonderful feature:
This effectively hides any class diagram compartments that are empty. It's useful in domain modeling where, with some methodologies, you don't model operations, and if a domain class has no attributes, it's just a rectangle with its name.
I've made some progress with CSS, but I'm stuck in hiding a compartment when its elements are empty.
/* if no attributes, hide that compartment */
ClassDiagram Class > Compartment[kind="attributes"] {
visible: false;
}
/* if attributes, show the compartment */
ClassDiagram Class > Compartment[kind="attributes"][ownedAttribute] {
visible: true;
}
The problem with my approach is that ownedAttribute is always matched. I'm trying to find out how to do a selector that only find classes that have no ownedAttribute elements. Is this possible?
|
|
|
Re: CSS to hide empty compartments on class diagrams [message #1768993 is a reply to message #1768909] |
Tue, 25 July 2017 09:52   |
Eclipse User |
|
|
|
Hi,
You want to write:
/* if no attributes, hide that compartment */
ClassDiagram Class > Compartment[kind="attributes"] {
visible: false;
}
/* if attributes, show the compartment */
ClassDiagram Class[ownedAttribute] > Compartment[kind="attributes"] {
visible: true;
}
because CSS matchers work at the semantic level, i.e. it is the Class that owns attributes. However, there are still more issues:
- A bug in the Eclipse 4 CSS matchers for "OneOf" condition (~=), which doesn't check for attribute existence before reading an attribute value (Thus will fail with a NullPointer if the attribute is null/doesn't exist). So Papyrus always returns empty values instead of null to work around this issue, but ideally, we should override or the E4 matcher. The consequence of returning empty values is that the CSS Matchers consider that any attribute always exists.
- You can't add attributes to a Class when its attributes compartment is hidden. So even if you were able to hide empty compartments, you'd have to show them before creating new children in them (Or you'd have to use alternate ways, such as Model Explorer or Properties View, which is a little bit less straightforward). And even if you add an attribute to the semantic model, the compartment will be visible, but it won't display the attribute (Because the diagram is not synchronized with the semantic model - at least not by default).
So there are a few adjustments to make in Papyrus (and, optionally, E4 CSS) to make this work properly
HTH,
Camille
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05077 seconds