svn commit: r17524 - 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-11-23 04:24:34-0800
New Revision: 17524
Modified:
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Log:
Add controls for Move Up/Down/Top/Bottom - not actually operating as yet.
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=17524&r1=17523&r2=17524
==============================================================================
--- 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-11-23 04:24:34-0800
@@ -45,6 +45,7 @@
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.JTree;
+import javax.swing.ListModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.TreeUI;
@@ -53,6 +54,7 @@
import org.apache.log4j.Logger;
import org.argouml.application.helpers.ResourceLoaderWrapper;
+import org.argouml.i18n.Translator;
import org.argouml.kernel.Project;
import org.argouml.kernel.ProjectManager;
import org.argouml.model.Model;
@@ -159,6 +161,26 @@
private final DeleteAction deleteAction;
/**
+ * The delete action that we must enable/disable
+ */
+ private final MoveUpAction moveUpAction;
+
+ /**
+ * The delete action that we must enable/disable
+ */
+ private final MoveDownAction moveDownAction;
+
+ /**
+ * The delete action that we must enable/disable
+ */
+ private final MoveTopAction moveTopAction;
+
+ /**
+ * The delete action that we must enable/disable
+ */
+ private final MoveBottomAction moveBottomAction;
+
+ /**
* Constructor
* @param model The single item list model
*/
@@ -204,6 +226,10 @@
expander = null;
tb = null;
deleteAction = null;
+ moveUpAction = null;
+ moveDownAction = null;
+ moveTopAction = null;
+ moveBottomAction = null;
} else {
// Create actions and expander if we have multiple rows
final ArrayList<Action> actions = new ArrayList<Action>(2);
@@ -218,6 +244,22 @@
deleteAction = new DeleteAction();
actions.add(deleteAction);
+ if (getModel() instanceof UMLModelElementOrderedListModel) {
+ moveUpAction = new MoveUpAction();
+ moveDownAction = new MoveDownAction();
+ moveTopAction = new MoveTopAction();
+ moveBottomAction = new MoveBottomAction();
+ actions.add(moveUpAction);
+ actions.add(moveDownAction);
+ actions.add(moveTopAction);
+ actions.add(moveBottomAction);
+ } else {
+ moveUpAction = null;
+ moveDownAction = null;
+ moveTopAction = null;
+ moveBottomAction = null;
+ }
+
final ToolBarFactory tbf = new ToolBarFactory(actions);
tb = tbf.createToolBar();
tb.setRollover(true);
@@ -235,7 +277,17 @@
}
add(buttonPanel, BorderLayout.WEST);
- scroll.getList().addListSelectionListener(deleteAction);
+ getList().addListSelectionListener(deleteAction);
+ // TODO: We should really test the model instead for this
+ // but we have no API yet.
+ // Can we just check if the collection to build the JList
+ // control implements the List interface?
+ if (getModel() instanceof UMLModelElementOrderedListModel) {
+ getList().addListSelectionListener(moveUpAction);
+ getList().addListSelectionListener(moveDownAction);
+ getList().addListSelectionListener(moveTopAction);
+ getList().addListSelectionListener(moveBottomAction);
+ }
addContainerListener(this);
}
@@ -342,7 +394,13 @@
*/
@Override
public void componentRemoved(ContainerEvent event) {
- scroll.getList().removeListSelectionListener(deleteAction);
+ getList().removeListSelectionListener(deleteAction);
+ if (moveUpAction != null) {
+ getList().removeListSelectionListener(moveUpAction);
+ getList().removeListSelectionListener(moveDownAction);
+ getList().removeListSelectionListener(moveTopAction);
+ getList().removeListSelectionListener(moveBottomAction);
+ }
this.removeMouseListener(this);
this.removeContainerListener(this);
}
@@ -368,6 +426,10 @@
return scroll.getList();
}
+ private ListModel getModel() {
+ return (ListModel) scroll.getList().getModel();
+ }
+
/**
* This action deletes the model elements that are selected in the JList
*/
@@ -381,7 +443,7 @@
@Override
public void valueChanged(ListSelectionEvent e) {
- setEnabled(scroll.getList().getSelectedIndex() > -1);
+ setEnabled(getList().getSelectedIndex() > -1);
}
/*
@@ -409,8 +471,104 @@
}
Project p = ProjectManager.getManager().getCurrentProject();
- Object[] targets = scroll.getList().getSelectedValues();
+ Object[] targets = getList().getSelectedValues();
p.moveToTrash(Arrays.asList(targets));
}
}
+
+ /**
+ * This action deletes the model elements that are selected in the JList
+ */
+ private class MoveUpAction extends UndoableAction implements ListSelectionListener {
+
+ MoveUpAction() {
+ super(Translator.localize("menu.popup.moveup"),
+ ResourceLoaderWrapper.lookupIconResource("MoveUp"));
+ setEnabled(false);
+ }
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ setEnabled(getList().getSelectedIndex() > -1);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ super.actionPerformed(e);
+ //
+ }
+ }
+
+
+ /**
+ * This action deletes the model elements that are selected in the JList
+ */
+ private class MoveDownAction extends UndoableAction implements ListSelectionListener {
+
+ MoveDownAction() {
+ super(Translator.localize("menu.popup.movedown"),
+ ResourceLoaderWrapper.lookupIconResource("MoveDown"));
+ setEnabled(false);
+ }
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ setEnabled(getList().getSelectedIndex() > -1);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ super.actionPerformed(e);
+ //
+ }
+ }
+
+
+ /**
+ * This action deletes the model elements that are selected in the JList
+ */
+ private class MoveTopAction extends UndoableAction implements ListSelectionListener {
+
+ MoveTopAction() {
+ super(Translator.localize("menu.popup.movetop"),
+ ResourceLoaderWrapper.lookupIconResource("MoveTop"));
+ setEnabled(false);
+ }
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ setEnabled(getList().getSelectedIndex() > -1);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ super.actionPerformed(e);
+ //
+ }
+ }
+
+
+ /**
+ * This action deletes the model elements that are selected in the JList
+ */
+ private class MoveBottomAction extends UndoableAction implements ListSelectionListener {
+
+ MoveBottomAction() {
+ super(Translator.localize("menu.popup.movebottom"),
+ ResourceLoaderWrapper.lookupIconResource("MoveBottom"));
+ setEnabled(false);
+ }
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ setEnabled(scroll.getList().getSelectedIndex() > -1);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ super.actionPerformed(e);
+ //
+ }
+ }
+
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2423316
To unsubscribe from this discussion, e-mail: [[email protected]].