Author: tfmorris
Date: 2008-10-06 11:45:06-0700
New Revision: 15893
Modified:
trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java
trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
Log:
Issue 5438: Make use of new listener minimal update facility so that we don't unregister all our listeners and then get an exception when adding them again, preventing us from properly processing the remove event
http://argouml.tigris.org/issues/show_bug.cgi?id=5438
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java?view=diff&rev=15893&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java&r1=15892&r2=15893
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/static_structure/ui/FigClassifierBoxWithAttributes.java 2008-10-06 11:45:06-0700
@@ -27,9 +27,9 @@
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import javax.swing.Action;
@@ -86,6 +86,7 @@
*
* @see org.argouml.uml.diagram.static_structure.ui.FigClassifierBox#buildAddMenu()
*/
+ @Override
protected ArgoJMenu buildAddMenu() {
ArgoJMenu addMenu = super.buildAddMenu();
Action addAttribute = new ActionAddAttribute();
@@ -99,39 +100,58 @@
* @return the class name and bounds together with compartment
* visibility.
*/
+ @Override
public String classNameAndBounds() {
return super.classNameAndBounds()
+ "attributesVisible=" + isAttributesVisible() + ";";
}
+ @Override
protected void updateListeners(Object oldOwner, Object newOwner) {
- if (oldOwner != null) {
- removeAllElementListeners();
- }
+ Set<Object[]> listeners = new HashSet<Object[]>();
+
+ // Collect the set of model elements that we want to listen to
if (newOwner != null) {
+ // TODO: Because we get called on each and every change event, when
+ // the model is in a state of flux, we'll often get an
+ // InvalidElementException before we finish this collection. The
+ // only saving grace is that we're called SO many times that on the
+ // last time, things should be stable again and we'll get a good set
+ // of elements for the final update. We need a better mechanism.
+
// add the listeners to the newOwner
- addElementListener(newOwner);
+ listeners.add(new Object[] {newOwner, null});
+
// and its stereotypes
// TODO: Aren't stereotypes handled elsewhere?
- Collection c = new ArrayList(
- Model.getFacade().getStereotypes(newOwner));
+ for (Object stereotype
+ : Model.getFacade().getStereotypes(newOwner)) {
+ listeners.add(new Object[] {stereotype, null});
+ }
+
// and its features
for (Object feat : Model.getFacade().getFeatures(newOwner)) {
- c.add(feat);
+ listeners.add(new Object[] {feat, null});
// and the stereotypes of its features
- c.addAll(new ArrayList(Model.getFacade().getStereotypes(feat)));
+ for (Object stereotype
+ : Model.getFacade().getStereotypes(feat)) {
+ listeners.add(new Object[] {stereotype, null});
+ }
// and the parameter of its operations
if (Model.getFacade().isAOperation(feat)) {
- c.addAll(Model.getFacade().getParameters(feat));
+ for (Object param : Model.getFacade().getParameters(feat)) {
+ listeners.add(new Object[] {param, null});
+ }
}
}
- // And now add listeners to them all:
- for (Object obj : c) {
- addElementListener(obj);
- }
}
+
+ // Update the listeners to match the desired set using the minimal
+ // update facility
+ updateElementListeners(listeners);
}
+ @Override
public void renderingChanged() {
if (getOwner() != null) {
updateAttributes();
@@ -143,6 +163,7 @@
* TODO: Based on my comments below, with that work done,
* this method can be removed - Bob.
*/
+ @Override
protected void updateLayout(UmlChangeEvent event) {
super.updateLayout(event);
@@ -174,6 +195,7 @@
}
}
+ @Override
protected void updateStereotypeText() {
Rectangle rect = getBounds();
@@ -256,7 +278,7 @@
}
}
}
-
+ @Override
public Dimension getMinimumSize() {
// Use "aSize" to build up the minimum size. Start with the size of the
// name compartment and build up.
@@ -314,6 +336,7 @@
*
* @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
*/
+ @Override
protected void setStandardBounds(final int x, final int y, final int w,
final int h) {
Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java?view=diff&rev=15893&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java&r1=15892&r2=15893
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java 2008-10-06 11:45:06-0700
@@ -1249,6 +1249,11 @@
if (notationProviderName != null) {
notationProviderName.updateListener(this, getOwner(), event);
}
+ // TODO: This brute force approach of updating listeners on each
+ // and every event, without checking the event type or any other
+ // information is going to cause lots of InvalidElementExceptions
+ // in subclasses implementations of updateListeners (and they
+ // won't have the event information to make their own decisions)
updateListeners(getOwner(), getOwner());
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.