svn commit: r15720 - trunk/src/argouml-app/src/org/argouml/uml/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2008-09-15 12:01:38-0700
New Revision: 15720

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/ui/ActionActivityDiagram.java
   trunk/src/argouml-app/src/org/argouml/uml/ui/ActionAddDiagram.java
   trunk/src/argouml-app/src/org/argouml/uml/ui/ActionNewDiagram.java
   trunk/src/argouml-app/src/org/argouml/uml/ui/ActionStateDiagram.java

Log:
Fix for issue 5393: Diagram toolbar action on profile diagram malfunctions.

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/ActionActivityDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/ActionActivityDiagram.java?view=diff&rev=15720&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionActivityDiagram.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionActivityDiagram.java&r1=15719&r2=15720
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/ActionActivityDiagram.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/ActionActivityDiagram.java	2008-09-15 12:01:38-0700
@@ -58,7 +58,7 @@
         Object context = TargetManager.getInstance().getModelTarget();
         
         if (!Model.getActivityGraphsHelper().isAddingActivityGraphAllowed(
-                context)) {
+                context) || Model.getModelManagementHelper().isReadOnly(context)) {
             context = namespace;
         } 
         Object graph = 

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/ActionAddDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/ActionAddDiagram.java?view=diff&rev=15720&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionAddDiagram.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionAddDiagram.java&r1=15719&r2=15720
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/ActionAddDiagram.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/ActionAddDiagram.java	2008-09-15 12:01:38-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-2008 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
@@ -25,6 +25,7 @@
 package org.argouml.uml.ui;
 
 import java.awt.event.ActionEvent;
+import java.util.Collection;
 
 import javax.swing.Action;
 
@@ -43,7 +44,11 @@
  * Abstract class that is the parent of all actions adding diagrams to ArgoUML.
  * The children of this class should implement createDiagram to do any specific
  * actions for creating a diagram and isValidNamespace that checks if some
- * namespace is valid to add the diagram to.
+ * namespace is valid to add the diagram to. <p>
+ * 
+ * ArgoUML shall never create a diagram for a read-only modelelement.<p>
+ * 
+ * TODO: This class should be merged with ActionNewDiagram.
  *
  * @author [email protected]
  */
@@ -71,7 +76,6 @@
      * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
      */
     public void actionPerformed(ActionEvent e) {
-    	super.actionPerformed(e);
         Project p = ProjectManager.getManager().getCurrentProject();
         Object ns = findNamespace();
 
@@ -98,8 +102,12 @@
         Project p = ProjectManager.getManager().getCurrentProject();
         Object target = TargetManager.getInstance().getModelTarget();
         Object ns = null;
-        if (target == null || !Model.getFacade().isAModelElement(target)) {
-            target = p.getRoot();
+        if (target == null || !Model.getFacade().isAModelElement(target)
+                || Model.getModelManagementHelper().isReadOnly(target)) {
+            Collection c = p.getRoots();
+            if ((c != null) && !c.isEmpty()) {
+                target = c.iterator().next();
+            } // else what?
         }
         if (Model.getFacade().isANamespace(target)) {
             ns = target;

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/ActionNewDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/ActionNewDiagram.java?view=diff&rev=15720&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionNewDiagram.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionNewDiagram.java&r1=15719&r2=15720
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/ActionNewDiagram.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/ActionNewDiagram.java	2008-09-15 12:01:38-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2006-2007 The Regents of the University of California. All
+// Copyright (c) 2006-2008 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
@@ -28,6 +28,7 @@
 
 import javax.swing.Action;
 
+import org.apache.log4j.Logger;
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 import org.argouml.i18n.Translator;
 import org.argouml.kernel.Project;
@@ -39,7 +40,10 @@
 import org.tigris.gef.undo.UndoableAction;
 
 /**
- * Abstract action to trigger creation of a new diagram.
+ * Abstract action to trigger creation of a new diagram. <p>
+ * 
+ * ArgoUML shall never create a diagram for a read-only modelelement.
+ * <p>
  * TODO: Bobs says, can we merge ActionAddDiagram with this class?
  * 
  * @author michiel
@@ -47,6 +51,12 @@
 public abstract class ActionNewDiagram extends UndoableAction {
 
     /**
+     * Logger.
+     */
+    private static final Logger LOG =
+        Logger.getLogger(ActionNewDiagram.class);
+
+    /**
      * The constructor.
      * @param name the i18n key for this action name.
      */
@@ -69,18 +79,35 @@
         // a project, this should be using the default Namespace (currently
         // undefined) or something similar 
         Project p = ProjectManager.getManager().getCurrentProject();
-        ArgoDiagram diagram = createDiagram(p.getRoot());
-        assert (diagram != null)
-        	: "No diagram was returned by the concrete class";
-
-        p.addMember(diagram);
-        //TODO: make the explorer listen to project member property
-        //changes...  to eliminate coupling on gui.
-        ExplorerEventAdaptor.getInstance().modelElementAdded(
-                diagram.getNamespace());
-        TargetManager.getInstance().setTarget(diagram);
+        Object ns = findNamespace();
+        
+        if (ns != null && isValidNamespace(ns)) {
+            ArgoDiagram diagram = createDiagram(ns);
+            assert (diagram != null)
+            : "No diagram was returned by the concrete class";
+
+            p.addMember(diagram);
+            //TODO: make the explorer listen to project member property
+            //changes...  to eliminate coupling on gui.
+            ExplorerEventAdaptor.getInstance().modelElementAdded(
+                    diagram.getNamespace());
+            TargetManager.getInstance().setTarget(diagram);
+        } else {
+            LOG.error("No valid namespace found");
+            throw new IllegalStateException("No valid namespace found");
+        }
     }
-    
+
+    /**
+     * Find the right namespace for the diagram.
+     *
+     * @return the namespace or null
+     */
+    protected Object findNamespace() {
+        Project p = ProjectManager.getManager().getCurrentProject();
+        return p.getRoot();
+    }
+
     /**
      * @param namespace the namespace in which to create the diagram
      * @return the new diagram
@@ -88,6 +115,18 @@
     protected abstract ArgoDiagram createDiagram(Object namespace);
 
     /**
+     * Test if the given namespace is a valid namespace to add the diagram to.
+     * TODO: This method was created to facilitate the merge 
+     * of this class with ActionAddDiagram.
+     *
+     * @param ns the namespace to check
+     * @return Returns <code>true</code> if valid.
+     */
+    public boolean isValidNamespace(Object ns) {
+        return true;
+    }
+
+    /**
      * Utility function to create a collaboration.
      * 
      * @return a new collaboration
@@ -109,6 +148,9 @@
      */
     protected static Object createCollaboration(Object namespace) {
         Object target = TargetManager.getInstance().getModelTarget();
+        if (Model.getModelManagementHelper().isReadOnly(target)) {
+            target = namespace;
+        }
         Object collaboration = null;
         if (Model.getFacade().isAOperation(target)) {
             Object ns = Model.getFacade().getNamespace(

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/ActionStateDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/ActionStateDiagram.java?view=diff&rev=15720&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionStateDiagram.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/ActionStateDiagram.java&r1=15719&r2=15720
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/ActionStateDiagram.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/ActionStateDiagram.java	2008-09-15 12:01:38-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2008 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
@@ -28,8 +28,8 @@
 import org.argouml.kernel.ProjectManager;
 import org.argouml.model.Model;
 import org.argouml.ui.targetmanager.TargetManager;
-import org.argouml.uml.diagram.DiagramFactory;
 import org.argouml.uml.diagram.ArgoDiagram;
+import org.argouml.uml.diagram.DiagramFactory;
 import org.argouml.uml.diagram.state.ui.UMLStateDiagram;
 
 /**
@@ -49,6 +49,9 @@
      */
     protected ArgoDiagram createDiagram(Object namespace) {
         Object target = TargetManager.getInstance().getModelTarget();
+        if (Model.getModelManagementHelper().isReadOnly(target)) {
+            target = namespace;
+        }
         Object machine = null;
         if (Model.getStateMachinesHelper().isAddingStatemachineAllowed(
               target)) {
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.