In
Template Package Item Rendering outcome I expose the bug that you won't get consistent item rendering in different target diagrams for items defined in a template package.
This bug, essentially, makes that problem
moot since (it appears) that the diagram to be used as the source for the new item in the target diagram is defined almost "by accident" - and so your new item
may look NOTHING like you expect it to...
OK, let's start by noting that in EA
any item (pretty much) can be placed on
any diagram type. For any model, of more than say two items, it is
extremely likely that any given item will be placed on more than one diagram. Let's also assert that for most (if not all) of those diagrams, the item will have the same rendering but on some may have other renderings.
EA accommodates this usage by the concept of the local diagram rendering (set via the Format Tool (
View|Toolbars>Format Tool) and the concept of a default rendering (set via
Appearance>Default Appearance... [F4]). So far so good.
EA also has the notion of a Template package where the user can set the initial values (Note how I haven't set default - although the Help implies that) for new (unstereotyped) items:
if you drop an unstereotyped element - a Class, for example - onto a diagram, Enterprise Architect searches the Templates package for a Class diagram that defines an unstereotyped Class, and applies that definition to the new Class.So you see how the Help EXPLICITLY says that for a Class it searches for a Class diagram? Well that doesn't appear to be the case! What EA does (it appears from the limited testing I - and apparently NOT Sparx have done) is locate the item type with the lowest object ID within the Template package! In fact the template item doesn't have to be in any package at all! Currently, I have (as a result of this testing, NO diagrams in my template package and and the new items are still being created according to some of the items within the package. NOTE: Because there is NO local override, only the default appearance attributes are used. However, IF the item with the lowest Object_ID is in ANY diagram, the local settings from that diagram are used! Confused? You should be!
So if you have the same type of item defined more than once (why would you? - see below), it will take the item with the lowest Object_ID.
Obviously there is are
two defects here - the first is
either in the behaviour or in the help definition,
the second is in Sparx's design, testing and development process!Back to why define the item type more than once? As I mentioned above, you can place any (pretty much) item type on any diagram type. Having found the bug regarding the the local versus default rendering identified above, I thought I'd investigate if EA took the source diagram from the target diagram type. I created the same class in an activity diagram but found that the resultant rendering on the activity diagram was the one from the (original) Class diagram. I then removed the class from the class diagram, and the next new class took its rendering from the rendering in the Activity diagram!
It occurs to me that if you followed a logical algorithm for the ultimate rendering of an item from the template package you might create something like this:
Check the type of the target diagram, if there is an item of the same type on the same type of diagram in the Template package, use its rendering. Otherwise, if there is only one rendering of the same type of item on one diagram in the template package use that. Finally, if there is an element of the same type but not on any diagram (or in more than one diagram, none of which are the target diagram type) in the template package, use the Default rendering for the element (as defined for that element), otherwise, use the EA default.
NOTE: Because this is a Template package, there should only be one instance of each type of element and each type of diagram in the package (and EA should validate this). You'll note that if we take the actual rendering in the diagram, as the default rendering for the new element, the
same browser element can have different renderings in different diagrams!
{end of part 1}