1 | public void actionPerformed(ActionEvent e) { | | 1 | /** |
2 | super.actionPerformed(e); | | 2 | * Helper method that gets a stereotype for the given model |
3 | Object t = TargetManager.getInstance().getModelTarget(); | | 3 | * element with the given name. |
4 | Object owner = null; | | 4 | * |
5 | Object namespace = null; | | 5 | * TODO: this might be a performance bottleneck. If so, caching of |
6 | if (Model.getFacade().isAStereotype(t)) { | | 6 | * stereotypes for model elements by their stereotypes names could fix it. |
7 | owner = t; | | 7 | * |
8 | } else if (Model.getFacade().isAPackage(t)) { | | 8 | * @param modelElement The model element for which to look for the |
9 | namespace = t; | | 9 | * stereotype with the given name |
10 | } else { | | 10 | * @param stereotypeName The name of the stereotype. |
11 | namespace = Model.getFacade().getInnerContainingModel(t); | | 11 | * @return the stereotype model element or null if not found. |
12 | } | | 12 | */ |
13 | Object newTagDefinition = null; | | 13 | private Object getStereotype(Object modelElement, String stereotypeName) { |
14 | if (Model.getFacade().getUmlVersion().charAt(0) == '1') { | | 14 | Object stereotype = null; |
15 | newTagDefinition = Model.getExtensionMechanismsFactory() | | 15 | Collection stereotypes = StereotypeUtility.getAvailableStereotypes( |
16 | .buildTagDefinition((String) null, owner, namespace); | | 16 | modelElement); |
17 | } else { | | 17 | for (Iterator it = stereotypes.iterator(); it.hasNext();) { |
18 | Object type = null; | | 18 | Object candidateStereotype = it.next(); |
19 | for (Object aType : Model.getExtensionMechanismsHelper() | | 19 | if (getFacade().getName(candidateStereotype).equals( |
20 | .getCommonTaggedValueTypes()) { | | 20 | stereotypeName)) { |
21 | if ("String".equals(Model.getFacade().getName(aType))) { | | 21 | stereotype = candidateStereotype; |
22 | type = aType; | | 22 | break; |
23 | break; | | 23 | } |
24 | } | | 24 | } |
25 | } | | 25 | return stereotype; |
26 | newTagDefinition = Model.getCoreFactory().buildAttribute2(t, type); | | 26 | } |
27 | } | | | |
28 | TargetManager.getInstance().setTarget(newTagDefinition); | | | |
29 | super.actionPerformed(e); | | | |
30 | } | | | |