CSS to hide empty compartments on class diagrams [message #1768909] |
Mon, 24 July 2017 20:38 |
C. Fuhrman Messages: 4 Registered: July 2017 |
Junior Member |
|
|
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 13:52 |
Camille Letavernier Messages: 952 Registered: February 2011 |
Senior Member |
|
|
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
Camille Letavernier
|
|
|
Re: CSS to hide empty compartments on class diagrams [message #1769022 is a reply to message #1768993] |
Tue, 25 July 2017 18:35 |
C. Fuhrman Messages: 4 Registered: July 2017 |
Junior Member |
|
|
Thanks - that is useful information. I hadn't thought about the difficulty of adding attributes later once the compartment is hidden. I see it's possible to add them via the properties dialog for the class if it's selected. I admit I'm not well versed on implications with model synchronization, as I've not gotten that far with Papyrus.
If anyone's interested, here are the other parts of my CSS that simplifies domain modeling in an agile fashion (without worrying about too many details too soon). It draws its inspiration from the methodology of Craig Larman's Applying UML and Patterns book. If an attribute's type isn't specified, its type is hidden (better than showing "<Undefined>"). I also hide the role names in associations, as that information is probably not useful in the beginning.
Class {
gradient: white vertical;
elementIcon:false;
shadow:false;
/* qualifiedNameDepth:full; */
}
Class > Compartment[kind="operations"] {
visible:false;
}
Class > Compartment[kind="nestedclassifiers"] {
visible:false;
}
Property {
elementIcon: false;
maskLabel: derived name type; /* show these only on properties */
}
Property[type=""] {
maskLabel: derived name; /* don't show "<Undefined>" if no type */
}
/* Association tweaks for Domain Diagrams */
Association > Label:sourceRole {
maskLabel: none;
}
Association > Label:targetRole {
maskLabel: none;
}
Association {
routing: Rectilinear;
targetDecoration: none;
sourceDecoration: none;
}
[Updated on: Tue, 25 July 2017 18:36] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03491 seconds