Change null session to singleton with no owner
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 2 Oct 2015 11:38:44 +0000 (13:38 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 2 Oct 2015 11:38:44 +0000 (13:38 +0200)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/NullSession.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/CdmPreferencePage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/SessionsViewPart.java

index 5344a4800ace2dd333855ecfaba04f0ad9e371ee..84be7d87176ac0dc72d153c09c8674f12d622b31 100644 (file)
@@ -62,12 +62,10 @@ public class CdmEntitySessionManager implements ICdmEntitySessionManager {
     }
 
     @Override
-    public ICdmEntitySession bindNullSession(ICdmEntitySessionEnabled sessionOwner) {
+    public ICdmEntitySession bindNullSession() {
 
         if(nullSession == null) {
-            nullSession = new NullSession(sessionOwner, this);
-        } else {
-            nullSession.setOwner(sessionOwner);
+            nullSession = new NullSession(null, this);
         }
 
         setActiveSession(nullSession);
@@ -197,6 +195,15 @@ public class CdmEntitySessionManager implements ICdmEntitySessionManager {
         if(session != null) {
             session.dispose();
         }
+        if(nullSession != null && nullSession.getOwner() == owner) {
+            nullSession = null;
+        }
+        notifyObservers();
+    }
+
+    @Override
+    public void disposeNullSession() {
+        nullSession = null;
         notifyObservers();
     }
 
index 27e23a02f87ee80b1374fca377bd079f29be4ac7..1800003818b5750915666e88ab73f4657067d7e5 100644 (file)
@@ -13,7 +13,7 @@ public interface ICdmEntitySessionManager {
      * @param sessionOwner
      * @return
      */
-    public ICdmEntitySession bindNullSession(ICdmEntitySessionEnabled sessionOwner);
+    public ICdmEntitySession bindNullSession();
 
 
        public abstract void bind(ICdmEntitySessionEnabled sessionOwner);
@@ -72,4 +72,9 @@ public interface ICdmEntitySessionManager {
      */
     public ICdmEntitySession getNullSession();
 
+    /**
+     *
+     */
+    public void disposeNullSession();
+
 }
\ No newline at end of file
index 130167c2cea250a02d8fb99d3b9dc88726615e73..65b8e7c245481d78c085db7d91c2dbaa73f35943 100644 (file)
@@ -141,7 +141,7 @@ public class NullSession implements ICdmEntitySession {
      */
     @Override
     public void bind() {
-        cdmEntitySessionManager.bindNullSession(sessionOwner);
+        cdmEntitySessionManager.bindNullSession();
     }
 
     /* (non-Javadoc)
index 081cffbcfe838ca3a583f02d36c93a72a192851b..9eeabb7a5bbbbb00ba5f1880ee7978429c88a3d6 100644 (file)
@@ -122,7 +122,7 @@ public class MockCdmEntitySessionManager implements ICdmEntitySessionManager {
      * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#bindNullSession(eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled)
      */
     @Override
-    public ICdmEntitySession bindNullSession(ICdmEntitySessionEnabled sessionOwner) {
+    public ICdmEntitySession bindNullSession() {
         return new MockCdmEntitySession();
     }
 
@@ -134,6 +134,15 @@ public class MockCdmEntitySessionManager implements ICdmEntitySessionManager {
         return new MockCdmEntitySession();
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#disposeNullSession()
+     */
+    @Override
+    public void disposeNullSession() {
+        // TODO Auto-generated method stub
+
+    }
+
 
 
 }
index 756d1461b4996553056138928e572e5f2260982a..c52f692666b7faa3c862105e413726eb2bd1b10b 100644 (file)
@@ -38,13 +38,13 @@ public abstract class CdmPreferencePage extends PreferencePage implements ICdmEn
 
     private void bindNullSession() {
         if(CdmStore.isActive()) {
-            CdmStore.getCurrentSessionManager().bindNullSession(this);
+            CdmStore.getCurrentSessionManager().bindNullSession();
         }
     }
 
     protected void disposeNullSession() {
         if(CdmStore.isActive()) {
-            CdmStore.getCurrentSessionManager().dispose(this);
+            CdmStore.getCurrentSessionManager().disposeNullSession();
         }
     }
 
index 7a876f545bc833655936bec3bdabe1791bd0d2b1..b53b064e53d61cdab87f79c7912b08fa4083b318 100644 (file)
@@ -63,7 +63,7 @@ public class AvailableDistributionPage extends WizardPage implements ICdmEntityS
     protected AvailableDistributionPage(String pageName) {
         super(pageName);
         // TODO check if configuration exists
-        CdmStore.getCurrentSessionManager().bindNullSession(this);
+        CdmStore.getCurrentSessionManager().bindNullSession();
     }
 
     /*
index 07c94bbb85deb401bb163cf53ecac2c56cb0a095..9947664f697bc0e42968293e65e2a22d5690f3d9 100644 (file)
@@ -39,6 +39,7 @@ import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManagerObserver;
+import eu.etaxonomy.taxeditor.session.NullSession;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -259,18 +260,11 @@ public class SessionsViewPart extends ViewPart implements ICdmEntitySessionManag
             Collection<ICdmEntitySession> sessions = cdmEntitySessionManager.getSessions();
             txtNoOfSessions.setText(String.valueOf(sessions.size()));
             for(ICdmEntitySession session : sessions) {
-                if(session.getOwner() != null) {
-                    TableItem item = new TableItem(tableSessions, SWT.NULL);
-                    item.setText(session.getOwner().toString());
-                    String activePrefix = "";
-                    if(session.isActive()) {
-                        activePrefix = "*";
-                    }
-                    item.setText(0, activePrefix + session.getOwner().toString());
-                    LiveCacheStatistics cacheStatistics = session.getCacheStatistics();
-                    item.setText(1, getInMemoryStats(cacheStatistics));
-                    item.setText(2, getOnDiskStats(cacheStatistics));
-                }
+                addSession(session);
+            }
+            ICdmEntitySession nullSession = cdmEntitySessionManager.getNullSession();
+            if(nullSession != null) {
+                addSession(nullSession);
             }
             for (int i=0; i<titles.length; i++) {
                 tableSessions.getColumn (i).pack ();
@@ -301,6 +295,28 @@ public class SessionsViewPart extends ViewPart implements ICdmEntitySessionManag
 
     }
 
+    private void addSession(ICdmEntitySession session) {
+
+        TableItem item = new TableItem(tableSessions, SWT.NULL);
+
+        String activePrefix = "";
+        if(session.isActive()) {
+            activePrefix = "*";
+        }
+        String sessionOwnerString = "";
+        if(session instanceof NullSession) {
+            sessionOwnerString = "Null Session";
+        } else {
+            if(session.getOwner() != null) {
+                sessionOwnerString = session.getOwner().toString();
+            }
+        }
+        item.setText(0, activePrefix + sessionOwnerString);
+        LiveCacheStatistics cacheStatistics = session.getCacheStatistics();
+        item.setText(1, getInMemoryStats(cacheStatistics));
+        item.setText(2, getOnDiskStats(cacheStatistics));
+    }
+
     private String getInMemoryStats(LiveCacheStatistics statistics) {
         if(statistics != null) {
             long localHeapSize = statistics.getLocalHeapSize();