Author: mvw
Date: 2007-05-10 12:42:59-0700
New Revision: 12592
Modified:
trunk/src_new/org/argouml/ui/explorer/ExplorerPopup.java
trunk/src_new/org/argouml/ui/targetmanager/TargetManager.java
trunk/src_new/org/argouml/uml/ui/ActionDeleteModelElements.java
Log:
Downlight Delete action when the selected element can not be deleted (e.g. the last diagram).
Move the knowledge about when deleting is allowed into the Action class.
Modified: trunk/src_new/org/argouml/ui/explorer/ExplorerPopup.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/explorer/ExplorerPopup.java?view=diff&rev=12592&p1=trunk/src_new/org/argouml/ui/explorer/ExplorerPopup.java&p2=trunk/src_new/org/argouml/ui/explorer/ExplorerPopup.java&r1=12591&r2=12592
==============================================================================
--- trunk/src_new/org/argouml/ui/explorer/ExplorerPopup.java (original)
+++ trunk/src_new/org/argouml/ui/explorer/ExplorerPopup.java 2007-05-10 12:42:59-0700
@@ -268,7 +268,9 @@
if (selectedItem instanceof Diagram) {
this.add(new ActionSaveDiagramToClipboard());
- this.add(new ActionDeleteModelElements());
+ ActionDeleteModelElements ad = new ActionDeleteModelElements();
+ ad.setEnabled(ad.shouldBeEnabled());
+ this.add(ad);
}
}
Modified: trunk/src_new/org/argouml/ui/targetmanager/TargetManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/targetmanager/TargetManager.java?view=diff&rev=12592&p1=trunk/src_new/org/argouml/ui/targetmanager/TargetManager.java&p2=trunk/src_new/org/argouml/ui/targetmanager/TargetManager.java&r1=12591&r2=12592
==============================================================================
--- trunk/src_new/org/argouml/ui/targetmanager/TargetManager.java (original)
+++ trunk/src_new/org/argouml/ui/targetmanager/TargetManager.java 2007-05-10 12:42:59-0700
@@ -33,7 +33,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Action;
@@ -50,8 +49,6 @@
import org.argouml.uml.ui.foundation.core.ActionAddAttribute;
import org.argouml.uml.ui.foundation.core.ActionAddOperation;
import org.tigris.gef.base.Diagram;
-import org.tigris.gef.base.Editor;
-import org.tigris.gef.base.Globals;
import org.tigris.gef.presentation.Fig;
/**
@@ -405,7 +402,7 @@
private ActionAddMessage addMessageAction = new ActionAddMessage();
- private AbstractAction deleteAction = new ActionDeleteModelElements();
+ private ActionDeleteModelElements deleteAction = new ActionDeleteModelElements();
/**
* Singleton retrieval method.
@@ -836,52 +833,12 @@
addAttributeAction.setEnabled(addAttributeAction.shouldBeEnabled());
addOperationAction.setEnabled(addOperationAction.shouldBeEnabled());
addMessageAction.setEnabled(addMessageAction.shouldBeEnabled());
- deleteAction.setEnabled(isDeleteAllowed());
+ deleteAction.setEnabled(deleteAction.shouldBeEnabled());
inTransaction = false;
}
/**
- * Determine if the current selected targets should allow enablement of
- * the delete action.
- * @return true to enable delete
- */
- private boolean isDeleteAllowed() {
- int size = 0;
- try {
- Editor ce = Globals.curEditor();
- Vector figs = ce.getSelectionManager().getFigs();
- size = figs.size();
- } catch (Exception e) {
- // Ignore
- }
- if (size > 0) {
- return true;
- }
- Object target = TargetManager.getInstance().getTarget();
- if (target instanceof Diagram) { // we cannot delete the last diagram
- return (ProjectManager.getManager().getCurrentProject()
- .getDiagrams().size() > 1);
- }
- if (Model.getFacade().isAModel(target)
- // we cannot delete the model itself
- && target.equals(ProjectManager.getManager().getCurrentProject()
- .getModel())) {
- return false;
- }
- if (Model.getFacade().isAAssociationEnd(target)) {
- return Model.getFacade().getOtherAssociationEnds(target).size() > 1;
- }
- if (Model.getStateMachinesHelper().isTopState(target)) {
- /* we can not delete a "top" state,
- * it comes and goes with the statemachine. Issue 2655.
- */
- return false;
- }
- return target != null;
- }
-
- /**
* Get the Action for creating and adding a new attribute
* to the single selected target (or its owner).
* @deprecated in 0.25.3 by Bob Tarling
Modified: trunk/src_new/org/argouml/uml/ui/ActionDeleteModelElements.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/ui/ActionDeleteModelElements.java?view=diff&rev=12592&p1=trunk/src_new/org/argouml/uml/ui/ActionDeleteModelElements.java&p2=trunk/src_new/org/argouml/uml/ui/ActionDeleteModelElements.java&r1=12591&r2=12592
==============================================================================
--- trunk/src_new/org/argouml/uml/ui/ActionDeleteModelElements.java (original)
+++ trunk/src_new/org/argouml/uml/ui/ActionDeleteModelElements.java 2007-05-10 12:42:59-0700
@@ -28,6 +28,7 @@
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.text.MessageFormat;
+import java.util.Vector;
import javax.swing.Action;
import javax.swing.JOptionPane;
@@ -46,6 +47,9 @@
import org.argouml.uml.diagram.static_structure.ui.CommentEdge;
import org.argouml.uml.diagram.ui.ActionDeleteConcurrentRegion;
import org.argouml.uml.diagram.ui.UMLDiagram;
+import org.tigris.gef.base.Diagram;
+import org.tigris.gef.base.Editor;
+import org.tigris.gef.base.Globals;
import org.tigris.gef.presentation.Fig;
import org.tigris.gef.presentation.FigTextEditor;
import org.tigris.gef.undo.UndoableAction;
@@ -53,7 +57,7 @@
/**
* Action for removing objects from the model.
* Objects can be Modelelements, Diagrams (argodiagram and it's children),
- * Figs without owner,... <p>
+ * Figs without owner,...
*/
public class ActionDeleteModelElements extends UndoableAction {
@@ -233,4 +237,42 @@
return (response == JOptionPane.YES_OPTION);
}
+
+ /**
+ * @return true if the tool should be enabled
+ */
+ public boolean shouldBeEnabled() {
+ int size = 0;
+ try {
+ Editor ce = Globals.curEditor();
+ Vector figs = ce.getSelectionManager().getFigs();
+ size = figs.size();
+ } catch (Exception e) {
+ // Ignore
+ }
+ if (size > 0) {
+ return true;
+ }
+ Object target = TargetManager.getInstance().getTarget();
+ if (target instanceof Diagram) { // we cannot delete the last diagram
+ return (ProjectManager.getManager().getCurrentProject()
+ .getDiagrams().size() > 1);
+ }
+ if (Model.getFacade().isAModel(target)
+ // we cannot delete the model itself
+ && target.equals(ProjectManager.getManager().getCurrentProject()
+ .getModel())) {
+ return false;
+ }
+ if (Model.getFacade().isAAssociationEnd(target)) {
+ return Model.getFacade().getOtherAssociationEnds(target).size() > 1;
+ }
+ if (Model.getStateMachinesHelper().isTopState(target)) {
+ /* we can not delete a "top" state,
+ * it comes and goes with the statemachine. Issue 2655.
+ */
+ return false;
+ }
+ return target != null;
+ }
} /* end class ActionRemoveFromModel */
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.