svn commit: r16324 - trunk/src/argouml-app/src/org/argouml/uml/reveng/DiagramInterface.java

Tom Morris <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2008-12-11 08:33:34-0800
New Revision: 16324

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/reveng/DiagramInterface.java

Log:
Get project from diagram rather than global state

Modified: trunk/src/argouml-app/src/org/argouml/uml/reveng/DiagramInterface.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/reveng/DiagramInterface.java?view=diff&pathrev=16324&r1=16323&r2=16324
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/reveng/DiagramInterface.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/reveng/DiagramInterface.java	2008-12-11 08:33:34-0800
@@ -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
@@ -27,11 +27,9 @@
 import java.beans.PropertyVetoException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Vector;
 
 import org.apache.log4j.Logger;
 import org.argouml.kernel.Project;
-import org.argouml.kernel.ProjectManager;
 import org.argouml.model.Model;
 import org.argouml.uml.diagram.ArgoDiagram;
 import org.argouml.uml.diagram.DiagramFactory;
@@ -59,19 +57,14 @@
     private static final char DIAGRAM_NAME_SEPARATOR = '_';
     private static final String DIAGRAM_NAME_SUFFIX = "classes";
 
-    /**
-     * Logger.
-     */
     private static final Logger LOG =
         Logger.getLogger(DiagramInterface.class);
-    
-
 
     private Editor currentEditor;
 
     /**
      * To know what diagrams we have to layout after the import,
-     * we store them in this Vector.
+     * we store them in this list.
      */
     private List<ArgoDiagram> modifiedDiagrams = 
         new ArrayList<ArgoDiagram>();
@@ -91,6 +84,8 @@
      */
     private ArgoDiagram currentDiagram;
 
+    private Project currentProject;
+    
     /**
      * Creates a new DiagramInterface.
      *
@@ -98,9 +93,22 @@
      */
     public DiagramInterface(Editor editor) {
   	currentEditor = editor;
+  	LayerPerspective layer = 
+  	    (LayerPerspective) editor.getLayerManager().getActiveLayer();
+  	currentProject = ((ArgoDiagram) layer.getDiagram()).getProject();
     }
 
     /**
+     * Creates a new DiagramInterface.
+     *
+     * @param editor The editor to operate on.
+     * @param project the project being operated on
+     */
+    public DiagramInterface(Editor editor, Project project) {
+        currentEditor = editor;
+    }
+    
+    /**
      * Get the current editor.
      *
      * @return The current editor.
@@ -181,8 +189,10 @@
      * @return true if diagram exists in project.
      */
     public boolean isDiagramInProject(String name) {
-        Project project = ProjectManager.getManager().getCurrentProject();
-        return project.getDiagram(getDiagramName(name)) != null;
+        if (currentProject == null) {
+            throw new RuntimeException("current project not set yet");
+        }
+        return currentProject.getDiagram(getDiagramName(name)) != null;
     }
 
     /**
@@ -212,8 +222,10 @@
      */
     public void selectClassDiagram(Object p, String name) {
         // Check if this diagram already exists in the project
-        Project project = ProjectManager.getManager().getCurrentProject();
-        ArgoDiagram m = project.getDiagram(getDiagramName(name));
+        if (currentProject == null) {
+            throw new RuntimeException("current project not set yet");
+        }
+        ArgoDiagram m = currentProject.getDiagram(getDiagramName(name));
         if (m != null) {
             // The diagram already exists in this project. Select it
             // as the current target.
@@ -235,18 +247,19 @@
      *            generate the diagram name from.
      */
     public void addClassDiagram(Object ns, String name) {
-        Project p = ProjectManager.getManager().getCurrentProject();
-
+        if (currentProject == null) {
+            throw new RuntimeException("current project not set yet");
+        }
         ArgoDiagram d = DiagramFactory.getInstance().createDiagram(
                 DiagramFactory.DiagramType.Class,
-                ns == null ? p.getRoot() : ns, null);
+                ns == null ? currentProject.getRoot() : ns, null);
 
         try {
             d.setName(getDiagramName(name));
         } catch (PropertyVetoException pve) { 
             LOG.error("Failed to set diagram name.", pve);
         }
-        p.addMember(d);
+        currentProject.addMember(d);
         setCurrentDiagram(d);
     }
 
@@ -350,7 +363,8 @@
         currentGM = (ClassDiagramGraphModel) diagram.getGraphModel();
         currentLayer = diagram.getLayer();
         currentDiagram = diagram;
-
+        currentProject = diagram.getProject();
+        
         markDiagramAsModified(diagram);
     }

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

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.