Author: mvw
Date: 2009-11-29 22:56:31-0800
New Revision: 17560

Modified:
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/module/TempListener.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLChangeExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLConditionExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLDefaultValueExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionBodyField.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionLanguageField.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionPanel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLInitialValueExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLRecurrenceExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLScriptExpressionModel.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTimeExpressionModel.java

Log:
Fix for issue 5215: Make the expression fields on the new proppanels work.

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/module/TempListener.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/module/TempListener.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/module/TempListener.java
       (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/module/TempListener.java
       2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id: XmlPropertyPanelsModule.java 17494 2009-11-19 20:14:02Z bobtarling $
-// Copyright (c) 2008 The Regents of the University of California. All
+// Copyright (c) 2008-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -34,30 +34,34 @@
 import org.argouml.ui.targetmanager.TargetListener;
 
 public class TempListener implements TargetListener {
-    
+
     private static final Logger LOG = Logger.getLogger(TempListener.class);
     private TempTabPage tab;
     private JPanel lastPanel;
-    
+
     TempListener(TempTabPage tab) {
         this.tab = tab;
     }
-    
+
     public void targetAdded(TargetEvent e) {
+       setTarget(e.getNewTarget());
     }
 
     public void targetRemoved(TargetEvent e) {
-        // TODO Auto-generated method stub
-        
+       setTarget(e.getNewTarget());
     }
 
     public void targetSet(TargetEvent e) {
+        setTarget(e.getNewTarget());
+    }
+
+    private void setTarget(Object target) {
         try {
-            LOG.info("TARGET SET" + e.getNewTarget());
+            LOG.info("TARGET SET" + target);
             if (lastPanel != null) {
                 tab.remove(lastPanel);
             }
-            lastPanel = 
XMLPropPanelFactory.getInstance().createPropPanel(e.getNewTarget());
+            lastPanel = 
XMLPropPanelFactory.getInstance().createPropPanel(target);
             tab.add(lastPanel, BorderLayout.CENTER);
         } catch (Exception ex) {
             //

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLChangeExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLChangeExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLChangeExpressionModel.java
       (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLChangeExpressionModel.java
       2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2006-2008 The Regents of the University of California. All
+// Copyright (c) 2006-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -26,14 +26,11 @@
 
 import org.apache.log4j.Logger;
 import org.argouml.model.Model;
-import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetManager;
-import org.argouml.uml.ui.UMLExpressionModel2;
-import org.argouml.uml.ui.UMLUserInterfaceContainer;
 
 /**
  * The model for the boolean expression of a ChangeEvent.
- * 
+ *
  * @author michiel, penyaskito
  */
 class UMLChangeExpressionModel extends UMLExpressionModel {
@@ -68,14 +65,15 @@
         if (target == null) {
             throw new IllegalStateException("There is no target");
         }
+        Model.getStateMachinesHelper().setChangeExpression(target, null);
         Model.getStateMachinesHelper().setChangeExpression(target, expression);
     }
 
     /*
      * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
      */
-    public Object newExpression() {
+    public Object newExpression(String lang, String body) {
         LOG.debug("new boolean expression");
-        return Model.getDataTypesFactory().createBooleanExpression("", "");
+        return Model.getDataTypesFactory().createBooleanExpression(lang, body);
     }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLConditionExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLConditionExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLConditionExpressionModel.java
    (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLConditionExpressionModel.java
    2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2003-2006 The Regents of the University of California. All
+// Copyright (c) 2003-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -24,11 +24,8 @@
 
 package org.argouml.core.propertypanels.ui;
 
-import java.beans.PropertyChangeEvent;
-
 import org.apache.log4j.Logger;
 import org.argouml.model.Model;
-import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetManager;
 
 /**
@@ -42,7 +39,7 @@
         Logger.getLogger(UMLConditionExpressionModel.class);
 
     /**
-     * The constructor.    
+     * The constructor.
      */
     public UMLConditionExpressionModel(Object target) {
         super(target, "condition");
@@ -65,14 +62,15 @@
         if (target == null) {
             throw new IllegalStateException("There is no target");
         }
+        Model.getUseCasesHelper().setCondition(target, null);
         Model.getUseCasesHelper().setCondition(target, expression);
     }
 
     /*
      * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
      */
-    public Object newExpression() {
+    public Object newExpression(String lang, String body) {
         LOG.debug("new boolean expression");
-        return Model.getDataTypesFactory().createBooleanExpression("", "");
+        return Model.getDataTypesFactory().createBooleanExpression(lang, body);
     }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLDefaultValueExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLDefaultValueExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLDefaultValueExpressionModel.java
 (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLDefaultValueExpressionModel.java
 2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2008 The Regents of the University of California. All
+// Copyright (c) 2008-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -25,15 +25,15 @@
 package org.argouml.core.propertypanels.ui;
 
 import org.argouml.model.Model;
-import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetManager;
 
 /**
+ * The model for the expression for a default value of a Parameter.
  *
  * @author penyaskito
  */
 class UMLDefaultValueExpressionModel extends UMLExpressionModel {
-    
+
     /**
      * The constructor.
      *
@@ -61,6 +61,7 @@
         Object target = TargetManager.getInstance().getTarget();
 
         if (target != null) {
+            Model.getCoreHelper().setDefaultValue(target, null);
             Model.getCoreHelper().setDefaultValue(target, expression);
         }
         else {
@@ -72,23 +73,8 @@
     /*
      * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
      */
-    public Object newExpression() {
-        return Model.getDataTypesFactory().createExpression("", "");
-    }
-
-    public void targetAdded(TargetEvent e) {
-        // TODO: Auto-generated method stub
-        
-    }
-
-    public void targetRemoved(TargetEvent e) {
-        // TODO: Auto-generated method stub
-        
-    }
-
-    public void targetSet(TargetEvent e) {
-        // TODO: Auto-generated method stub
-        
+    public Object newExpression(String lang, String body) {
+        return Model.getDataTypesFactory().createExpression(lang, body);
     }
 
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionBodyField.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionBodyField.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionBodyField.java
 (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionBodyField.java
 2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Copyright (c) 1996-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -23,9 +23,6 @@
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 
 package org.argouml.core.propertypanels.ui;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
 import javax.swing.JTextArea;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
@@ -52,13 +49,14 @@
 
     /**
      * The constructor.
-     * 
+     *
      * @param expressionModel
      *            Expression model, should be shared between Language and Body
      *            fields
      * @param notify
      *            Set to true to forward events to model. Only one of Language
      *            and Body fields should have this set to true.
+     *            TODO: MVW: I do not understand that.
      */
     public UMLExpressionBodyField(UMLExpressionModel expressionModel,
                                  boolean notify) {
@@ -68,11 +66,11 @@
         setToolTipText(Translator.localize("label.body.tooltip"));
         setFont(LookAndFeelMgr.getInstance().getStandardFont());
         setRows(2); // make it stretch vertically
-        
+
         update();
     }
 
-    private void update() {
+    void update() {
         String oldText = getText();
         String newText = model.getBody();
 

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionExpressionModel.java
   (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionExpressionModel.java
   2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2004-2006 The Regents of the University of California. All
+// Copyright (c) 2004-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -25,12 +25,11 @@
 package org.argouml.core.propertypanels.ui;
 
 import org.argouml.model.Model;
-import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetManager;
 
 /**
  * The model for a UML Expression that is obtained from its "parent"
- * by getExpression - hence: Guard, ChangeEvent, TimeEvent.
+ * by getExpression - hence: Guard, ChangeEvent.
  *
  * @author Michiel, Penyaskito
  */
@@ -56,14 +55,19 @@
      * @see 
org.argouml.uml.ui.UMLExpressionModel2#setExpression(java.lang.Object)
      */
     public void setExpression(Object expr) {
-        Model.getStateMachinesHelper()
-               .setExpression(TargetManager.getInstance().getTarget(), expr);
+       assert (expr == null) || Model.getFacade().isAExpression(expr);
+       Object target = TargetManager.getInstance().getTarget();
+       assert Model.getFacade().isAGuard(target)
+               || Model.getFacade().isAChangeEvent(target);
+       Model.getStateMachinesHelper().setExpression(target, null);
+       /* If we do not set it to null first, then we get a MDR DebugException: 
*/
+       Model.getStateMachinesHelper().setExpression(target, expr);
     }
 
     /*
      * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
      */
-    public Object newExpression() {
-        return Model.getDataTypesFactory().createBooleanExpression("", "");
+    public Object newExpression(String lang, String body) {
+        return Model.getDataTypesFactory().createBooleanExpression(lang, body);
     }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionLanguageField.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionLanguageField.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionLanguageField.java
     (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionLanguageField.java
     2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -46,6 +46,7 @@
      * Language and Body fields
      * @param n Only one of Language and Body fields should
      * forward events to model
+     * TODO: MVW: I do not understand that.
      */
     public UMLExpressionLanguageField(UMLExpressionModel m, boolean n) {
         model = m;
@@ -56,7 +57,7 @@
         update();
     }
 
-    private void update() {
+    void update() {
         String oldText = getText();
         String newText = model.getLanguage();
         if (oldText == null || newText == null || !oldText.equals(newText)) {

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionModel.java
     (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionModel.java
     2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -24,19 +24,55 @@
 
 package org.argouml.core.propertypanels.ui;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.EventListenerList;
+
+import org.apache.log4j.Logger;
 import org.argouml.model.Model;
 
 /**
- * @author mkl, penyaskito
+ * The model for Expressions.
+ * The target is the UML element to which this Expression is attached.
+ *
+ * The ChangeEvent/ChangeListener handling is inspired by
+ * javax.swing.DefaultBoundedRangeModel.
+ * It listens to UML model changes not caused by us,
+ * which need to trigger an update of the UI rendering.
+ *
+ * @author mkl, penyaskito, mvw
  */
-abstract class UMLExpressionModel {
-    
+abstract class UMLExpressionModel
+       implements PropertyChangeListener {
+
+    private static final Logger LOG =
+        Logger.getLogger(UMLExpressionModel.class);
+
     private Object target;
     private String propertyName;
-    private Object/*MExpression*/ expression;
-    private boolean mustRefresh;
+
+    /** This member is only used when we set the expression ourselves.
+     * In this case, we do not wish to receive UML model change events
+     * for this self-inflicted change.
+     * So, this member is used to detect this situation. */
+    private Object rememberExpression;
+
+//    private boolean mustRefresh;
     private static final String EMPTYSTRING = "";
 
+    /** The listeners waiting for model changes. */
+    protected EventListenerList listenerList = new EventListenerList();
+
+    /**
+     * Only one <code>ChangeEvent</code> is needed per model instance
+     * since the event's only (read-only) state is the expression.  The source
+     * of events generated here is always "this".
+     */
+    protected transient ChangeEvent changeEvent = null;
+
     /**
      * The constructor.
      *
@@ -46,13 +82,42 @@
     public UMLExpressionModel(Object target, String name) {
         this.target = target;
         propertyName = name;
-        mustRefresh = true;
+//        mustRefresh = true;
+        startListeningForModelChanges();
+    }
+
+    protected void startListeningForModelChanges() {
+       if (Model.getFacade().isAUMLElement(target)) {
+           Model.getPump().addModelEventListener(this, target,
+                   propertyName);
+       }
+       LOG.debug(">>Start listening for UML changes...");
+    }
+
+    protected void stopListeningForModelChanges() {
+       if (Model.getFacade().isAUMLElement(target)) {
+           Model.getPump().removeModelEventListener(this, target,
+                       propertyName);
+       }
+       LOG.debug(">>Stop listening for UML changes...");
+    }
+
+    public void propertyChange(PropertyChangeEvent e) {
+       if (propertyName.equals(e.getPropertyName())) {
+           if (rememberExpression != e.getNewValue()) {
+               fireStateChanged();
+               LOG.debug(">>UML expression changed.");
+           } else {
+               /* This should not happen. */
+               LOG.debug(">>Got an event for a modelchange that we inflicted 
ourselves...");
+           }
+       }
     }
 
     protected Object getTarget() {
         return target;
     }
-    
+
     /**
      * @return the expression
      */
@@ -64,18 +129,15 @@
     public abstract void setExpression(Object expr);
 
     /**
-     * @return a new expression
+     * @return a new expression with given language and body
      */
-    public abstract Object newExpression();
-
+    public abstract Object newExpression(String language, String body);
 
     /**
      * @return the language of the expression
      */
     public String getLanguage() {
-        if (mustRefresh) {
-            expression = getExpression();
-        }
+       Object expression = getExpression();
         if (expression == null) {
             return EMPTYSTRING;
         }
@@ -86,9 +148,7 @@
      * @return The body text of the expression.
      */
     public String getBody() {
-        if (mustRefresh) {
-            expression = getExpression();
-        }
+        Object expression = getExpression();
         if (expression == null) {
             return EMPTYSTRING;
         }
@@ -100,6 +160,7 @@
      */
     public void setLanguage(String lang) {
 
+       Object expression = getExpression();
         boolean mustChange = true;
         if (expression != null) {
             String oldValue =
@@ -123,6 +184,8 @@
      * @param body the body text of the expression
      */
     public void setBody(String body) {
+
+       Object expression = getExpression();
         boolean mustChange = true;
         if (expression != null) {
             Object oldValue = Model.getDataTypesHelper().getBody(expression);
@@ -144,17 +207,72 @@
     }
 
     /**
+     * This is only called if we already know that the values differ.
+     *
      * @param lang the language of the expression
      * @param body the body text of the expression
      */
     private void setExpression(String lang, String body) {
+       assert lang != null;
+       assert body != null;
+
         // Expressions are DataTypes, not independent model elements
         // be careful not to reuse them
-        if (mustRefresh || expression == null) {
-            expression = newExpression();
+       rememberExpression = getExpression();
+       stopListeningForModelChanges();
+       if (rememberExpression != null) {
+           Model.getUmlFactory().delete(rememberExpression);
+       }
+       if (lang.length() == 0 && body.length()==0) {
+           rememberExpression = null;
+       } else {
+           rememberExpression = newExpression(lang, body);
+       }
+       setExpression(rememberExpression);
+       startListeningForModelChanges();
+    }
+
+    /**
+     * Adds a <code>ChangeListener</code>.
+     * The change listeners are run each
+     * time the expression changes.
+     *
+     * @param l the ChangeListener to add
+     * @see #removeChangeListener
+     */
+    public void addChangeListener(ChangeListener l) {
+        listenerList.add(ChangeListener.class, l);
+        LOG.debug(">>Add listener");
+    }
+
+    /**
+     * Removes a <code>ChangeListener</code>.
+     *
+     * @param l the <code>ChangeListener</code> to remove
+     * @see #addChangeListener
+     */
+    public void removeChangeListener(ChangeListener l) {
+        listenerList.remove(ChangeListener.class, l);
+        LOG.debug(">>Remove listener");
+    }
+
+    /**
+     * Runs each <code>ChangeListener</code>'s
+     * <code>stateChanged</code> method.
+     *
+     * @see #setRangeProperties
+     * @see EventListenerList
+     */
+    protected void fireStateChanged() {
+       LOG.debug(">>Fire state changed to listeners.");
+        Object[] listeners = listenerList.getListenerList();
+        for (int i = listeners.length - 2; i >= 0; i -=2 ) {
+            if (listeners[i] == ChangeListener.class) {
+                if (changeEvent == null) {
+                    changeEvent = new ChangeEvent(this);
+                }
+                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
+            }
         }
-        expression = Model.getDataTypesHelper().setLanguage(expression, lang);
-        expression = Model.getDataTypesHelper().setBody(expression, body);
-        setExpression(expression);
     }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionPanel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionPanel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionPanel.java
     (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpressionPanel.java
     2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2008 The Regents of the University of California. All
+// Copyright (c) 2008-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -27,34 +27,58 @@
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.border.TitledBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 
+import org.apache.log4j.Logger;
 import org.tigris.swidgets.LabelledLayout;
 
 
 /**
+ * The panel that shows an Expression for an other UML element.
+ * There are 8 kinds of Expressions defined in the UML 1.4.2.
  *
  * @author penyaskito
  */
-class UMLExpressionPanel extends JPanel {
+class UMLExpressionPanel extends JPanel
+       implements ChangeListener {
+
+    private static final Logger LOG =
+        Logger.getLogger(UMLExpressionPanel.class);
 
     private final UMLExpressionModel model;
     private final UMLExpressionLanguageField languageField;
     private final UMLExpressionBodyField bodyField;
-    
+
     public UMLExpressionPanel(UMLExpressionModel model, String title) {
-        
+
         super(new LabelledLayout());
+        LOG.debug(">>New Expression panel created");
+
         TitledBorder border = new TitledBorder(title);
-        this.setBorder(border);        
-        
+        this.setBorder(border);
+
         this.model = model;
         this.languageField = new UMLExpressionLanguageField(model,
                 false);
         this.bodyField = new UMLExpressionBodyField(
                 model, true);
-        
-        add(languageField);        
+
+        add(languageField);
         add(new JScrollPane(bodyField));
+
+        model.addChangeListener(this);
+    }
+
+    @Override
+    public void removeNotify() {
+       model.removeChangeListener(this);
+       super.removeNotify();
+    }
+
+    public void stateChanged(ChangeEvent e) {
+       LOG.debug(">>Values shown on panel are changed");
+       bodyField.update();
+       languageField.update();
     }
-    
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLInitialValueExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLInitialValueExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLInitialValueExpressionModel.java
 (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLInitialValueExpressionModel.java
 2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2008 The Regents of the University of California. All
+// Copyright (c) 2008-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -31,13 +31,13 @@
  * @author jaap.branderhorst
  * @author penyaskito
  */
-class UMLInitialValueExpressionModel 
+class UMLInitialValueExpressionModel
     extends UMLExpressionModel {
 
-    
-    
+
+
     public UMLInitialValueExpressionModel(Object target) {
-        super(target, "initial value");
+        super(target, "initialValue");
     }
 
     /**
@@ -45,21 +45,18 @@
      * @see org.argouml.uml.ui.UMLExpressionModel2#getExpression()
      */
     @Override
-    public Object getExpression() {        
-        Object target = null; //TODO getTarget();
+    public Object getExpression() {
+        Object target = getTarget();
         if (target == null) {
             return null;
         }
+        assert Model.getFacade().isAAttribute(target);
         return Model.getFacade().getInitialValue(target);
     }
 
-    /**
-     * @return
-     * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
-     */
     @Override
-    public Object newExpression() {
-        return Model.getDataTypesFactory().createExpression("", "");
+    public Object newExpression(String lang, String body) {
+        return Model.getDataTypesFactory().createExpression(lang, body);
     }
 
     /**
@@ -68,7 +65,11 @@
      */
     @Override
     public void setExpression(Object expression) {
-        Object target = null; // TODO  getTarget();
+        Object target = getTarget();
+        assert Model.getFacade().isAAttribute(target);
+        assert (expression == null) || 
Model.getFacade().isAExpression(expression);
+        /* If we do not set it to null first, then we get a MDR 
DebugException: */
+        Model.getCoreHelper().setInitialValue(target, null);
         Model.getCoreHelper().setInitialValue(target, expression);
     }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLRecurrenceExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLRecurrenceExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLRecurrenceExpressionModel.java
   (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLRecurrenceExpressionModel.java
   2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2003-2006 The Regents of the University of California. All
+// Copyright (c) 2003-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -26,7 +26,6 @@
 
 import org.apache.log4j.Logger;
 import org.argouml.model.Model;
-import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetManager;
 
 /**
@@ -66,14 +65,15 @@
         if (target == null) {
             throw new IllegalStateException("There is no target");
         }
+        Model.getCommonBehaviorHelper().setRecurrence(target, null);
         Model.getCommonBehaviorHelper().setRecurrence(target, expression);
     }
 
     /*
      * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
      */
-    public Object newExpression() {
+    public Object newExpression(String lang, String body) {
         LOG.debug("new boolean expression");
-        return Model.getDataTypesFactory().createIterationExpression("", "");
+        return Model.getDataTypesFactory().createIterationExpression(lang, 
body);
     }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLScriptExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLScriptExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLScriptExpressionModel.java
       (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLScriptExpressionModel.java
       2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2003-2006 The Regents of the University of California. All
+// Copyright (c) 2003-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -25,10 +25,9 @@
 package org.argouml.core.propertypanels.ui;
 
 import org.argouml.model.Model;
-import org.argouml.ui.targetmanager.TargetEvent;
-import org.argouml.ui.targetmanager.TargetManager;
 
 /**
+ * Model for the ActionExpression that is the script of an Action.
  *
  * @author mkl, penyaskito
  *
@@ -56,14 +55,14 @@
      * @see 
org.argouml.uml.ui.UMLExpressionModel2#setExpression(java.lang.Object)
      */
     public void setExpression(Object expression) {
-        Model.getCommonBehaviorHelper()
-               .setScript(getTarget(), expression);
+       Model.getCommonBehaviorHelper().setScript(getTarget(), null);
+       Model.getCommonBehaviorHelper().setScript(getTarget(), expression);
     }
 
     /*
      * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
      */
-    public Object newExpression() {
-        return Model.getDataTypesFactory().createActionExpression("", "");
+    public Object newExpression(String lang, String body) {
+        return Model.getDataTypesFactory().createActionExpression(lang, body);
     }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTimeExpressionModel.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTimeExpressionModel.java?view=diff&pathrev=17560&r1=17559&r2=17560
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTimeExpressionModel.java
 (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTimeExpressionModel.java
 2009-11-29 22:56:31-0800
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2003-2006 The Regents of the University of California. All
+// Copyright (c) 2003-2009 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -26,7 +26,6 @@
 
 import org.apache.log4j.Logger;
 import org.argouml.model.Model;
-import org.argouml.ui.targetmanager.TargetEvent;
 import org.argouml.ui.targetmanager.TargetManager;
 
 /**
@@ -64,30 +63,17 @@
         if (target == null) {
             throw new IllegalStateException("There is no target");
         }
+        /* If we do not set it to null first, then we get a MDR 
DebugException: */
+        Model.getStateMachinesHelper().setWhen(target, null);
         Model.getStateMachinesHelper().setWhen(target, expression);
     }
 
     /*
      * @see org.argouml.uml.ui.UMLExpressionModel2#newExpression()
      */
-    public Object newExpression() {
+    public Object newExpression(String lang, String body) {
         LOG.debug("new time expression");
-        return Model.getDataTypesFactory().createTimeExpression("", "");
-    }
-
-    public void targetAdded(TargetEvent e) {
-        // TODO: Auto-generated method stub
-        
-    }
-
-    public void targetRemoved(TargetEvent e) {
-        // TODO: Auto-generated method stub
-        
-    }
-
-    public void targetSet(TargetEvent e) {
-        // TODO: Auto-generated method stub
-        
+        return Model.getDataTypesFactory().createTimeExpression(lang, body);
     }
 
 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2425344

To unsubscribe from this discussion, e-mail: 
[[email protected]].

Reply via email to