svn commit: r17622 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Bob Tarling <[email protected]>
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: bobtarling
Date: 2009-12-10 03:34:19-0800
New Revision: 17622
Modified:
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Log:
First attempt to keep selected item elected during move - work in progress
Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java?view=diff&pathrev=17622&r1=17621&r2=17622
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java (original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java 2009-12-10 03:34:19-0800
@@ -46,6 +46,8 @@
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.ListModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.TreeUI;
@@ -75,7 +77,7 @@
* @since 0.29.2
*/
class RowSelector extends JPanel
- implements MouseListener, ContainerListener {
+ implements MouseListener, ContainerListener, ListDataListener {
/**
* The logger
@@ -97,6 +99,9 @@
*/
private static Icon collapsedIcon;
+ /**
+ * The model element that is the target of this control
+ */
private final Object target;
static {
@@ -146,6 +151,16 @@
* The current expanded state
*/
private boolean expanded = false;
+
+ /**
+ * The model element that is being moved. This is used because move
+ * effectively removes the selected model element and then adds it in a
+ * new place.
+ * The problem to the user is that when added the selection is lost.
+ * By recording the model element being moved the add event can detected
+ * when the element is added and mark it as selected.
+ */
+ private Object movedModelElement;
/**
* The label that contains the +/- symbol to indicate
@@ -198,12 +213,14 @@
*/
public RowSelector(UMLModelElementListModel model, boolean expanded, boolean expandable) {
super(new BorderLayout());
-
+
this.expandable = expandable;
target = model.getTarget();
Object metaType = model.getMetaType();
+ LOG.info("Creating list for " + target);
+
LOG.info("model = " + model.getClass().getName());
LOG.info("metatype = " + metaType);
LOG.info("target = " + target);
@@ -291,6 +308,8 @@
getList().addListSelectionListener(moveTopAction);
getList().addListSelectionListener(moveBottomAction);
}
+
+ getModel().addListDataListener(this);
addContainerListener(this);
}
@@ -399,6 +418,7 @@
}
this.removeMouseListener(this);
this.removeContainerListener(this);
+ getModel().removeListDataListener(this);
}
@@ -440,6 +460,22 @@
private ListModel getModel() {
return (ListModel) scroll.getList().getModel();
}
+
+
+ @Override
+ public void contentsChanged(ListDataEvent e) {
+ }
+ @Override
+ public void intervalAdded(ListDataEvent e) {
+ if (e.getIndex0() == e.getIndex1()
+ && getModel().getElementAt(e.getIndex0()) == movedModelElement) {
+ getList().setSelectedValue(movedModelElement, true);
+ movedModelElement = null;
+ }
+ }
+ @Override
+ public void intervalRemoved(ListDataEvent e) {
+ }
/**
* This action deletes the model elements that are selected in the JList
@@ -493,9 +529,9 @@
}
}
- Project p = ProjectManager.getManager().getCurrentProject();
- Object[] targets = getList().getSelectedValues();
- p.moveToTrash(Arrays.asList(targets));
+ final Project p = ProjectManager.getManager().getCurrentProject();
+ final Object[] selectedValues = getList().getSelectedValues();
+ p.moveToTrash(Arrays.asList(selectedValues));
}
}
@@ -533,7 +569,11 @@
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
- Model.getUmlHelper().move(target, getList().getSelectedValues()[0], UmlHelper.Direction.UP);
+ movedModelElement = getList().getSelectedValues()[0];
+ Model.getUmlHelper().move(
+ target,
+ movedModelElement,
+ UmlHelper.Direction.UP);
}
}
@@ -573,7 +613,11 @@
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
- Model.getUmlHelper().move(target, getList().getSelectedValues()[0], UmlHelper.Direction.DOWN);
+ movedModelElement = getList().getSelectedValues()[0];
+ Model.getUmlHelper().move(
+ target,
+ movedModelElement,
+ UmlHelper.Direction.DOWN);
}
}
@@ -612,7 +656,11 @@
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
- Model.getUmlHelper().move(target, getList().getSelectedValues()[0], UmlHelper.Direction.TOP);
+ movedModelElement = getList().getSelectedValues()[0];
+ Model.getUmlHelper().move(
+ target,
+ movedModelElement,
+ UmlHelper.Direction.TOP);
}
}
@@ -652,7 +700,11 @@
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
- Model.getUmlHelper().move(target, getList().getSelectedValues()[0], UmlHelper.Direction.BOTTOM);
+ movedModelElement = getList().getSelectedValues()[0];
+ Model.getUmlHelper().move(
+ target,
+ movedModelElement,
+ UmlHelper.Direction.BOTTOM);
}
}
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2429165
To unsubscribe from this discussion, e-mail: [[email protected]].