Author: tfmorris
Date: 2008-11-28 13:58:29-0800
New Revision: 16202
Modified:
trunk/src/argouml-app/src/org/argouml/kernel/ProjectManager.java
Log:
RESOLVED - Issue 5522: Defer settings current project on new until its fully set up. Protect undo code against null current project.
http://argouml.tigris.org/issues/show_bug.cgi?id=5522
Modified: trunk/src/argouml-app/src/org/argouml/kernel/ProjectManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/kernel/ProjectManager.java?view=diff&rev=16202&p1=trunk/src/argouml-app/src/org/argouml/kernel/ProjectManager.java&p2=trunk/src/argouml-app/src/org/argouml/kernel/ProjectManager.java&r1=16201&r2=16202
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/kernel/ProjectManager.java (original)
+++ trunk/src/argouml-app/src/org/argouml/kernel/ProjectManager.java 2008-11-28 13:58:29-0800
@@ -64,12 +64,14 @@
public final class ProjectManager implements ModelCommandCreationObserver {
/**
- * The name of the property that defines the current project.
+ * The name of the property that defines the current project. The values
+ * passed are Projects, not Strings. The 'name' here refers to the name
+ * of this property, not the name of the project.
*
* @deprecated for 0.27.2 by tfmorris. Listeners of this event which expect
* it to indicate a new project being opened should listen for
* {@link #OPEN_PROJECTS_PROPERTY}. Listeners who think
- * they need to know a single global current project name need
+ * they need to know a single global current project need
* to be changed to deal with things on a per-project basis.
*/
@Deprecated
@@ -184,19 +186,19 @@
/**
* Sets the current project (the project that is viewable in the
- * projectbrowser).
- * Sets the current diagram for the project (if one exists).
- * This method fires a propertychanged event.<p>
- *
+ * projectbrowser). Sets the current diagram for the project (if one
+ * exists). This method fires a propertychanged event.
+ * <p>
* If the argument is null, then the current project will be forgotten
* about.
- *
+ *
* @param newProject The new project.
- * @deprecated for 0.27.2 by tfmorris. There is no longer the concept of
- * a single global "current" project. In the future, multiple projects
- * will be able to be open at a time, so all code should be prepared to deal
- * with multiple projects and should require a Project to be passed as an
- * argument if they need access.
+ * @deprecated for 0.27.2 by tfmorris. There is no longer the concept of a
+ * single global "current" project. In the future, multiple
+ * projects will be able to be open at a time, so all code
+ * should be prepared to deal with multiple projects and should
+ * require a Project to be passed as an argument if they need
+ * access.
*/
public void setCurrentProject(Project newProject) {
Project oldProject = currentProject;
@@ -209,6 +211,10 @@
currentProject.setActiveDiagram(activeDiagram);
}
}
+ notifyProjectAdded(newProject, oldProject);
+ }
+
+ private void notifyProjectAdded(Project newProject, Project oldProject) {
firePropertyChanged(CURRENT_PROJECT_PROPERTY_NAME,
oldProject, newProject);
// TODO: Tentative implementation. Do we want something that updates
@@ -228,14 +234,15 @@
* <p>
*
* @return Project the current project or null if none
- * @deprecated for 0.27.2 by tfmorris. There is no longer the concept of
- * a single global "current" project. In the future, multiple projects
- * will be able to be open at a time, so all code should be prepared to deal
- * with multiple projects and should require a Project to be passed as an
- * argument if they need access. To get a list of all currently open
- * projects, use {@link #getOpenProjects()}. For settings which affect
- * renderings in diagrams use
- * {@link org.argouml.uml.diagram.ui.ArgoFig#getDiagramSettings()}.
+ * @deprecated for 0.27.2 by tfmorris. There is no longer the concept of a
+ * single global "current" project. In the future, multiple
+ * projects will be able to be open at a time, so all code
+ * should be prepared to deal with multiple projects and should
+ * require a Project to be passed as an argument if they need
+ * access. To get a list of all currently open projects, use
+ * {@link #getOpenProjects()}. For settings which affect
+ * renderings in diagrams use
+ * {@link org.argouml.uml.diagram.ui.ArgoFig#getSettings()}.
*/
public Project getCurrentProject() {
if (currentProject == null && !creatingCurrentProject) {
@@ -286,28 +293,19 @@
creatingCurrentProject = true;
LOG.info("making empty project");
Project newProject = new ProjectImpl();
- // Our project isn't really fully initialized yet, but the
- // UndoManager depends on having the current project set before
- // we can create our default Model
- setCurrentProject(newProject);
+ createDefaultModel(newProject);
if (addDefaultDiagrams) {
createDefaultDiagrams(newProject);
}
creatingCurrentProject = false;
- // The explorer appears to be listing for this in order
- // to refresh the project node.
- firePropertyChanged(CURRENT_PROJECT_PROPERTY_NAME,
- null, currentProject);
+ setCurrentProject(newProject);
Model.getPump().startPumpingEvents();
-
- if (saveAction != null) {
- saveAction.setEnabled(false);
- }
return null;
}
};
cmd.execute();
currentProject.getUndoManager().addCommand(cmd);
+ setSaveEnabled(false);
return currentProject;
}
@@ -318,14 +316,15 @@
* @param project the project to create the diagrams in.
*/
private void createDefaultDiagrams(Project project) {
- createDefaultModel(project);
Object model = project.getRoots().iterator().next();
DiagramFactory df = DiagramFactory.getInstance();
- ArgoDiagram d = df.createDiagram(DiagramFactory.DiagramType.Class,
- model, null);
+ ArgoDiagram d = df.create(DiagramFactory.DiagramType.Class,
+ model,
+ project.getProjectSettings().getDefaultDiagramSettings());
project.addMember(d);
- project.addMember(df.createDiagram(
- DiagramFactory.DiagramType.UseCase, model, null));
+ project.addMember(df.create(
+ DiagramFactory.DiagramType.UseCase, model,
+ project.getProjectSettings().getDefaultDiagramSettings()));
project.addMember(new ProjectMemberTodoList("",
project));
project.setActiveDiagram(d);
@@ -383,7 +382,6 @@
saveAction.setEnabled(newValue);
}
}
-
/**
* Remove the project.
@@ -391,11 +389,9 @@
* @param oldProject The project to be removed.
*/
public void removeProject(Project oldProject) {
-
if (currentProject == oldProject) {
currentProject = null;
}
-
oldProject.remove();
}
@@ -408,9 +404,7 @@
* @see org.argouml.model.ModelCommandCreationObserver#execute(ModelCommand)
*/
public Object execute(final ModelCommand command) {
- if (saveAction != null) {
- saveAction.setEnabled(true);
- }
+ setSaveEnabled(true);
AbstractCommand wrappedCommand = new AbstractCommand() {
private ModelCommand modelCommand = command;
public void undo() {
@@ -429,6 +423,11 @@
return modelCommand.toString();
}
};
- return getCurrentProject().getUndoManager().execute(wrappedCommand);
+ Project p = getCurrentProject();
+ if (p != null) {
+ return getCurrentProject().getUndoManager().execute(wrappedCommand);
+ } else {
+ return wrappedCommand.execute();
+ }
}
}
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.