eclipse-uml2 / uml2

An EMF-based implementation of the UML 2.x metamodel for the Eclipse platform.
Eclipse Public License 2.0
5 stars 4 forks source link

Eclipse Modeling example: Apply Stereotype to model element not work in Java. #78

Open eclipse-uml2-bot opened 1 week ago

eclipse-uml2-bot commented 1 week ago

| --- | --- | | Bugzilla Link | 484719 | | Status | REOPENED | | Importance | P3 enhancement | | Reported | Dec 19, 2015 07:19 EDT | | Modified | Dec 23, 2015 09:58 EDT | | Reporter | Patrick Germann |

Description

Created attachment 258810\ Snapshot from Eclipse with the example model, profile and java code (as defined in eclipse - not custom)

The eclipse modeling example "org.eclipse.uml2.examples.introtoprofiles" has an example to create an UML-Profile (name of file is "Ecore.profile.uml"). The code has some instruction to apply the stereotypes of the UML-Profile to the target model "ExtendedPO2.uml". The example runs without any errors - but the target model does not contains any applied stereotypes.\ I think the operation "applyStereotype" does not work.

Example Eclipse Project reference description:\ Creates an example project containing the complete profile and source code for the Introduction to UML2 Profiles tutorial on the Eclipse UML2 wiki.

applystereotype.PNG

applystereotype.PNG

eclipse-uml2-bot commented 1 week ago

By Kenn Hussey on Dec 20, 2015 14:11

Did you modify the example to save the model, along with its stereotype applications, at the end?

The out-of-the-box example doesn't actually save the model at the end, so unless you've modified it to do so you won't see the stereotype applications when you open the (unmodified) model afterward.

eclipse-uml2-bot commented 1 week ago

By Patrick Germann on Dec 23, 2015 04:23

Created attachment 258864 Same problem apply stereotype after model save.

Example of eclipse modeling example.

:compression: eclipseModelingExample.zip

eclipse-uml2-bot commented 1 week ago

By Patrick Germann on Dec 23, 2015 04:25

I have added the example. Now I have modified the example - small enhancement with the 'model save'.

But there is no visible Change on the model file 'ExtendedPO2.uml' (after refresh of Environment).

Best regards\ Patrick

eclipse-uml2-bot commented 1 week ago

By Kenn Hussey on Dec 23, 2015 09:18

It's not enough to just save the model - you have to add all of the stereotype applications (which are separate objects that aren't located in the model's containment hierarchy) to the resource as well. Try adding something more like this to the end of the main method in the example:

    Resource resource = RESOURCE_SET.createResource(\
        URI.createFileURI(args[0]).appendSegment("ExtendedPO2")
            .appendFileExtension(UMLResource.FILE_EXTENSION));

    EList<EObject> contents = resource.getContents();

    contents.add(epo2Model);

    for (TreeIterator<EObject> allContents = UML2Util
        .getAllContents(epo2Model, true, false); allContents.hasNext();) {

        EObject eObject = allContents.next();

        if (eObject instanceof Element) {\
            contents
                .addAll(((Element) eObject).getStereotypeApplications());\
        }\
    }

    try {\
        resource.save(null);\
    } catch (IOException ioe) {\
        err(ioe.getMessage());\
    }
eclipse-uml2-bot commented 1 week ago

By Ed Willink on Dec 23, 2015 09:27

(In reply to Kenn Hussey from comment #4)

It's not enough to just save the model - you have to add all of the stereotype applications (which are separate objects that aren't located in the model's containment hierarchy) to the resource as well. Try adding something more like this to the end of the main method in the example:

Surely this code should be in the distributed example?

eclipse-uml2-bot commented 1 week ago

By Kenn Hussey on Dec 23, 2015 09:40

(In reply to comment #5)

Surely this code should be in the distributed example?

We could consider making that modification, but the original intent of the example was to show how to build a profile, apply stereotypes, and retrieve tagged values.

eclipse-uml2-bot commented 1 week ago

By Ed Willink on Dec 23, 2015 09:54

(In reply to Kenn Hussey from comment #6)

We could consider making that modification, but the original intent of the example was to show how to build a profile, apply stereotypes, and retrieve tagged values.

When I upgraded the example on Bug 382342, "save" was one of the hard-to-do things that I highlighted. IMHO since the example is all that there is, it should endeavor to demonstrate the full life cycle.

Christian did an excellent job of polishing the example and resolving my FIXMEs. He provided "save" code, but this bug identifies that the example save is incomplete.

eclipse-uml2-bot commented 1 week ago

By Kenn Hussey on Dec 23, 2015 09:58

Actually, overwriting the original model is a lot simpler than the code snippet I provided, since the model and its stereotype applications are already attached to a resource in the resource set:

    try {\
        epo2Model.eResource().save(null);\
    } catch (IOException ioe) {\
        err(ioe.getMessage());\
    }

The snippet I originally provided would be useful if you wanted to add the model and stereotype applications to a new/different resource (with a different URI) in case you don't want to overwrite the original.