Revision: 5566
          http://sourceforge.net/p/jump-pilot/code/5566
Author:   jammerhund
Date:     2017-11-17 20:38:59 +0000 (Fri, 17 Nov 2017)
Log Message:
-----------
  * added methods for handling multiple ApplicationExitHandler in the
    WorkbenchFrame. Set the old getApplicationExitHandler() and
    setApplicationExitHandler() methods deprecated.
  * ConnectionManager adjusted for the new ApplicationExitHandler stuff.

Modified Paths:
--------------
    core/trunk/ChangeLog
    
core/trunk/src/com/vividsolutions/jump/workbench/datastore/ConnectionManager.java
    core/trunk/src/com/vividsolutions/jump/workbench/ui/WorkbenchFrame.java

Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog        2017-11-14 10:47:59 UTC (rev 5565)
+++ core/trunk/ChangeLog        2017-11-17 20:38:59 UTC (rev 5566)
@@ -3,6 +3,12 @@
 # 2. make sure that lines break at 80 chars for constricted display situations
 #<-------------------------------- 80 chars 
---------------------------------->#
 
+2017-11-17 Matthias Scholz <m...@jammerhund.de>
+  * added methods for handling multiple ApplicationExitHandler in the
+    WorkbenchFrame. Set the old getApplicationExitHandler() and
+    setApplicationExitHandler() methods deprecated.
+  * ConnectionManager adjusted for the new ApplicationExitHandler stuff.
+
 2017-11-13 Giuseppe Aruta. 
   * RasterImageLayer <Sextante>: Spatial reference system srid and its 
location 
     are now stored as metadata on loading file. Updated Raster Info plugin.

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/datastore/ConnectionManager.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/datastore/ConnectionManager.java
   2017-11-14 10:47:59 UTC (rev 5565)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/datastore/ConnectionManager.java
   2017-11-17 20:38:59 UTC (rev 5566)
@@ -73,10 +73,8 @@
         });
         
         // close all connections on exit
-        final ApplicationExitHandler oldApplicationExitHandler = context
-            .getWorkbench().getFrame().getApplicationExitHandler();
         context.getWorkbench().getFrame()
-            .setApplicationExitHandler(new ApplicationExitHandler() {
+            .addApplicationExitHandler(new ApplicationExitHandler() {
               public void exitApplication(JFrame mainFrame) {
                 try {
                   closeConnections();
@@ -83,7 +81,6 @@
                 } catch (DataStoreException e) {
                   throw new RuntimeException(e);
                 }
-                oldApplicationExitHandler.exitApplication(mainFrame);
               }
             });
     }

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/WorkbenchFrame.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/WorkbenchFrame.java     
2017-11-14 10:47:59 UTC (rev 5565)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/WorkbenchFrame.java     
2017-11-17 20:38:59 UTC (rev 5566)
@@ -145,6 +145,7 @@
 import com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager;
 import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog;
 import com.vividsolutions.jump.workbench.ui.zoom.ZoomToCoordinatePlugIn;
+import java.util.List;
 
 /**
  * This class is responsible for the main window of the JUMP application.
@@ -405,6 +406,8 @@
     private Set choosableStyleClasses = new HashSet();
 
     private ArrayList<TaskListener> taskListeners = new 
ArrayList<TaskListener>();
+    
+    private ArrayList<ApplicationExitHandler> applicationExitHandlers = new 
ArrayList<>();
 
     private Map nodeClassToLayerNamePopupMenuMap = CollectionUtil
             .createMap(new Object[] { Layer.class, layerNamePopupMenu,
@@ -1377,6 +1380,13 @@
     }
 
     private void closeApplication() {
+        // run all applicationExitHandlers
+        Object[] handlers = applicationExitHandlers.toArray();
+        for (Object handler : handlers) {
+            ((ApplicationExitHandler)handler).exitApplication(this);
+        }
+        
+        // for compatibilty reasons run the old applicationExitHandler as last
         applicationExitHandler.exitApplication(this);
     }
 
@@ -1808,13 +1818,57 @@
         internalFrameCloseHandler = value;
     }
 
+    /**
+     * You should use the new addApplicationExitHandler(),
+     * removeApplicationExitHandler(), getApplicationExitHandlers() methods.
+     * 
+     * @return
+     * @deprecated
+     */
+    @Deprecated
     public ApplicationExitHandler getApplicationExitHandler() {
         return applicationExitHandler;
     }
 
+    /**
+     * You should use the new addApplicationExitHandler(),
+     * removeApplicationExitHandler(), getApplicationExitHandlers() methods.
+     * 
+     * @return
+     * @deprecated
+     */
+    @Deprecated
     public void setApplicationExitHandler(ApplicationExitHandler value) {
         applicationExitHandler = value;
     }
+    
+    /**
+     * Gets the ApplicationExitHandlers.
+     * 
+     * @return the ApplicationExitHandlers
+     */
+    public List<ApplicationExitHandler> getApplicationExitHandlers() {
+        return applicationExitHandlers;
+    }
+    
+    /**
+     * Adds an ApplicationExitHandler, wich will be executed if the
+     * WorkbenchFrame gets closing.
+     * 
+     * @param aeh the ApplicationExitHandler to add
+     */
+    public void addApplicationExitHandler(ApplicationExitHandler aeh) {
+        applicationExitHandlers.add(aeh);
+    }
+    
+    /**
+     * Remove's the given ApplicationExitHandler.
+     * 
+     * @param aeh the ApplicationExitHandler to remove
+     */
+    public void removeApplicationExitHandler(ApplicationExitHandler aeh) {
+        applicationExitHandlers.remove(aeh);
+    }
 
     private class DefaultInternalFrameCloser implements
             InternalFrameCloseHandler {


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to