Author: bobtarling
Date: 2008-08-10 13:59:22-0700
New Revision: 15538
Modified:
trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBox2.java
trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java
trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java
Log:
Issue 5298: Lazy load the namespace combo
Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBox2.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBox2.java?view=diff&rev=15538&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBox2.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBox2.java&r1=15537&r2=15538
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBox2.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBox2.java 2008-08-10 13:59:22-0700
@@ -28,7 +28,10 @@
import javax.swing.Action;
import javax.swing.JComboBox;
+import javax.swing.event.PopupMenuEvent;
+import javax.swing.event.PopupMenuListener;
+import org.apache.log4j.Logger;
import org.argouml.ui.LookAndFeelMgr;
import org.argouml.ui.targetmanager.TargetEvent;
import org.argouml.ui.targetmanager.TargetListener;
@@ -44,35 +47,40 @@
* replaced with this implementation to improve performance.
*/
public class UMLComboBox2
- extends JComboBox implements TargettableModelView, TargetListener {
+ extends JComboBox
+ implements TargettableModelView, TargetListener {
+ private static final Logger LOG = Logger.getLogger(UMLComboBox2.class);
+
/**
* Constructor for UMLComboBox2.
* @deprecated As of ArgoUml version unknown (before 0.13.5),
* replaced by {@link #UMLComboBox2(UMLComboBoxModel2, Action, boolean)}
- * @param arg0 the ComboBoxModel
+ * @param model the ComboBoxModel
*/
@Deprecated
- protected UMLComboBox2(UMLComboBoxModel2 arg0) {
- super(arg0);
+ protected UMLComboBox2(UMLComboBoxModel2 model) {
+ super(model);
setFont(LookAndFeelMgr.getInstance().getStandardFont());
addActionListener(this);
+ addPopupMenuListener(model);
}
/**
* Constructor for UMLComboBox2. Via the given action, the
* action for this combobox is done.
- * @param arg0 the ComboBoxModel
+ * @param model the ComboBoxModel
* @param action the action
* @param showIcon true if an icon should be shown in front of the items
*/
- public UMLComboBox2(UMLComboBoxModel2 arg0, Action action,
+ public UMLComboBox2(UMLComboBoxModel2 model, Action action,
boolean showIcon) {
- super(arg0);
+ super(model);
setFont(LookAndFeelMgr.getInstance().getStandardFont());
addActionListener(action);
// setDoubleBuffered(true);
setRenderer(new UMLListCellRenderer2(showIcon));
+ addPopupMenuListener(model);
}
/**
Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java?view=diff&rev=15538&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java&r1=15537&r2=15538
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java 2008-08-10 13:59:22-0700
@@ -32,6 +32,9 @@
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.event.PopupMenuEvent;
+import javax.swing.event.PopupMenuListener;
import org.apache.log4j.Logger;
import org.argouml.model.AddAssociationEvent;
@@ -53,7 +56,8 @@
* at construction time of this class. I.e. it is "clearable".
*/
public abstract class UMLComboBoxModel2 extends AbstractListModel
- implements PropertyChangeListener, ComboBoxModel, TargetListener {
+ implements PropertyChangeListener,
+ ComboBoxModel, TargetListener, PopupMenuListener {
/**
* Logger.
*/
@@ -99,6 +103,12 @@
* Flag to indicate whether the model is being build.
*/
protected boolean buildingModel = false;
+
+ /**
+ * Flag needed to prevent a loop
+ */
+ private boolean willBecomeVisible = false;
+
/**
* Constructs a model for a combobox. The container given is used
@@ -207,7 +217,7 @@
* selected item if there is one. Called from targetChanged every time the
* target of the proppanel is changed.
*/
- protected abstract void buildModelList();
+ abstract protected void buildModelList();
/**
* @param obj an UML object
@@ -374,7 +384,8 @@
buildingModel = true;
try {
- buildModelList();
+ LOG.info("Building the combo box model for " + this);
+ buildMinimalModelList();
// Do not set buildingModel = false here,
// otherwise the action for selection is performed.
setSelectedItem(getSelectedModelElement());
@@ -394,6 +405,7 @@
diagram.addPropertyChangeListener(
ArgoDiagram.NAMESPACE_KEY, this);
buildingModel = true;
+ LOG.info("Building the combo box model for " + this);
buildModelList();
setSelectedItem(getSelectedModelElement());
buildingModel = false;
@@ -409,6 +421,16 @@
}
}
}
+
+ /**
+ * Build the minimal number of items in the model for the edit box
+ * to be populated. By default this calls buildModelList but it
+ * can be overridden in subclasses to delay population of the list
+ * till the list is displayed.
+ */
+ protected void buildMinimalModelList() {
+ buildModelList();
+ }
/**
* This function allows subclasses to listen to more modelelements.
@@ -686,5 +708,31 @@
protected void setFireListEvents(boolean events) {
this.fireListEvents = events;
}
+
+ boolean isLazy() {
+ return false;
+ }
+
+ public void popupMenuCanceled(PopupMenuEvent e) {
+ LOG.info("popupMenuCanceled");
+ }
+
+ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
+ LOG.info("popupMenuWillBecomeInvisible");
+ }
+
+ public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
+ if (isLazy() && !willBecomeVisible) {
+ JComboBox list = (JComboBox) ev.getSource();
+ buildModelList();
+
+ willBecomeVisible = true; // the flag is needed to prevent a loop
+ try {
+ list.getUI().setPopupVisible( list, true );
+ } finally {
+ willBecomeVisible = false;
+ }
+ }
+ }
}
Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java?view=diff&rev=15538&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java&r1=15537&r2=15538
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java (original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java 2008-08-10 13:59:22-0700
@@ -25,6 +25,7 @@
package org.argouml.uml.ui.foundation.core;
import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
import java.util.Collection;
import org.apache.log4j.Logger;
@@ -47,6 +48,11 @@
Logger.getLogger(UMLModelElementNamespaceComboBoxModel.class);
/**
+ * The UID.
+ */
+ private static final long serialVersionUID = -775116993155949065L;
+
+ /**
* Constructor for UMLModelElementNamespaceComboBoxModel.
*/
public UMLModelElementNamespaceComboBoxModel() {
@@ -66,6 +72,22 @@
/*
* @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList()
*/
+ protected void buildMinimalModelList() {
+ Object target = getTarget();
+ Collection c = new ArrayList(1);
+
+ if (target != null) {
+ Object namespace = Model.getFacade().getNamespace(target);
+ if (namespace != null && !c.contains(namespace)) {
+ c.add(namespace);
+ }
+ }
+ setElements(c);
+ }
+
+ /*
+ * @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList()
+ */
protected void buildModelList() {
Object model =
ProjectManager.getManager().getCurrentProject().getRoot();
@@ -115,12 +137,12 @@
* the selected item differs. Without the next step,
* the combo would not be refreshed.
*/
+ buildMinimalModelList();
setSelectedItem(getSelectedModelElement());
}
}
-
- /**
- * The UID.
- */
- private static final long serialVersionUID = -775116993155949065L;
+
+ boolean isLazy() {
+ return true;
+ }
}
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.