Index: actor/gui/PtolemyQuery.java =================================================================== --- actor/gui/PtolemyQuery.java (revision 71666) +++ actor/gui/PtolemyQuery.java (working copy) @@ -535,6 +535,12 @@ // Attach the entry to the attribute by registering a listener. attribute.addValueListener(this); + + // if the attribute is a Variable, set a weak dependency to avoid + // warnings if the attribute changes containers. + if(attribute instanceof Variable) { + ((Variable)attribute).setValueListenerAsWeakDependency(this); + } // Put the attribute in a Map from attribute -> (list of entry names // attached to attribute), but only if entryName is not already Index: data/expr/Variable.java =================================================================== --- data/expr/Variable.java (revision 71666) +++ data/expr/Variable.java (working copy) @@ -816,6 +816,9 @@ if (_valueListeners != null) { _valueListeners.remove(listener); } + if (_weakValueListeners != null) { + _weakValueListeners.remove(listener); + } } /** Reset the variable to its initial value. If the variable was @@ -882,16 +885,26 @@ NameDuplicationException { Nameable previousContainer = getContainer(); + // Warn if there are variables that depend on this one. - if (container != previousContainer && previousContainer != null - && _valueListeners != null && _valueListeners.size() > 0) { - if (!MessageHandler - .yesNoQuestion("WARNING: There are variables depending on " - + getName() + ". Continue?")) { - // Cancel. - throw new IllegalActionException(this, - "Cancelled change of container."); + if (container != previousContainer && previousContainer != null) { + Set listeners = new HashSet(); + if(_valueListeners != null && !_valueListeners.isEmpty()) { + listeners.addAll(_valueListeners); } + if(_weakValueListeners != null && !_weakValueListeners.isEmpty()) { + listeners.removeAll(_weakValueListeners); + } + + if(!listeners.isEmpty()) { + if (!MessageHandler + .yesNoQuestion("WARNING: There are variables depending on " + + getName() + ". Continue?")) { + // Cancel. + throw new IllegalActionException(this, + "Cancelled change of container."); + } + } } super.setContainer(container); @@ -1382,6 +1395,17 @@ _isTokenUnknown = value; } + /** Set a value listener as a weak dependency. When this Variable changes + * containers, the value listener is not considered a dependency. + * @see #setContainer() + */ + public void setValueListenerAsWeakDependency(ValueListener listener) { + if (_weakValueListeners == null) { + _weakValueListeners = new HashSet(); + } + _weakValueListeners.add(listener); + } + /** Set the visibility of this variable. The argument should be one * of the public static instances in Settable. * @param visibility The visibility of this variable. @@ -2536,7 +2560,11 @@ // The visibility of this variable. private Settable.Visibility _visibility = Settable.EXPERT; + + /** Value listeners that should not be treated as true dependencies. */ + private Set _weakValueListeners; + /////////////////////////////////////////////////////////////////// //// inner classes ////