svn commit: r17516 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-11-22 09:12:06-0800
New Revision: 17516

Removed:
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLSingleRowSelector.java
Modified:
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/EnumerationListModel.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ScrollList.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassAttributeListModel.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassOperationListModel.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementOrderedListModel.java

Log:
Provide create and delete actions in toolbar for expanded lists

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/EnumerationListModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/EnumerationListModel.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/EnumerationListModel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/EnumerationListModel.java	2009-11-22 09:12:06-0800
@@ -24,8 +24,6 @@
 
 package org.argouml.core.propertypanels.ui;
 
-import javax.swing.DefaultListModel;
-
 import org.argouml.model.Model;
 
 /**
@@ -33,15 +31,22 @@
  *
  * @author [email protected]
  */
-class EnumerationListModel extends DefaultListModel {
+class EnumerationListModel extends UMLModelElementListModel {
 
     /**
      * Constructor for EnumerationListModel.
      */
     public EnumerationListModel(Object target) {
         super();
-        if (Model.getFacade().isAEnumerationLiteral(target)) {
-            addElement(Model.getFacade().getEnumeration(target));
-        }
+    }
+
+    @Override
+    protected void buildModelList() {
+        addElement(Model.getFacade().getEnumeration(getTarget()));
+    }
+
+    @Override
+    protected boolean isValidElement(Object element) {
+        return Model.getFacade().isAEnumeration(element);
     }
 }

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ScrollList.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ScrollList.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ScrollList.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ScrollList.java	2009-11-22 09:12:06-0800
@@ -50,7 +50,7 @@
  * 
  * @author Bob Tarling
  */
-class ScrollList extends JScrollPane implements KeyListener, MouseListener {
+class ScrollList extends JScrollPane implements KeyListener {
 
     private static final Logger LOG = Logger.getLogger(ScrollList.class);
     
@@ -90,7 +90,6 @@
                     listModel.getRemoveAction());
         }
         setViewportView(list);
-        addListeners();
     }
 
     /**
@@ -106,7 +105,6 @@
         list = new UMLLinkedList(listModel, true, true);
         list.setVisibleRowCount(visibleRowCount);
         setViewportView(list);
-        addListeners();
     }
 
     /**
@@ -121,13 +119,6 @@
                 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
         this.list = (UMLLinkedList) alist;
         setViewportView(list);
-        addListeners();
-    }
-    
-    private void addListeners() {
-        this.addMouseListener(this);
-        list.addMouseListener(this);
-        getVerticalScrollBar().addMouseListener(this);
     }
     
     public ListModel getListModel() {
@@ -168,37 +159,8 @@
         super.removeNotify();
         list.removeKeyListener(this);
     }
-
-    public void mouseClicked(MouseEvent evt) {
-        // TODO Auto-generated method stub
-        
-    }
-
-    public void mouseEntered(MouseEvent evt) {
-//        if (originalHeight == 0) {
-//            originalHeight = getHeight();
-//            final int parentHeight = getParent().getHeight();
-//            setSize(getWidth(), parentHeight - getY());
-//            list.setSize(this.getSize());
-//        }
-    }
-
-    public void mouseExited(MouseEvent evt) {
-//        Rectangle rect = new Rectangle(getLocationOnScreen(), getSize());
-//        if (!rect.contains(evt.getLocationOnScreen())) {
-//            setSize(getWidth(), originalHeight);
-//            list.setSize(getWidth(), originalHeight);
-//            originalHeight = 0;
-//        }
-    }
-
-    public void mousePressed(MouseEvent arg0) {
-        // TODO Auto-generated method stub
-        
-    }
-
-    public void mouseReleased(MouseEvent arg0) {
-        // TODO Auto-generated method stub
-        
+    
+    JList getList() {
+        return list;
     }
 }

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SingleListFactory.java	2009-11-22 09:12:06-0800
@@ -33,15 +33,12 @@
  */
 class SingleListFactory implements ComponentFactory {
     
-    public SingleListFactory() {
-    }
-    
     public JComponent createComponent(
             final Object modelElement,
             final String propName) {
         
         UMLModelElementListModel model = null;
-        UMLSingleRowSelector pane = null;
+        JComponent pane = null;
         
         if ("owner".equals(propName)) {
             model = new UMLFeatureOwnerListModel();
@@ -55,7 +52,6 @@
             model = new UMLParameterBehavioralFeatListModel();
         } else if ("enumeration".equals(propName)) {
             EnumerationListModel m = new EnumerationListModel(modelElement);
-            pane = new UMLSingleRowSelector(m);
         } else if ("association".equals(propName)) {
             model = new UMLAssociationEndAssociationListModel();
         } else if ("base".equals(propName)) {
@@ -116,7 +112,7 @@
         
         if (model != null && pane == null) {
             model.setTarget(modelElement);
-            pane = new UMLSingleRowSelector(model);
+            pane = new UMLExpandableRowSelector(model, false, false);
         }
         
         return pane;

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassAttributeListModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassAttributeListModel.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassAttributeListModel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassAttributeListModel.java	2009-11-22 09:12:06-0800
@@ -41,7 +41,7 @@
      * Constructor for UMLClassifierStructuralFeatureListModel.
      */
     public UMLClassAttributeListModel() {
-        super("feature", true, false);
+        super("feature", true, false, Model.getMetaTypes().getAttribute());
     }
 
     /*

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassOperationListModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassOperationListModel.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassOperationListModel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassOperationListModel.java	2009-11-22 09:12:06-0800
@@ -40,7 +40,7 @@
      * Constructor for UMLClassifierFeatureListModel.
      */
     public UMLClassOperationListModel() {
-        super("feature", true, false);
+        super("feature", true, false, Model.getMetaTypes().getOperation());
     }
 
     /*

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java	2009-11-22 09:12:06-0800
@@ -25,17 +25,42 @@
 package org.argouml.core.propertypanels.ui;
 
 import java.awt.BorderLayout;
+import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.KeyboardFocusManager;
+import java.awt.event.ActionEvent;
+import java.awt.event.ContainerEvent;
+import java.awt.event.ContainerListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
+import java.util.ArrayList;
+import java.util.Arrays;
 
+import javax.swing.Action;
 import javax.swing.Icon;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JToolBar;
 import javax.swing.JTree;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
 import javax.swing.plaf.TreeUI;
 import javax.swing.plaf.basic.BasicTreeUI;
+import javax.swing.table.TableCellEditor;
+
+import org.apache.log4j.Logger;
+import org.argouml.application.helpers.ResourceLoaderWrapper;
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
+import org.argouml.model.Model;
+import org.argouml.ui.ActionCreateContainedModelElement;
+import org.argouml.ui.UndoableAction;
+import org.tigris.gef.presentation.FigTextEditor;
+import org.tigris.swidgets.FlexiGridLayout;
+import org.tigris.toolbar.ToolBar;
+import org.tigris.toolbar.ToolBarFactory;
 
 /**
  * A control for displaying the contents of a list model elements in a panel
@@ -46,7 +71,12 @@
  * @since 0.29.2
  */
 public class UMLExpandableRowSelector extends JPanel
-        implements MouseListener {
+        implements MouseListener, ContainerListener {
+    
+    /**
+     * The logger
+     */
+    private static final Logger LOG = Logger.getLogger(UMLExpandableRowSelector.class);
     
     /**
      * class uid
@@ -84,24 +114,29 @@
     /**
      * The scrollpane that will contain the list
      */
-    private JScrollPane scroll;
+    private ScrollList scroll;
 
     /**
      * The preferred size of the component when shrunk
      */
-    private Dimension shrunkPreferredSize = null;
+    private final Dimension shrunkPreferredSize;
 
     /**
      * The preferred size of the component when expanded
      */
-    private Dimension expandedPreferredSize = null;
+    private final Dimension expandedPreferredSize;
 
     /**
      * The maximum size of the component when expanded
      */
-    private Dimension expandedMaximumSize = null;
+    private final Dimension expandedMaximumSize;
     
     /**
+     * True if the component is expandable
+     */
+    private final boolean expandable;
+
+    /**
      * The current expanded state
      */
     private boolean expanded = false;
@@ -110,21 +145,43 @@
      * The label that contains the +/- symbol to indicate
      * expansion feature to user.
      */
-    private JLabel expander;
+    private final JLabel expander;
+    
+    /**
+     * The toolbar of controls for manipulating items in the list
+     */
+    private final JToolBar tb;
+    
+    /**
+     * The delete action that we must enable/disable
+     */
+    private final DeleteAction deleteAction;
     
     /**
      * Constructor
      * @param model The single item list model
      */
     public UMLExpandableRowSelector(UMLModelElementListModel model) {
+        this(model, false, true);
+        
+    }
+    /**
+     * Constructor
+     * @param model The single item list model
+     * @param singleRow true if we only ever want a single row
+     */
+    public UMLExpandableRowSelector(UMLModelElementListModel model, boolean expanded, boolean expandable) {
         super(new BorderLayout());
         
-        JPanel buttonPanel = new JPanel();
-        expander = new JLabel();
-        this.addMouseListener(this);
-        setIcon();
-        buttonPanel.add(expander, BorderLayout.NORTH);
-        add(buttonPanel, BorderLayout.WEST);
+        this.expandable = expandable;
+        
+        Object target = model.getTarget();
+        Object metaType = model.getMetaType();
+        
+        LOG.info("model = " + model.getClass().getName());
+        LOG.info("metatype = " + metaType);
+        LOG.info("target = " + target);
+        
         scroll = new ScrollList(model, 1);
         add(scroll);
         
@@ -138,7 +195,49 @@
         expandedMaximumSize = scroll.getMaximumSize();
         
         scroll.setHorizontalScrollBarPolicy(
-        	JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+        
+        if (!expandable && !expanded) {
+            scroll.setVerticalScrollBarPolicy(
+                    JScrollPane.VERTICAL_SCROLLBAR_NEVER);
+            expander = null;
+            tb = null;
+            deleteAction = null;
+        } else {
+            // Create actions and expander if we have multiple rows
+            final ArrayList<Action> actions = new ArrayList<Action>(2);
+            
+            if (Model.getUmlFactory().isContainmentValid(metaType, target)) {
+                final Action createAction = new ActionCreateContainedModelElement(
+                        metaType,
+                        target,
+                        "button.new-" + Model.getMetaTypes().getName(metaType).toLowerCase());
+                actions.add(createAction);
+            }
+            deleteAction = new DeleteAction();
+            actions.add(deleteAction);
+            
+            final ToolBarFactory tbf = new ToolBarFactory(actions);
+            tb = tbf.createToolBar();
+            tb.setRollover(true);
+            tb.setOrientation(ToolBar.VERTICAL);
+            
+            JPanel buttonPanel =
+                new JPanel(new FlexiGridLayout(2, 1, FlexiGridLayout.ROWCOLPREFERRED));
+            expander = new JLabel();
+            this.addMouseListener(this);
+            setIcon();
+            buttonPanel.add(expander);
+            if (tb != null) {
+                tb.setVisible(false);
+                buttonPanel.add(tb);
+            }
+            add(buttonPanel, BorderLayout.WEST);
+
+            scroll.getList().addListSelectionListener(deleteAction);
+            
+            addContainerListener(this);
+        }
     }
     
     /**
@@ -211,6 +310,9 @@
         expanded = !expanded;
         
         setIcon();
+        if (tb != null) {
+            tb.setVisible(expanded);
+        }
         
         // Froce the parent to redraw
         getParent().invalidate();
@@ -227,4 +329,83 @@
             expander.setIcon(collapsedIcon);
         }
     }
+    
+    @Override
+    public void componentAdded(ContainerEvent arg0) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /**
+     * Remove all the listeners that were added in the constructor
+     */
+    @Override
+    public void componentRemoved(ContainerEvent event) {
+        scroll.getList().removeListSelectionListener(deleteAction);
+        this.removeMouseListener(this);
+        this.removeContainerListener(this);
+    }
+    
+
+    /**
+     * Add a listener for selection changes to the list
+     * @param listener the listener
+     */
+    public void addListSelectionListener(ListSelectionListener listener) {
+        scroll.getList().addListSelectionListener(listener);
+    }
+
+    /**
+     * Add a listener for selection changes to the list
+     * @param listener the listener
+     */
+    public void removeListSelectionListener(ListSelectionListener listener) {
+        scroll.getList().removeListSelectionListener(listener);
+    }
+    
+    /**
+     * This action deletes the model elements that are selected in the JList
+     */
+    private class DeleteAction extends UndoableAction implements ListSelectionListener {
+        
+        DeleteAction() {
+            super("button.delete",
+                    ResourceLoaderWrapper.getInstance().lookupIconResource("DeleteFromModel"));
+            setEnabled(false);
+        }
+
+        @Override
+        public void valueChanged(ListSelectionEvent e) {
+            setEnabled(scroll.getList().getSelectedIndex() > -1);
+        }
+        
+        /*
+         * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
+         */
+        public void actionPerformed(ActionEvent ae) {
+            super.actionPerformed(ae);
+            // TODO Part of this is copied from ActionDeleteModelElement. We
+            // maybe need some subclass for common code.
+            KeyboardFocusManager focusManager =
+                KeyboardFocusManager.getCurrentKeyboardFocusManager();
+            Component focusOwner = focusManager.getFocusOwner();
+            if (focusOwner instanceof FigTextEditor) {
+                // TODO: Probably really want to cancel editing
+                //((FigTextEditor) focusOwner).cancelEditing();
+                ((FigTextEditor) focusOwner).endEditing();
+            } else if (focusOwner instanceof JTable) {
+                JTable table = (JTable) focusOwner;
+                if (table.isEditing()) {
+                    TableCellEditor ce = table.getCellEditor();
+                    if (ce != null) {
+                        ce.cancelCellEditing();
+                    }
+                }
+            }
+
+            Project p = ProjectManager.getManager().getCurrentProject();
+            Object[] targets = scroll.getList().getSelectedValues();
+            p.moveToTrash(Arrays.asList(targets));
+        }
+    }
 }

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java	2009-11-22 09:12:06-0800
@@ -141,6 +141,18 @@
         this.showPath = showPath;
     }
     
+    public UMLModelElementListModel(
+            final String name,
+            final boolean showIcon,
+            final boolean showPath,
+            final Object metaType) {
+        super();
+        eventName = name;
+        this.showIcon = showIcon;
+        this.showPath = showPath;
+        this.metaType = metaType;
+    }
+    
     /**
      * Constructor for UMLModelElementListModel2.
      *

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementOrderedListModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementOrderedListModel.java?view=diff&pathrev=17516&r1=17515&r2=17516
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementOrderedListModel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementOrderedListModel.java	2009-11-22 09:12:06-0800
@@ -87,6 +87,20 @@
         super(name, showIcon, showPath);
     }
 
+    /**
+     * The constructor.
+     *
+     * @param name
+     *            the name
+     */
+    public UMLModelElementOrderedListModel(
+            final String name,
+            final boolean showIcon,
+            final boolean showPath,
+            final Object metaType) {
+        super(name, showIcon, showPath, metaType);
+    }
+
     /*
      * @see org.argouml.uml.ui.UMLModelElementListModel2#buildModelList()
      */

Removed: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLSingleRowSelector.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLSingleRowSelector.java?view=markup&pathrev=17515

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2423059

To unsubscribe from this discussion, e-mail: [[email protected]].
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.