Fixed unnecessary showing of dialog related to saving tool changes

This commit is contained in:
dragonmacher 2022-11-17 10:41:55 -05:00
parent 279b58a6e2
commit 6736068df2

View file

@ -86,8 +86,8 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
} }
/** /**
* Registers the new instance of the tool in the namesMap and returns the total number of * Registers the new instance of the tool in the namesMap and returns the total number of
* running instances of that tool * running instances of that tool
* @param toolName the name of the tool being registers * @param toolName the name of the tool being registers
* @param tool the tool being registered * @param tool the tool being registered
@ -208,8 +208,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
wsMap.put(name, ws); wsMap.put(name, ws);
// notify listeners of added workspace // notify listeners of added workspace
for (int i = 0; i < changeListeners.size(); i++) { for (WorkspaceChangeListener listener : changeListeners) {
WorkspaceChangeListener listener = changeListeners.get(i);
listener.workspaceAdded(ws); listener.workspaceAdded(ws);
} }
@ -250,8 +249,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
wsMap.remove(wsName); wsMap.remove(wsName);
// notify listeners of removed workspace // notify listeners of removed workspace
for (int i = 0; i < changeListeners.size(); i++) { for (WorkspaceChangeListener listener : changeListeners) {
WorkspaceChangeListener listener = changeListeners.get(i);
listener.workspaceRemoved(ws); listener.workspaceRemoved(ws);
} }
@ -288,8 +286,8 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
Element root = new Element("TOOL_MANAGER"); Element root = new Element("TOOL_MANAGER");
root.setAttribute("ACTIVE_WORKSPACE", activeWorkspace.getName()); root.setAttribute("ACTIVE_WORKSPACE", activeWorkspace.getName());
for (int i = 0; i < workspaces.size(); i++) { for (Workspace element : workspaces) {
WorkspaceImpl ws = (WorkspaceImpl) workspaces.get(i); WorkspaceImpl ws = (WorkspaceImpl) element;
root.addContent(ws.saveToXml()); root.addContent(ws.saveToXml());
} }
Iterator<String> keys = connectMap.keySet().iterator(); Iterator<String> keys = connectMap.keySet().iterator();
@ -306,7 +304,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
/** /**
* restores the object from an XML element * restores the object from an XML element
* *
* @param root root element of saved XML state * @param root root element of saved XML state
*/ */
public void restoreFromXml(Element root) { public void restoreFromXml(Element root) {
@ -381,13 +379,13 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
* Close all running tools in the project. * Close all running tools in the project.
*/ */
public void close() { public void close() {
for (int i = 0; i < workspaces.size(); i++) { for (Workspace element : workspaces) {
WorkspaceImpl w = (WorkspaceImpl) workspaces.get(i); WorkspaceImpl w = (WorkspaceImpl) element;
w.close(); w.close();
} }
} }
/** /**
* Save the tools that are opened and changed, that will be brought back up when the project * Save the tools that are opened and changed, that will be brought back up when the project
* is reopened * is reopened
* @return true if the session was saved * @return true if the session was saved
@ -518,7 +516,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
/** /**
* Get any tool services available from this tool * Get any tool services available from this tool
* *
* @return ToolServices list of tool services this tool can provide. * @return ToolServices list of tool services this tool can provide.
*/ */
public ToolServices getToolServices() { public ToolServices getToolServices() {
@ -557,14 +555,14 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
/** /**
* Close a tool. * Close a tool.
* *
* @param tool tool to be closed. * @param tool tool to be closed.
*/ */
void closeTool(PluginTool tool) { void closeTool(PluginTool tool) {
// find the workspace running the tool // find the workspace running the tool
for (int i = 0; i < workspaces.size(); i++) { for (Workspace element : workspaces) {
WorkspaceImpl ws = (WorkspaceImpl) workspaces.get(i); WorkspaceImpl ws = (WorkspaceImpl) element;
PluginTool[] tools = ws.getTools(); PluginTool[] tools = ws.getTools();
for (PluginTool tool2 : tools) { for (PluginTool tool2 : tools) {
if (tool == tool2) { if (tool == tool2) {
@ -577,7 +575,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
/** /**
* Set the active workspace. * Set the active workspace.
* *
* @param workspace workspace to set active * @param workspace workspace to set active
*/ */
void setActiveWorkspace(WorkspaceImpl workspace) { void setActiveWorkspace(WorkspaceImpl workspace) {
@ -600,17 +598,16 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
activeWorkspace = workspace; activeWorkspace = workspace;
// notify listeners of new active workspace // notify listeners of new active workspace
for (int i = 0; i < changeListeners.size(); i++) { for (WorkspaceChangeListener listener : changeListeners) {
WorkspaceChangeListener listener = changeListeners.get(i);
listener.workspaceSetActive(activeWorkspace); listener.workspaceSetActive(activeWorkspace);
} }
} }
/** /**
* Get a handle to the workspace with the given name. * Get a handle to the workspace with the given name.
* *
* @param name name of the workspace. * @param name name of the workspace.
* *
* @return workspace handle if one exists. * @return workspace handle if one exists.
*/ */
Workspace getWorkspace(String name) { Workspace getWorkspace(String name) {
@ -619,7 +616,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
/** /**
* Mark workspace as changed. * Mark workspace as changed.
* *
* @param ws workspace to tag * @param ws workspace to tag
*/ */
void setWorkspaceChanged(WorkspaceImpl ws) { void setWorkspaceChanged(WorkspaceImpl ws) {
@ -631,10 +628,10 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
/** /**
* Called by the workspace when it is updating its name; * Called by the workspace when it is updating its name;
* causes a property change event to be fired. * causes a property change event to be fired.
* *
* @param ws workspace to rename * @param ws workspace to rename
* @param name new name of workspace * @param name new name of workspace
* *
* @throws DuplicateNameException if there already exists a workspace by the given name * @throws DuplicateNameException if there already exists a workspace by the given name
*/ */
void setWorkspaceName(Workspace ws, String name) throws DuplicateNameException { void setWorkspaceName(Workspace ws, String name) throws DuplicateNameException {
@ -648,8 +645,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
// fire property change event // fire property change event
PropertyChangeEvent event = PropertyChangeEvent event =
new PropertyChangeEvent(this, WORKSPACE_NAME_PROPERTY, ws.getName(), name); new PropertyChangeEvent(this, WORKSPACE_NAME_PROPERTY, ws.getName(), name);
for (int i = 0; i < changeListeners.size(); i++) { for (WorkspaceChangeListener l : changeListeners) {
WorkspaceChangeListener l = changeListeners.get(i);
l.propertyChange(event); l.propertyChange(event);
} }
} }
@ -672,8 +668,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
deregisterTool(tool.getToolName(), tool); deregisterTool(tool.getToolName(), tool);
disconnectTool(tool); disconnectTool(tool);
for (int i = 0; i < changeListeners.size(); i++) { for (WorkspaceChangeListener l : changeListeners) {
WorkspaceChangeListener l = changeListeners.get(i);
l.toolRemoved(ws, tool); l.toolRemoved(ws, tool);
} }
} }
@ -714,8 +709,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
} }
void fireToolAddedEvent(Workspace ws, PluginTool tool) { void fireToolAddedEvent(Workspace ws, PluginTool tool) {
for (int i = 0; i < changeListeners.size(); i++) { for (WorkspaceChangeListener l : changeListeners) {
WorkspaceChangeListener l = changeListeners.get(i);
l.toolAdded(ws, tool); l.toolAdded(ws, tool);
} }
} }
@ -758,10 +752,10 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
/** /**
* Get the key for the connection map. * Get the key for the connection map.
* *
* @param producer tool producing an event * @param producer tool producing an event
* @param consumer tool consuming an event * @param consumer tool consuming an event
* *
*/ */
private String getKey(PluginTool producer, PluginTool consumer) { private String getKey(PluginTool producer, PluginTool consumer) {
return producer.getName() + "+" + consumer.getName(); return producer.getName() + "+" + consumer.getName();
@ -778,8 +772,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
private void firePropertyChangeEvent(PropertyChangeEvent ev) { private void firePropertyChangeEvent(PropertyChangeEvent ev) {
// notify listeners of tool change // notify listeners of tool change
for (int i = 0; i < changeListeners.size(); i++) { for (WorkspaceChangeListener l : changeListeners) {
WorkspaceChangeListener l = changeListeners.get(i);
l.propertyChange(ev); l.propertyChange(ev);
} }
} }
@ -812,7 +805,7 @@ public class ToolManagerImpl implements ToolManager, PropertyChangeListener {
} }
// we are in auto mode...if there is only one tool, then we can auto save // we are in auto mode...if there is only one tool, then we can auto save
if (getToolInstanceCount(tool) == 1) { if (getToolInstanceCount(tool) <= 1) {
return true; return true;
} }