Skip to content

Commit e3f5585

Browse files
committed
Don't save model when cytoscape is shutting down
1 parent c75e223 commit e3f5585

File tree

4 files changed

+33
-38
lines changed

4 files changed

+33
-38
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/CyActivator.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.baderlab.csplugins.enrichmentmap.commands.BuildEnrichmentMapTuneableTaskFactory;
88
import org.baderlab.csplugins.enrichmentmap.commands.EnrichmentMapGSEACommandHandlerTaskFactory;
99
import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMapManager;
10+
import org.baderlab.csplugins.enrichmentmap.model.io.SessionListener;
1011
import org.baderlab.csplugins.enrichmentmap.style.ChartFactoryManager;
1112
import org.baderlab.csplugins.enrichmentmap.style.charts.radialheatmap.RadialHeatMapChartFactory;
1213
import org.baderlab.csplugins.enrichmentmap.view.control.ControlPanelMediator;
@@ -93,18 +94,21 @@ public void start(BundleContext bc) {
9394
Em21Handler.removeVersion21(bc, injector.getInstance(CyApplicationConfiguration.class));
9495
}
9596

97+
9698
@Override
9799
public void shutDown() {
98-
if (injector != null) {
99-
// If the App gets updated or restarted we need to save all the data first
100-
SessionListener sessionListener = injector.getInstance(SessionListener.class);
101-
sessionListener.save();
102-
103-
// Also close the legend panel
104-
LegendPanelMediator legendPanelMediator = injector.getInstance(LegendPanelMediator.class);
105-
legendPanelMediator.hideDialog();
100+
try {
101+
if (injector != null) {
102+
// If the App gets updated or restarted we need to save all the data first
103+
SessionListener sessionListener = injector.getInstance(SessionListener.class);
104+
sessionListener.appShutdown();
105+
106+
// Close the legend panel
107+
LegendPanelMediator legendPanelMediator = injector.getInstance(LegendPanelMediator.class);
108+
legendPanelMediator.hideDialog();
109+
}
110+
} finally {
111+
super.shutDown();
106112
}
107-
108-
super.shutDown();
109113
}
110114
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/SessionListener.java renamed to EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/model/io/SessionListener.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package org.baderlab.csplugins.enrichmentmap;
1+
package org.baderlab.csplugins.enrichmentmap.model.io;
22

3-
import org.baderlab.csplugins.enrichmentmap.model.io.SessionModelIO;
43
import org.baderlab.csplugins.enrichmentmap.view.control.io.SessionViewIO;
4+
import org.cytoscape.application.events.CyShutdownEvent;
5+
import org.cytoscape.application.events.CyShutdownListener;
56
import org.cytoscape.session.CySession;
67
import org.cytoscape.session.events.SessionAboutToBeSavedEvent;
78
import org.cytoscape.session.events.SessionAboutToBeSavedListener;
@@ -12,15 +13,16 @@
1213
import com.google.inject.Singleton;
1314

1415
@Singleton
15-
public class SessionListener implements SessionLoadedListener, SessionAboutToBeSavedListener {
16+
public class SessionListener implements SessionLoadedListener, SessionAboutToBeSavedListener, CyShutdownListener {
1617

1718
@Inject private SessionModelIO modelIO;
1819
@Inject private SessionViewIO viewIO;
1920

21+
private boolean cytoscapeShuttingDown = false;
22+
2023
@Override
2124
public void handleEvent(SessionLoadedEvent event) {
22-
CySession session = event.getLoadedSession();
23-
restore(session);
25+
restore(event.getLoadedSession());
2426
}
2527

2628
@Override
@@ -37,4 +39,16 @@ public void restore(CySession session) {
3739
modelIO.restoreModel(session);
3840
viewIO.restoreView(session);
3941
}
42+
43+
@Override
44+
public void handleEvent(CyShutdownEvent e) {
45+
cytoscapeShuttingDown = e.actuallyShutdown();
46+
}
47+
48+
public void appShutdown() {
49+
if(!cytoscapeShuttingDown) {
50+
// the App is being updated or restarted, we want to save all the data first
51+
save();
52+
}
53+
}
4054
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/model/io/SessionModelIO.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.baderlab.csplugins.enrichmentmap.model.io;
22

3-
import java.awt.event.ActionEvent;
43
import java.util.ArrayList;
5-
import java.util.Arrays;
64
import java.util.HashSet;
75
import java.util.List;
86
import java.util.Map;
@@ -16,7 +14,6 @@
1614
import org.baderlab.csplugins.enrichmentmap.style.ColumnDescriptor;
1715
import org.baderlab.csplugins.enrichmentmap.view.control.ControlPanelMediator;
1816
import org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapMediator;
19-
import org.cytoscape.application.swing.AbstractCyAction;
2017
import org.cytoscape.model.CyColumn;
2118
import org.cytoscape.model.CyEdge;
2219
import org.cytoscape.model.CyIdentifiable;
@@ -91,10 +88,6 @@ public void saveModel() {
9188
});
9289
}
9390

94-
public void restoreModel() {
95-
restoreModel(null);
96-
}
97-
9891
public void restoreModel(CySession session) {
9992
if(debug)
10093
System.out.println("SessionModelListener.restoreModel()");
@@ -239,16 +232,4 @@ private void clearTable(CyTable table) {
239232
table.deleteRows(rowKeys);
240233
}
241234

242-
243-
@SuppressWarnings("serial")
244-
public List<AbstractCyAction> getDebugActions() {
245-
return Arrays.asList(
246-
new AbstractCyAction(CyActivator.APP_NAME + ": Save Model") {
247-
{setPreferredMenu("Apps");}
248-
public void actionPerformed(ActionEvent e) {
249-
saveModel();
250-
}
251-
}
252-
);
253-
}
254235
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/control/io/SessionViewIO.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ public void saveView() {
6464
});
6565
}
6666

67-
public void restoreView() {
68-
restoreView(null);
69-
}
70-
7167
public void restoreView(CySession session) {
7268
if (!headless) {
7369
CyTable table = getPrivateTable();

0 commit comments

Comments
 (0)