|
Re: Notification problem with class package [message #1393977 is a reply to message #1393806] |
Fri, 04 July 2014 15:21 |
|
Hi, Justin,
The setPackage(Package) implementation inherited by the implementation
of Class looks like this:
public void setPackage(org.eclipse.uml2.uml.Package newPackage) {
if (newPackage != eInternalContainer()) {
if (EcoreUtil.isAncestor(this, newPackage))
throw new IllegalArgumentException(
"Recursive containment not allowed for " + toString()); //$NON-NLS-1$
NotificationChain msgs = null;
if (eInternalContainer() != null)
msgs = eBasicRemoveFromContainer(msgs);
if (newPackage != null)
msgs = ((InternalEList<Type>) newPackage.getOwnedTypes())
.basicAdd(this, msgs);
msgs = eBasicSetContainer((InternalEObject) newPackage,
InternalEObject.EOPPOSITE_FEATURE_BASE
- UMLPackage.PACKAGE__PACKAGED_ELEMENT, msgs);
if (msgs != null)
msgs.dispatch();
} else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
UMLPackage.CLASSIFIER__PACKAGE, newPackage, newPackage));
}
As you can see, the class will notify the change in its package
property if the package is being set to the same package that is
already referenced (generating a "touch" notification). In all other
cases, you will get notification of the Package::packagedElement
collection changing in both the old and new packages and this will
produce also notifications for whatever reference is the opposite of
Package::packagedElement. Unfortunately, there is no opposite in this
case, so you will only get notifications from the packages.
This looks to me like an oversight in the codegen template for
container references like this. I'd suggest raising an enhancement
request in bugzilla. At the very least, it seems inconsistent to me
that setPackage() will sometimes notify a Classifier::package "change"
and sometimes not.
HTH,
Christian
On 2014-07-04 14:40:02 +0000, Justin Trentesaux said:
> Hi,
>
> I use the UML2 implementation in my project and I want to be notified
> when the package of a class changed.
> For illutrate my problem, I wrote the following code:
>
>
> Model model = UMLFactory.eINSTANCE.createModel();
> model.setName("model");
> Package package1 = model.createNestedPackage("package1");
> Package package2 = model.createNestedPackage("package2");
> Class class1 = package1.createOwnedClass("Class1", false);
>
> class1.eAdapters().add(new AdapterImpl() {
> @Override
> public void notifyChanged(Notification notification)
> {
> super.notifyChanged(notification);
>
> if(notification.isTouch()) {
> return;
> }
>
> System.out.println("Notification received");
> }
> });
>
> class1.setPackage(package2); // same problem with
> 'package2.getPackagedElements().add(class1)'
>
>
> The problem is that my observer (adapter) is never notified by the
> class that its package has changed.
> Am I doing something wrong? Or this is a bug in the UML implementation?
>
> Regards,
> Justin
|
|
|
|
Powered by
FUDForum. Page generated in 0.03943 seconds