cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: Modeler: Update MacOS specific initialization code
Date Wed, 15 Mar 2017 11:59:37 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master f95a813cf -> f8bb12770


Modeler: Update MacOS specific initialization code


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/f8bb1277
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/f8bb1277
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/f8bb1277

Branch: refs/heads/master
Commit: f8bb127708c652ace34ae20d23e40f2ecd8dfcda
Parents: f95a813
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Wed Mar 15 14:59:25 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Wed Mar 15 14:59:25 2017 +0300

----------------------------------------------------------------------
 .../modeler/osx/OSXPlatformInitializer.java     | 59 +++++++++-----------
 .../cayenne/modeler/action/ExitAction.java      |  5 +-
 2 files changed, 30 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/f8bb1277/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
index eaab47c..21142f5 100644
--- a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
+++ b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
@@ -36,9 +36,12 @@ import org.apache.cayenne.modeler.action.ConfigurePreferencesAction;
 import org.apache.cayenne.modeler.action.ExitAction;
 import org.apache.cayenne.modeler.init.platform.PlatformInitializer;
 
+import com.apple.eawt.AboutHandler;
+import com.apple.eawt.AppEvent;
 import com.apple.eawt.Application;
-import com.apple.eawt.ApplicationAdapter;
-import com.apple.eawt.ApplicationEvent;
+import com.apple.eawt.PreferencesHandler;
+import com.apple.eawt.QuitHandler;
+import com.apple.eawt.QuitResponse;
 
 @SuppressWarnings("deprecation")
 public class OSXPlatformInitializer implements PlatformInitializer {
@@ -52,18 +55,34 @@ public class OSXPlatformInitializer implements PlatformInitializer {
         // launcher can only be executed on Mac
 
         // configure special Mac menu handlers though...
+        Application app = Application.getApplication();
+        app.setAboutHandler(new AboutHandler() {
+            @Override
+            public void handleAbout(AppEvent.AboutEvent aboutEvent) {
+                actionManager.getAction(AboutAction.class).showAboutDialog();
+            }
+        });
 
-        Application.getApplication().addAboutMenuItem();
-        Application.getApplication().addPreferencesMenuItem();
-        Application.getApplication().setEnabledAboutMenu(true);
-        Application.getApplication().setEnabledPreferencesMenu(true);
+        app.setPreferencesHandler(new PreferencesHandler() {
+            @Override
+            public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
+                actionManager.getAction(ConfigurePreferencesAction.class).showPreferencesDialog();
+            }
+        });
 
-        Application.getApplication().addApplicationListener(new MacEventsAdapter());
+        app.setQuitHandler(new QuitHandler() {
+            @Override
+            public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse
quitResponse) {
+                if(!actionManager.getAction(ExitAction.class).exit()) {
+                    quitResponse.cancelQuit();
+                }
+            }
+        });
     }
 
     public void setupMenus(JFrame frame) {
 
-        Set<Action> removeActions = new HashSet<Action>();
+        Set<Action> removeActions = new HashSet<>();
         removeActions.add(actionManager.getAction(ExitAction.class));
         removeActions.add(actionManager.getAction(AboutAction.class));
         removeActions.add(actionManager.getAction(ConfigurePreferencesAction.class));
@@ -95,28 +114,4 @@ public class OSXPlatformInitializer implements PlatformInitializer {
             }
         }
     }
-
-    class MacEventsAdapter extends ApplicationAdapter {
-
-        public void handleAbout(ApplicationEvent e) {
-            if (!e.isHandled()) {
-                actionManager.getAction(AboutAction.class).showAboutDialog();
-                e.setHandled(true);
-            }
-        }
-
-        public void handlePreferences(ApplicationEvent e) {
-            actionManager
-                    .getAction(ConfigurePreferencesAction.class)
-                    .showPreferencesDialog();
-            e.setHandled(true);
-        }
-
-        public void handleQuit(ApplicationEvent e) {
-            if (!e.isHandled()) {
-                e.setHandled(true);
-                actionManager.getAction(ExitAction.class).exit();
-            }
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/f8bb1277/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
index 6038c22..ccddb7e 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
@@ -43,9 +43,9 @@ public class ExitAction extends ProjectAction {
         exit();
     }
 
-    public void exit() {
+    public boolean exit() {
         if (!checkSaveOnClose()) {
-            return;
+            return false;
         }
 
         // stop logging before JVM shutdown to prevent hanging
@@ -55,6 +55,7 @@ public class ExitAction extends ProjectAction {
 
         // goodbye
         System.exit(0);
+        return true;
     }
 
     /**


Mime
View raw message