Author: mvw Date: 2008-02-28 08:48:41-0800 New Revision: 14161 Modified: trunk/src/app/src/org/argouml/uml/diagram/Relocatable.java trunk/src/app/src/org/argouml/uml/diagram/activity/ui/UMLActivityDiagram.java trunk/src/app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java trunk/src/app/src/org/argouml/uml/diagram/deployment/ui/UMLDeploymentDiagram.java trunk/src/app/src/org/argouml/uml/diagram/sequence/ui/UMLSequenceDiagram.java trunk/src/app/src/org/argouml/uml/diagram/state/ui/UMLStateDiagram.java trunk/src/app/src/org/argouml/uml/diagram/static_structure/ui/UMLClassDiagram.java trunk/src/app/src/org/argouml/uml/diagram/ui/PropPanelDiagram.java trunk/src/app/src/org/argouml/uml/diagram/use_case/ui/UMLUseCaseDiagram.java trunk/src/app/src/org/argouml/uml/ui/UMLComboBoxModel2.java
Log: Fix for issue 1860: This patch also allows diagrams to be moved from the properties panel. Modified: trunk/src/app/src/org/argouml/uml/diagram/Relocatable.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/Relocatable.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/Relocatable.java&p2=trunk/src/app/src/org/argouml/uml/diagram/Relocatable.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/Relocatable.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/Relocatable.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 2005-2007 The Regents of the University of California. All +// Copyright (c) 2005-2008 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,6 +24,8 @@ package org.argouml.uml.diagram; +import java.util.Collection; + /** * Interface which is used by the Explorer to determine if a diagram can * change its location to a new model element. @@ -55,4 +57,16 @@ */ boolean relocate(Object base); + /** + * Create a collection of candidate modelelements + * to relocate this diagram to. + * All candidates belong to a given namespace - e.g. the root Model. + * + * @param root all returned candidates are contained in this namespace + * @return the collection of candidate modelelements + * to which this diagram may be relocated + */ + @SuppressWarnings("unchecked") + Collection getRelocationCandidates(Object root); + } Modified: trunk/src/app/src/org/argouml/uml/diagram/activity/ui/UMLActivityDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/activity/ui/UMLActivityDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/activity/ui/UMLActivityDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/activity/ui/UMLActivityDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/activity/ui/UMLActivityDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/activity/ui/UMLActivityDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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,8 +27,10 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -638,6 +640,15 @@ // .isAddingActivityGraphAllowed(base); } + @SuppressWarnings("unchecked") + public Collection getRelocationCandidates(Object root) { + /* TODO: We may return something useful when the + * relocate() has been implemented. */ + Collection c = new HashSet(); + c.add(getOwner()); + return c; + } + /* * @see org.argouml.uml.diagram.ui.UMLDiagram#relocate(java.lang.Object) */ Modified: trunk/src/app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/collaboration/ui/UMLCollaborationDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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,6 +26,7 @@ import java.beans.PropertyVetoException; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; import javax.swing.Action; @@ -410,6 +411,15 @@ return false; } + @SuppressWarnings("unchecked") + public Collection getRelocationCandidates(Object root) { + /* TODO: We may return something useful when the + * relocate() has been implemented. */ + Collection c = new HashSet(); + c.add(getOwner()); + return c; + } + public void encloserChanged(FigNode enclosed, FigNode oldEncloser, FigNode newEncloser) { // Do nothing. Modified: trunk/src/app/src/org/argouml/uml/diagram/deployment/ui/UMLDeploymentDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/deployment/ui/UMLDeploymentDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/deployment/ui/UMLDeploymentDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/deployment/ui/UMLDeploymentDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/deployment/ui/UMLDeploymentDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/deployment/ui/UMLDeploymentDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 2003-2007 The Regents of the University of California. All +// Copyright (c) 2003-2008 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 @@ -459,6 +459,13 @@ return Model.getFacade().isAPackage(base); } + @SuppressWarnings("unchecked") + public Collection getRelocationCandidates(Object root) { + return + Model.getModelManagementHelper().getAllModelElementsOfKindWithModel( + root, Model.getMetaTypes().getPackage()); + } + /* * @see org.argouml.uml.diagram.ui.UMLDiagram#relocate(java.lang.Object) */ Modified: trunk/src/app/src/org/argouml/uml/diagram/sequence/ui/UMLSequenceDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/sequence/ui/UMLSequenceDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/sequence/ui/UMLSequenceDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/sequence/ui/UMLSequenceDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/sequence/ui/UMLSequenceDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/sequence/ui/UMLSequenceDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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,6 +25,8 @@ package org.argouml.uml.diagram.sequence.ui; import java.beans.PropertyVetoException; +import java.util.Collection; +import java.util.HashSet; import java.util.Hashtable; import org.argouml.i18n.Translator; @@ -175,17 +177,22 @@ */ } - @Override public boolean isRelocationAllowed(Object base) { return false; - /* TODO: We may return the following when the + /* TODO: We may return something useful when the * relocate() has been implemented. */ -// Model.getFacade().isAClassifier(base) -// || Model.getFacade().isAOperation(base); } + @SuppressWarnings("unchecked") + public Collection getRelocationCandidates(Object root) { + /* TODO: We may return something useful when the + * relocate() has been implemented. */ + Collection c = new HashSet(); + c.add(getOwner()); + return c; + } @Override public boolean relocate(Object base) { Modified: trunk/src/app/src/org/argouml/uml/diagram/state/ui/UMLStateDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/state/ui/UMLStateDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/state/ui/UMLStateDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/state/ui/UMLStateDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/state/ui/UMLStateDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/state/ui/UMLStateDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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,6 +26,8 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; +import java.util.Collection; +import java.util.HashSet; import javax.swing.Action; @@ -703,6 +705,16 @@ // .isAddingStatemachineAllowed(base); } + @SuppressWarnings("unchecked") + public Collection getRelocationCandidates(Object root) { + /* TODO: We may return something useful when the + * relocate() has been implemented, like + * all StateMachines that are not ActivityGraphs. */ + Collection c = new HashSet(); + c.add(getOwner()); + return c; + } + /* * @see org.argouml.uml.diagram.ui.UMLDiagram#relocate(java.lang.Object) */ Modified: trunk/src/app/src/org/argouml/uml/diagram/static_structure/ui/UMLClassDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/static_structure/ui/UMLClassDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/static_structure/ui/UMLClassDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/static_structure/ui/UMLClassDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/static_structure/ui/UMLClassDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/static_structure/ui/UMLClassDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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,6 +25,7 @@ package org.argouml.uml.diagram.static_structure.ui; import java.beans.PropertyVetoException; +import java.util.Collection; import javax.swing.Action; @@ -579,6 +580,13 @@ return Model.getFacade().isANamespace(base); } + @SuppressWarnings("unchecked") + public Collection getRelocationCandidates(Object root) { + return + Model.getModelManagementHelper().getAllModelElementsOfKindWithModel( + root, Model.getMetaTypes().getNamespace()); + } + /* * @see org.argouml.uml.diagram.ui.UMLDiagram#relocate(java.lang.Object) */ Modified: trunk/src/app/src/org/argouml/uml/diagram/ui/PropPanelDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/ui/PropPanelDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/ui/PropPanelDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/ui/PropPanelDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/ui/PropPanelDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/ui/PropPanelDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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,22 +24,28 @@ package org.argouml.uml.diagram.ui; +import static org.argouml.model.Model.getModelManagementFactory; + import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import javax.swing.DefaultListModel; import javax.swing.ImageIcon; +import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JTextField; import org.argouml.i18n.Translator; -import org.argouml.ui.targetmanager.TargetEvent; -import org.argouml.ui.targetmanager.TargetListener; +import org.argouml.ui.UndoableAction; import org.argouml.ui.targetmanager.TargetManager; import org.argouml.uml.diagram.ArgoDiagram; +import org.argouml.uml.diagram.Relocatable; import org.argouml.uml.ui.AbstractActionNavigate; import org.argouml.uml.ui.ActionDeleteModelElements; import org.argouml.uml.ui.PropPanel; +import org.argouml.uml.ui.UMLComboBox2; +import org.argouml.uml.ui.UMLComboBoxModel2; +import org.argouml.uml.ui.UMLComboBoxNavigator; +import org.argouml.uml.ui.UMLSearchableComboBox; /** * This class represents the properties panel for a Diagram. @@ -47,6 +53,10 @@ */ public class PropPanelDiagram extends PropPanel { + private JComboBox homeModelSelector; + private UMLDiagramHomeModelComboBoxModel homeModelComboBoxModel = + new UMLDiagramHomeModelComboBoxModel(); + /** * Construct a property panel with a given name and icon. * @@ -58,10 +68,9 @@ JTextField field = new JTextField(); field.getDocument().addDocumentListener(new DiagramNameDocument(field)); - addField(Translator.localize("label.name"), field); + addField("label.name", field); - addField(Translator.localize("label.home-model"), - getSingleRowScroll(new UMLDiagramHomeModelListModel())); + addField("label.home-model", getHomeModelSelector()); addAction(new ActionNavigateUpFromDiagram()); addAction(ActionDeleteModelElements.getTargetFollower()); @@ -75,6 +84,99 @@ this("Diagram", null); } + /** + * Returns the home-model selector. This is a component which allows the + * user to select a single item as the home-model, + * i.e. the "owner" of the diagram. + * + * @return a component for selecting the home-model + */ + protected JComponent getHomeModelSelector() { + if (homeModelSelector == null) { + homeModelSelector = new UMLSearchableComboBox( + homeModelComboBoxModel, + new ActionSetDiagramHomeModel(), true); + } + return new UMLComboBoxNavigator( + Translator.localize("label.namespace.navigate.tooltip"), + homeModelSelector); + } + +} + +class UMLDiagramHomeModelComboBoxModel extends UMLComboBoxModel2 { + + public UMLDiagramHomeModelComboBoxModel() { + super(ArgoDiagram.NAMESPACE_KEY, false); + } + + @Override + protected void buildModelList() { + Object t = getTarget(); + removeAllElements(); + if (t instanceof Relocatable) { + Relocatable diagram = (Relocatable) t; + for (Object obj : diagram.getRelocationCandidates( + getModelManagementFactory().getRootModel())) { + if (diagram.isRelocationAllowed(obj)) { + addElement(obj); + } + } + } + /* This should not be needed if the above is correct, + * but let's be sure: */ + addElement(getSelectedModelElement()); + } + + @Override + protected Object getSelectedModelElement() { + Object t = getTarget(); + if (t instanceof ArgoDiagram) { + return ((ArgoDiagram) t).getOwner(); + } + return null; + } + + @Override + protected boolean isValidElement(Object element) { + Object t = getTarget(); + if (t instanceof Relocatable) { + return ((Relocatable) t).isRelocationAllowed(element); + } + return false; + } + + /** + * @param evt + * @see org.argouml.uml.ui.UMLComboBoxModel2#propertyChange(java.beans.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent evt) { + // TODO: Auto-generated method stub + super.propertyChange(evt); + } + +} + +class ActionSetDiagramHomeModel extends UndoableAction { + protected ActionSetDiagramHomeModel() { + super(); + } + + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source instanceof UMLComboBox2) { + UMLComboBox2 box = (UMLComboBox2) source; + Object diagram = box.getTarget(); + Object homeModel = box.getSelectedItem(); + if (diagram instanceof Relocatable) { + Relocatable d = (Relocatable) diagram; + if (d.isRelocationAllowed(homeModel)) { + d.relocate(homeModel); + } + } + } + } } class ActionNavigateUpFromDiagram extends AbstractActionNavigate { @@ -116,73 +218,3 @@ } } } - -/** - * The list model for the "homeModel" of a diagram. - * - * @author [EMAIL PROTECTED] - */ -class UMLDiagramHomeModelListModel - extends DefaultListModel - implements TargetListener, PropertyChangeListener { - - private static ArgoDiagram oldTarget = null; - /** - * Constructor for UMLCommentAnnotatedElementListModel. - */ - public UMLDiagramHomeModelListModel() { - super(); - setTarget(TargetManager.getInstance().getTarget()); - TargetManager.getInstance().addTargetListener(this); - } - - /* - * @see TargetListener#targetAdded(TargetEvent) - */ - public void targetAdded(TargetEvent e) { - setTarget(e.getNewTarget()); - } - - /* - * @see TargetListener#targetRemoved(TargetEvent) - */ - public void targetRemoved(TargetEvent e) { - setTarget(e.getNewTarget()); - } - - /* - * @see TargetListener#targetSet(TargetEvent) - */ - public void targetSet(TargetEvent e) { - setTarget(e.getNewTarget()); - } - - private void setTarget(Object t) { - if (oldTarget != null) { - oldTarget.removePropertyChangeListener( - ArgoDiagram.NAMESPACE_KEY, this); - } - - ArgoDiagram target = null; - if (t instanceof ArgoDiagram) { - target = (ArgoDiagram) t; - oldTarget = target; - target.addPropertyChangeListener( - ArgoDiagram.NAMESPACE_KEY, this); - } - removeAllElements(); - - Object ns = null; - if (target != null) { - ns = target.getOwner(); - } - if (ns != null) { - addElement(ns); - } - } - - public void propertyChange(PropertyChangeEvent evt) { - removeAllElements(); - addElement(evt.getNewValue()); - } -} Modified: trunk/src/app/src/org/argouml/uml/diagram/use_case/ui/UMLUseCaseDiagram.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/diagram/use_case/ui/UMLUseCaseDiagram.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/diagram/use_case/ui/UMLUseCaseDiagram.java&p2=trunk/src/app/src/org/argouml/uml/diagram/use_case/ui/UMLUseCaseDiagram.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/diagram/use_case/ui/UMLUseCaseDiagram.java (original) +++ trunk/src/app/src/org/argouml/uml/diagram/use_case/ui/UMLUseCaseDiagram.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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,6 +25,8 @@ package org.argouml.uml.diagram.use_case.ui; import java.beans.PropertyVetoException; +import java.util.Collection; +import java.util.HashSet; import javax.swing.Action; @@ -50,6 +52,8 @@ * Defines the toolbar, provides for its initialization and provides * constructors for a top level diagram and one within a defined * namespace.<p> + * + * A use case diagram has as owner either a package or a classifier. */ public class UMLUseCaseDiagram extends UMLDiagram { @@ -440,6 +444,21 @@ return true; } + /* + * Allow all Packages and Classifiers.. + */ + @SuppressWarnings("unchecked") + public Collection getRelocationCandidates(Object root) { + Collection c = new HashSet(); + c.add(Model.getModelManagementHelper() + .getAllModelElementsOfKindWithModel(root, + Model.getMetaTypes().getPackage())); + c.add(Model.getModelManagementHelper() + .getAllModelElementsOfKindWithModel(root, + Model.getMetaTypes().getClassifier())); + return c; + } + public void encloserChanged(FigNode enclosed, FigNode oldEncloser, FigNode newEncloser) { // Do nothing. Modified: trunk/src/app/src/org/argouml/uml/ui/UMLComboBoxModel2.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/app/src/org/argouml/uml/ui/UMLComboBoxModel2.java?view=diff&rev=14161&p1=trunk/src/app/src/org/argouml/uml/ui/UMLComboBoxModel2.java&p2=trunk/src/app/src/org/argouml/uml/ui/UMLComboBoxModel2.java&r1=14160&r2=14161 ============================================================================== --- trunk/src/app/src/org/argouml/uml/ui/UMLComboBoxModel2.java (original) +++ trunk/src/app/src/org/argouml/uml/ui/UMLComboBoxModel2.java 2008-02-28 08:48:41-0800 @@ -1,5 +1,5 @@ // $Id$ -// Copyright (c) 1996-2007 The Regents of the University of California. All +// Copyright (c) 1996-2008 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 @@ -43,7 +43,7 @@ import org.argouml.model.RemoveAssociationEvent; import org.argouml.ui.targetmanager.TargetEvent; import org.argouml.ui.targetmanager.TargetListener; -import org.tigris.gef.base.Diagram; +import org.argouml.uml.diagram.ArgoDiagram; import org.tigris.gef.presentation.Fig; /** @@ -178,6 +178,17 @@ } } } + else if (evt.getSource() instanceof ArgoDiagram + && evt.getPropertyName().equals(propertySetName)) { + /* This should not be necessary, but let's be sure: */ + addElement(evt.getNewValue()); + /* TODO: MVW: for this case, I have to move the + * call to setSelectedItem() outside the "buildingModel", otherwise + * the combo does not update with the new selection. + * Does the same not apply in the cases above? */ + buildingModel = false; + setSelectedItem(evt.getNewValue()); + } buildingModel = false; } @@ -336,14 +347,20 @@ theNewTarget = theNewTarget instanceof Fig ? ((Fig) theNewTarget).getOwner() : theNewTarget; if (Model.getFacade().isAModelElement(theNewTarget) - || theNewTarget instanceof Diagram) { + || theNewTarget instanceof ArgoDiagram) { + + /* Remove old listeners: */ if (Model.getFacade().isAModelElement(comboBoxTarget)) { Model.getPump().removeModelEventListener(this, comboBoxTarget, propertySetName); // Allow listening to other elements: removeOtherModelEventListeners(comboBoxTarget); + } else if (comboBoxTarget instanceof ArgoDiagram) { + ((ArgoDiagram) comboBoxTarget).removePropertyChangeListener( + ArgoDiagram.NAMESPACE_KEY, this); } + /* Add new listeners: */ if (Model.getFacade().isAModelElement(theNewTarget)) { comboBoxTarget = theNewTarget; Model.getPump().addModelEventListener(this, comboBoxTarget, @@ -367,9 +384,20 @@ if (getSize() > 0) { fireIntervalAdded(this, 0, getSize() - 1); } - } else { + } else if (theNewTarget instanceof ArgoDiagram) { + comboBoxTarget = theNewTarget; + ArgoDiagram diagram = (ArgoDiagram) theNewTarget; + diagram.addPropertyChangeListener( + ArgoDiagram.NAMESPACE_KEY, this); + buildingModel = true; + buildModelList(); + setSelectedItem(getSelectedModelElement()); + buildingModel = false; + if (getSize() > 0) { + fireIntervalAdded(this, 0, getSize() - 1); + } + } else { /* MVW: This can never happen, isn't it? */ comboBoxTarget = null; - removeAllElements(); } if (getSelectedItem() != null && isClearable) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
