Hi Bob, et al.,
You marked the change included below to the CoreFactoryMDRImpl as: "this is
flawed, to be discussed".
If I analyse what you have done, I understand and completely approve the way
the Multiplicity of the attribute is handled: in fact, you convert the UML
object into an array of integers, so that a similar UML object can be
recreated with the integers (This is a form of serialisation, isn't it?).
The same applies for simple meta-attributes of the Attribute: e.g. the name:
it is converted to a string, and stored as such. No problem here.
But I have my doubts about e.g. the "Classifier type", i.e. the type of the
attribute.
Your implementation means that the memento keeps a reference to this
Classifier!
What will happen if e.g. the Classifier that is the attribute "type" is
deleted, too, en then afterwards, undo is invoked twice?
The first undo will recreate a similar Classifier - but with a different
internal ID.
The second undo will attempt to restore the "type" of the attribute: will
this work? It refers to a deleted (and replaced) element...
Regards,
Michiel
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, November 25, 2006 2:09 AM
Subject: svn commit: r11514 -
trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
Author: bobtarling
Date: 2006-11-24 17:09:23-0800
New Revision: 11514
Modified:
trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
Log:
Demo undo for deleting an attribute (this is flawed, to be discussed)
Modified:
trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
Url:
http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java?view=diff&rev=11514&p1=trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java&p2=trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java&r1=11513&r2=11514
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
(original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/CoreFactoryMDRImpl.java
2006-11-24 17:09:23-0800
@@ -30,6 +30,10 @@
import java.util.List;
import org.argouml.model.CoreFactory;
+import org.argouml.model.DataTypesFactory;
+import org.argouml.model.DummyModelMemento;
+import org.argouml.model.ModelMemento;
+import org.easymock.internal.Range;
import org.omg.uml.behavioralelements.statemachines.Event;
import org.omg.uml.foundation.core.Abstraction;
import org.omg.uml.foundation.core.Artifact;
@@ -78,6 +82,7 @@
import org.omg.uml.foundation.datatypes.CallConcurrencyKindEnum;
import org.omg.uml.foundation.datatypes.ChangeableKind;
import org.omg.uml.foundation.datatypes.ChangeableKindEnum;
+import org.omg.uml.foundation.datatypes.Expression;
import org.omg.uml.foundation.datatypes.Multiplicity;
import org.omg.uml.foundation.datatypes.MultiplicityRange;
import org.omg.uml.foundation.datatypes.OrderingKind;
@@ -1357,10 +1362,93 @@
throw new IllegalArgumentException("elem: " + elem);
}
// delete AttributeLinks where this is the Attribute
- nsmodel.getUmlHelper().deleteCollection(
- nsmodel.getUmlPackage().getCommonBehavior()
- .getAAttributeLinkAttribute().getAttributeLink(
- (Attribute) elem));
+
+ final Attribute attr = (Attribute) elem;
+
+ ModelMemento memento = new ModelMemento() {
+
+ private Attribute attribute = attr;
+ private String attributeName;
+ private VisibilityKind visibility;
+ private ScopeKind ownerScope;
+ private ScopeKind targetScope;
+ private Collection multiplicityPairs;
+ private Expression initialValue;
+ private ChangeableKind changeability;
+ private OrderingKind ordering;
+ private Namespace namespace;
+ private Classifier type;
+ private Classifier cls;
+ private AssociationEnd assEnd;
+ private Collection dependencies;
+ private int pos;
+
+ public void undo() {
+ attribute = (Attribute) createAttribute();
+ cls.getFeature().add(pos, attribute);
+
+ DataTypesFactory dtf = nsmodel.getDataTypesFactory();
+
+ Iterator it = multiplicityPairs.iterator();
+ ArrayList mrs = new ArrayList();
+ while (it.hasNext()) {
+ int pair[] = (int[])it.next();
+ MultiplicityRange multRange =
+ (MultiplicityRange) dtf.createMultiplicityRange(
+ pair[0], pair[1]);
+ mrs.add(multRange);
+ }
+ Multiplicity mult =
(Multiplicity)dtf.createMultiplicity(mrs);
+ attribute.setMultiplicity(mult);
+ attribute.setName(attributeName);
+ attribute.setNamespace(namespace);
+ attribute.setOrdering(ordering);
+ attribute.setOwnerScope(ownerScope);
+ attribute.setTargetScope(targetScope);
+ attribute.setType(type);
+ attribute.setVisibility(visibility);
+ attribute.setChangeability(changeability);
+ //attribute.setInitialValue(initialValue);
+ //attribute.setAssociationEnd(assEnd);
+ //attribute.setClientDependency(dependencies);
+ }
+ public void redo() {
+ multiplicityPairs =
+ new ArrayList(
+
attribute.getMultiplicity().getRange().size());
+ Iterator it =
+ attribute.getMultiplicity().getRange().iterator();
+ while (it.hasNext()) {
+ MultiplicityRange range = (MultiplicityRange)
it.next();
+ int pair[] = new int[2];
+ pair[0] = range.getLower();
+ pair[1] = range.getUpper();
+ multiplicityPairs.add(pair);
+ }
+
+ changeability = attribute.getChangeability();
+ attributeName = attribute.getName();
+ namespace = attribute.getNamespace();
+ ownerScope = attribute.getOwnerScope();
+ targetScope = attribute.getTargetScope();
+ type = attribute.getType();
+ visibility = attribute.getVisibility();
+ cls = attribute.getOwner();
+ assEnd = attribute.getAssociationEnd();
+ dependencies = attribute.getClientDependency();
+ initialValue = attribute.getInitialValue();
+
+ pos = cls.getFeature().indexOf(attribute);
+
+ nsmodel.getUmlHelper().deleteCollection(
+ nsmodel.getUmlPackage().getCommonBehavior()
+
.getAAttributeLinkAttribute().getAttributeLink(
+ attr));
+ }
+ };
+ memento.redo();
+
+ org.argouml.model.Model.notifyMementoCreationObserver(memento);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.14/548 - Release Date: 23/11/2006
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]