Author: bobtarling Date: 2010-03-27 09:22:29-0700 New Revision: 18176 Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/AbstractActionAddModelElement.java Removed: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassifierPackageImportsListModel.java Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ListFactory.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java
Log: Provide buttons to add/remove element imports from package Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java?view=diff&pathrev=18176&r1=18175&r2=18176 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManager.java 2010-03-27 09:22:29-0700 @@ -17,6 +17,10 @@ import java.util.HashMap; import java.util.Map; +import javax.swing.Action; + +import org.argouml.kernel.Command; + public abstract class GetterSetterManager { /** @@ -50,6 +54,15 @@ public abstract boolean isValidElement(String propertyName, String type, Object umlElement); + public abstract Command getRemoveCommand(String propertyName, Object umlElement, Object objectToRemove); + + public abstract Command getAddCommand(String propertyName, Object umlElement); + + /** This forces component to fully rebuild when items are added and removed + * Used for pragmatic purposes but not advised long term we should remove this in time + */ + public abstract boolean isFullBuildOnly(String propertyName); + public boolean contains(String propertyName) { return getterSetterByPropertyName.containsKey(propertyName); } @@ -86,6 +99,15 @@ protected abstract class ListGetterSetter extends OptionGetterSetter { abstract boolean isValidElement(Object modelElement, String type); abstract Object getMetaType(); + Action getAddAction(Object modelElement) { + return null; + } + Action getRemoveAction(Object modelElement) { + return null; + } + boolean isFullBuildOnly() { + return false; + } } } \ No newline at end of file Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java?view=diff&pathrev=18176&r1=18175&r2=18176 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/GetterSetterManagerImpl.java 2010-03-27 09:22:29-0700 @@ -17,10 +17,18 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.StringTokenizer; +import javax.swing.JOptionPane; + import org.apache.log4j.Logger; +import org.argouml.i18n.Translator; +import org.argouml.kernel.Command; +import org.argouml.kernel.NonUndoableCommand; import org.argouml.model.Model; +import org.argouml.uml.ui.UMLAddDialog; +import org.argouml.util.ArgoFrame; /** * Property getters and setters for UML1.4 @@ -75,6 +83,7 @@ addGetterSetter("guard", new GuardGetterSetter()); addGetterSetter("effect", new EffectGetterSetter()); addGetterSetter("trigger", new TriggerGetterSetter()); + addGetterSetter("elementImport", new ElementImportGetterSetter()); // UML2 only addGetterSetter("ownedOperation", new FeatureGetterSetter()); @@ -129,6 +138,16 @@ return null; } + public boolean isFullBuildOnly( + final String propertyName) { + BaseGetterSetter bgs = getterSetterByPropertyName.get(propertyName); + if (bgs instanceof ListGetterSetter) { + return ((ListGetterSetter) bgs).isFullBuildOnly(); + } + + return false; + } + public Object create(String propertyName, String language, String body) { BaseGetterSetter bgs = getterSetterByPropertyName.get(propertyName); @@ -160,6 +179,34 @@ return null; } + + @Override + public Command getAddCommand(String propertyName, Object umlElement) { + BaseGetterSetter bgs = getterSetterByPropertyName.get(propertyName); + if (bgs instanceof Addable) { + return ((Addable) bgs).getAddCommand(umlElement); + } + return null; + } + + @Override + public Command getRemoveCommand(String propertyName, Object umlElement, Object objectToRemove) { + BaseGetterSetter bgs = getterSetterByPropertyName.get(propertyName); + if (bgs instanceof Removeable) { + return ((Removeable) bgs).getRemoveCommand(umlElement, objectToRemove); + } + return null; + } + + private interface Addable { + Command getAddCommand(Object umlElement); + } + + private interface Removeable { + Command getRemoveCommand(Object umlElement, Object objectToRemove); + } + + /** * The getter/setter for the Absrtact property * @author Bob Tarling @@ -619,7 +666,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -657,7 +704,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -693,7 +740,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -728,7 +775,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -764,7 +811,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -800,7 +847,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -836,7 +883,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -873,7 +920,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -910,7 +957,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -947,7 +994,7 @@ // not needed } - protected boolean isValidElement( + public boolean isValidElement( final Object element, final String type) { return getOptions(element, type).contains(element); @@ -973,7 +1020,7 @@ // not needed } - protected boolean isValidElement(Object element, String type) { + public boolean isValidElement(Object element, String type) { return getOptions(element, type).contains(element); } @@ -982,6 +1029,219 @@ } } + private class ElementImportGetterSetter extends ListGetterSetter implements Addable, Removeable { + + public Collection getOptions(Object modelElement, String type) { + return Model.getFacade().getImportedElements(modelElement); + } + + public Object get(Object modelElement, String type) { + // not needed + return null; + } + + public boolean isFullBuildOnly() { + return true; + } + + public void set(Object element, Object x) { + // not needed + } + + public boolean isValidElement(Object element, String type) { + return getOptions(element, type).contains(element); + } + + public Object getMetaType() { + return Model.getMetaTypes().getModelElement(); + } + + public Command getAddCommand(Object modelElement) { + return new AddElementImportCommand(modelElement); + } + + public Command getRemoveCommand(Object modelElement, Object objectToRemove) { + return new RemoveElementImportCommand(modelElement, objectToRemove); + } + + private class AddElementImportCommand extends AddModelElementCommand { + + final Object target; + + /** + * Constructor for ActionAddPackageImport. + */ + public AddElementImportCommand(Object target) { + super(); + this.target = target; + } + + + protected List getChoices() { + List list = new ArrayList(); + /* TODO: correctly implement next function + * in the model subsystem for + * issue 1942: */ + list.addAll(Model.getModelManagementHelper() + .getAllPossibleImports(target)); + return list; + } + + + protected List getSelected() { + List list = new ArrayList(); + list.addAll(Model.getFacade().getImportedElements(target)); + return list; + } + + + protected String getDialogTitle() { + return Translator.localize("dialog.title.add-imported-elements"); + } + + + @Override + protected void doIt(Collection selected) { + if (LOG.isInfoEnabled()) { + LOG.info("Setting " + selected.size() + "imported elements"); + } + Model.getModelManagementHelper().setImportedElements(target, selected); + } + } + + private class RemoveElementImportCommand + extends NonUndoableCommand { + + private final Object target; + private final Object objectToRemove; + + /** + * Constructor for ActionRemovePackageImport. + */ + public RemoveElementImportCommand(final Object target, final Object objectToRemove) { + this.target = target; + this.objectToRemove = objectToRemove; + } + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public Object execute() { + Model.getModelManagementHelper() + .removeImportedElement(target, objectToRemove); + return null; + } + } + + public abstract class AddModelElementCommand extends NonUndoableCommand { + + private Object target; + private boolean multiSelect = true; + private boolean exclusive = true; + + /** + * Construct a command to add a model element to some list. + */ + protected AddModelElementCommand() { + } + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public Object execute() { + UMLAddDialog dialog = + new UMLAddDialog(getChoices(), getSelected(), getDialogTitle(), + isMultiSelect(), + isExclusive()); + int result = dialog.showDialog(ArgoFrame.getFrame()); + if (result == JOptionPane.OK_OPTION) { + doIt(dialog.getSelected()); + } + return null; + } + + /** + * Returns the choices the user has in the UMLAddDialog. The choices are + * depicted on the left side of the UMLAddDialog (sorry Arabic users) and + * can be moved via the buttons on the dialog to the right side. On the + * right side are the selected modelelements. + * @return List of choices + */ + protected abstract List getChoices(); + + + /** + * The modelelements already selected BEFORE the dialog is shown. + * @return List of model elements + */ + protected abstract List getSelected(); + + /** + * The action that has to be done by ArgoUml after the user clicks ok in the + * UMLAddDialog. + * @param selected The choices the user has selected in the UMLAddDialog + */ + protected abstract void doIt(Collection selected); + + /** + * Returns the UML model target. + * @return UML ModelElement + */ + protected Object getTarget() { + return target; + } + + /** + * Sets the UML model target. + * @param theTarget The target to set + */ + public void setTarget(Object theTarget) { + target = theTarget; + } + + /** + * Returns the title of the dialog. + * @return String + */ + protected abstract String getDialogTitle(); + + /** + * Returns the exclusive. + * @return boolean + */ + public boolean isExclusive() { + return exclusive; + } + + /** + * Returns the multiSelect. + * @return boolean + */ + public boolean isMultiSelect() { + return multiSelect; + } + + /** + * Sets the exclusive. + * @param theExclusive The exclusive to set + */ + public void setExclusive(boolean theExclusive) { + exclusive = theExclusive; + } + + /** + * Sets the multiSelect. + * @param theMultiSelect The multiSelect to set + */ + public void setMultiSelect(boolean theMultiSelect) { + multiSelect = theMultiSelect; + } + + } + + + } + private class MethodExpressionGetterSetter extends ExpressionGetterSetter { @@ -996,7 +1256,7 @@ } @Override - Object create(final String language, final String body) { + public Object create(final String language, final String body) { return Model.getDataTypesFactory().createProcedureExpression(language, body); } } @@ -1016,7 +1276,7 @@ // not needed } - protected boolean isValidElement(Object element, String type) { + public boolean isValidElement(Object element, String type) { return getOptions(element, type).contains(element); } @@ -1041,7 +1301,7 @@ // not needed } - protected boolean isValidElement(Object element, String type) { + public boolean isValidElement(Object element, String type) { return getOptions(element, type).contains(element); } Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/AbstractActionAddModelElement.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/AbstractActionAddModelElement.java?view=markup&pathrev=18176 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/AbstractActionAddModelElement.java 2010-03-27 09:22:29-0700 @@ -0,0 +1,200 @@ +/* $Id: AbstractActionAddModelElement2.java 17881 2010-01-12 21:09:28Z linus $ + ***************************************************************************** + * Copyright (c) 2009 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * bobtarling + ***************************************************************************** + * + * Some portions of this file was previously release using the BSD License: + */ + +// Copyright (c) 2007 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 +// and this paragraph appear in all copies. This software program and +// documentation are copyrighted by The Regents of the University of +// California. The software program and documentation are supplied "AS +// IS", without any accompanying services from The Regents. The Regents +// does not warrant that the operation of the program will be +// uninterrupted or error-free. The end-user understands that the program +// was developed for research purposes and is advised not to rely +// exclusively on the program for any reason. IN NO EVENT SHALL THE +// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, +// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, +// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF +// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF +// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, +// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +package org.argouml.core.propertypanels.ui; + +import java.awt.event.ActionEvent; +import java.util.Collection; +import java.util.List; + +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JOptionPane; + +import org.argouml.i18n.Translator; +import org.argouml.kernel.UmlModelMutator; +import org.argouml.util.ArgoFrame; +import org.argouml.ui.UndoableAction; +import org.argouml.uml.ui.UMLAddDialog; + +/** + * Abstract action that is the parent to all add actions that add the + * modelelements via the UMLAddDialog. + * + * @since Oct 2, 2002 + * @author [email protected] + */ +...@umlmodelmutator +public abstract class AbstractActionAddModelElement extends UndoableAction { + + private Object target; + private boolean multiSelect = true; + private boolean exclusive = true; + + /** + * Construct an action to add a model element to some list. + */ + protected AbstractActionAddModelElement() { + super(Translator.localize("menu.popup.add-modelelement"), null); + // Set the tooltip string: + putValue(Action.SHORT_DESCRIPTION, + Translator.localize("menu.popup.add-modelelement")); + } + + /** + * Construct a named action to add a model element to some list. + * @param name name for action + */ + public AbstractActionAddModelElement(String name) { + super(name); + } + + /** + * Construct an action to add a model element to some list with the + * given name and icon. + * @param name name for action + * @param icon icon for action + */ + public AbstractActionAddModelElement(String name, Icon icon) { + super(name, icon); + } + + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + @Override + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + UMLAddDialog dialog = + new UMLAddDialog(getChoices(), getSelected(), getDialogTitle(), + isMultiSelect(), + isExclusive()); + int result = dialog.showDialog(ArgoFrame.getFrame()); + if (result == JOptionPane.OK_OPTION) { + doIt(dialog.getSelected()); + } + } + + /** + * Returns the choices the user has in the UMLAddDialog. The choices are + * depicted on the left side of the UMLAddDialog (sorry Arabic users) and + * can be moved via the buttons on the dialog to the right side. On the + * right side are the selected modelelements. + * @return List of choices + */ + protected abstract List getChoices(); + + + /** + * The modelelements already selected BEFORE the dialog is shown. + * @return List of model elements + */ + protected abstract List getSelected(); + + /** + * The action that has to be done by ArgoUml after the user clicks ok in the + * UMLAddDialog. + * @param selected The choices the user has selected in the UMLAddDialog + */ + protected abstract void doIt(Collection selected); + + /* + * @see javax.swing.Action#isEnabled() + */ + @Override + public boolean isEnabled() { + return !getChoices().isEmpty(); + } + + + /** + * Returns the UML model target. + * @return UML ModelElement + */ + protected Object getTarget() { + return target; + } + + /** + * Sets the UML model target. + * @param theTarget The target to set + */ + public void setTarget(Object theTarget) { + target = theTarget; + } + + /** + * Returns the title of the dialog. + * @return String + */ + protected abstract String getDialogTitle(); + + /** + * Returns the exclusive. + * @return boolean + */ + public boolean isExclusive() { + return exclusive; + } + + /** + * Returns the multiSelect. + * @return boolean + */ + public boolean isMultiSelect() { + return multiSelect; + } + + /** + * Sets the exclusive. + * @param theExclusive The exclusive to set + */ + public void setExclusive(boolean theExclusive) { + exclusive = theExclusive; + } + + /** + * Sets the multiSelect. + * @param theMultiSelect The multiSelect to set + */ + public void setMultiSelect(boolean theMultiSelect) { + multiSelect = theMultiSelect; + } + +} Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ListFactory.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ListFactory.java?view=diff&pathrev=18176&r1=18175&r2=18176 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ListFactory.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ListFactory.java 2010-03-27 09:22:29-0700 @@ -105,8 +105,6 @@ model = new UMLStateDoActivityListModel(modelElement); JList l = new UMLStateDoActivityList((UMLModelElementListModel) model); list = new OldScrollList(l); - } else if ("elementImport".equals(propName)) { - model = new UMLClassifierPackageImportsListModel(modelElement); } else if ("entry".equals(propName)) { model = new UMLStateEntryListModel(modelElement); JList l = new UMLStateEntryList((UMLModelElementListModel) model); 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=18176&r1=18175&r2=18176 ============================================================================== --- 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 2010-03-27 09:22:29-0700 @@ -73,6 +73,7 @@ import org.apache.log4j.Logger; import org.argouml.application.helpers.ResourceLoaderWrapper; import org.argouml.i18n.Translator; +import org.argouml.kernel.Command; import org.argouml.kernel.Project; import org.argouml.kernel.ProjectManager; import org.argouml.model.Model; @@ -84,7 +85,6 @@ import org.tigris.toolbar.ToolBar; import org.tigris.toolbar.ToolBarFactory; import org.tigris.toolbar.toolbutton.PopupToolBoxButton; -import org.tigris.toolbar.toolbutton.ToolButton; /** * A control for displaying the contents of a list model elements in a panel @@ -95,7 +95,7 @@ * @since 0.29.2 */ class RowSelector extends JPanel - implements MouseListener, ListDataListener { + implements MouseListener, ListDataListener, ListSelectionListener { /** * The logger @@ -200,7 +200,12 @@ * The delete action that we must enable/disable */ private final DeleteAction deleteAction; - + + /** + * The remove action that we must enable/disable + */ + private final Action removeAction; + /** * The delete action that we must enable/disable */ @@ -241,6 +246,7 @@ this.expandable = expandable; Object metaType = null; List metaTypes = null; + final Action addAction; if (model instanceof UMLModelElementListModel) { // Temporary until SimpleListModel is used for all @@ -289,6 +295,16 @@ jscroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + if (model instanceof SimpleListModel + && ((SimpleListModel) model).getAddCommand() != null) { + removeAction = new RemoveAction(scroll.getList(), ((SimpleListModel) model)); + addAction = new AddAction(((SimpleListModel) model).getAddCommand()); + } else { + removeAction = null; + addAction = null; + } + if (!expandable && !expanded) { jscroll.setVerticalScrollBarPolicy( @@ -344,8 +360,16 @@ actions.add(createAction); } } - deleteAction = new DeleteAction(); - actions.add(deleteAction); + if (addAction != null) { + actions.add(addAction); + } + if (removeAction != null) { + actions.add(removeAction); + deleteAction = null; + } else { + deleteAction = new DeleteAction(); + actions.add(deleteAction); + } if (Model.getUmlHelper().isMovable(metaType)) { moveUpAction = new MoveUpAction(); @@ -385,6 +409,7 @@ this.addMouseListener(this); setIcon(); buttonPanel.add(expander); + // TODO: In think this will always be true if (toolbar != null) { toolbar.setVisible(false); buttonPanel.add(toolbar); @@ -392,7 +417,12 @@ add(buttonPanel, BorderLayout.WEST); if (!Model.getModelManagementHelper().isReadOnly(target)) { - getList().addListSelectionListener(deleteAction); + if (deleteAction != null) { + getList().addListSelectionListener(deleteAction); + } + if (removeAction != null) { + getList().addListSelectionListener(this); + } // 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 @@ -500,6 +530,7 @@ public void removeNotify() { LOG.info("The RowSelector is being removed from a panel"); if (!readonly) { + getList().removeListSelectionListener(this); getList().removeListSelectionListener(deleteAction); if (moveUpAction != null) { getList().removeListSelectionListener(moveUpAction); @@ -581,6 +612,14 @@ public void intervalRemoved(ListDataEvent e) { } + + + public void valueChanged(ListSelectionEvent e) { + if (removeAction != null) { + removeAction.setEnabled(getList().getSelectedIndex() > -1); + } + } + /** * This action deletes the model elements that are selected in the JList @@ -829,4 +868,44 @@ this.element = element; } } + + private static class AddAction extends UndoableAction { + + private Command command; + + public AddAction(Command command) { + super("", ResourceLoaderWrapper.lookupIcon("Add")); + this.command = command; + } + + @Override + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + command.execute(); + } + } + + private static class RemoveAction extends UndoableAction { + + private final SimpleListModel simpleListModel; + private final JList list; + + public RemoveAction(JList list, SimpleListModel model) { + super("", ResourceLoaderWrapper.lookupIcon("Remove")); + this.simpleListModel = model; + this.list = list; + } + + @Override + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + final Object objectToRemove = list.getSelectedValue(); + if (objectToRemove!= null) { + Command command = simpleListModel.getRemoveCommand(objectToRemove); + command.execute(); + } else { + LOG.warn("No selcted object was found in the list control - we shouldn't be able to get here"); + } + } + } } Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java?view=diff&pathrev=18176&r1=18175&r2=18176 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java 2010-03-27 09:22:29-0700 @@ -25,6 +25,7 @@ import org.apache.log4j.Logger; import org.argouml.core.propertypanels.model.GetterSetterManager; +import org.argouml.kernel.Command; import org.argouml.model.AddAssociationEvent; import org.argouml.model.InvalidElementException; import org.argouml.model.Model; @@ -104,45 +105,66 @@ return metaTypes; } + public Command getRemoveCommand(Object objectToRemove) { + return getterSetterManager.getRemoveCommand(propertyName, umlElement, objectToRemove); + } + + public Command getAddCommand() { + return getterSetterManager.getAddCommand(propertyName, umlElement); + } + /* * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange(final PropertyChangeEvent e) { - Runnable doWorkRunnable = new Runnable() { - public void run() { - try { - if (e instanceof RemoveAssociationEvent) { - removeElement( - ((RemoveAssociationEvent) e).getChangedValue()); - } else if (e instanceof AddAssociationEvent) { - Object newElement = ((AddAssociationEvent) e).getChangedValue(); - - if (Model.getUmlHelper().isMovable(getMetaType())) { - final Collection c = - (Collection) getterSetterManager.getOptions( - umlElement, - propertyName, - type); - final int index = - CollectionUtil.indexOf(c, newElement); - if (index < 0 || index > getSize() - 1) { - LOG.warn( - "Unable to add element at correct position " - + index + " added to end instead"); - addElement(newElement); - } else { - add(index, newElement); - } - } else { - addElement(newElement); - } - } - } catch (InvalidElementException e) { - LOG.debug("propertyChange accessed a deleted element ", e); - } - } - }; - SwingUtilities.invokeLater(doWorkRunnable); + if (e instanceof RemoveAssociationEvent + || e instanceof AddAssociationEvent) { + Runnable doWorkRunnable = new Runnable() { + public void run() { + try { + if (getterSetterManager.isFullBuildOnly(propertyName)) { + removeAllElements(); + build(); + } else { + if (e instanceof RemoveAssociationEvent) { + final Object objectToRemove = + ((RemoveAssociationEvent) e).getChangedValue(); + removeElement(objectToRemove); + } else if (e instanceof AddAssociationEvent) { + Object newElement = ((AddAssociationEvent) e).getChangedValue(); + + if (Model.getUmlHelper().isMovable(getMetaType())) { + final Collection c = + (Collection) getterSetterManager.getOptions( + umlElement, + propertyName, + type); + final int index = + CollectionUtil.indexOf(c, newElement); + if (index < 0 || index > getSize() - 1) { + LOG.warn( + "Unable to add element at correct position " + + index + " added to end instead"); + addElement(newElement); + } else { + add(index, newElement); + } + } else { + addElement(newElement); + } + } + } + } catch (InvalidElementException e) { + LOG.debug("propertyChange accessed a deleted element ", e); + } + } + }; + SwingUtilities.invokeLater(doWorkRunnable); + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("We are listening for too much here. An event we don't need " + e); + } + } } /** Removed: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassifierPackageImportsListModel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLClassifierPackageImportsListModel.java?view=markup&pathrev=18175 ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2465965 To unsubscribe from this discussion, e-mail: [[email protected]].
