You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/09/03 15:31:46 UTC

svn commit: r810933 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: Container.java MenuPopup.java Sheet.java Window.java skin/MenuItemSkin.java skin/terra/TerraSheetSkin.java

Author: gbrown
Date: Thu Sep  3 13:31:45 2009
New Revision: 810933

URL: http://svn.apache.org/viewvc?rev=810933&view=rev
Log:
Prevent a window from closing if any owned windows fail to close.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java?rev=810933&r1=810932&r2=810933&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java Thu Sep  3 13:31:45 2009
@@ -461,7 +461,7 @@
 
                     // Ensure that we don't get into an infinite loop
                     if (component == first) {
-                        throw new RuntimeException("Infinite loop in focus traversal policy for " + this);
+                        break;
                     }
                 }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java?rev=810933&r1=810932&r2=810933&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuPopup.java Thu Sep  3 13:31:45 2009
@@ -138,7 +138,7 @@
         if (!isClosed()) {
             Vote vote = menuPopupStateListeners.previewMenuPopupClose(this, immediate);
 
-            if (vote.isApproved()) {
+            if (vote == Vote.APPROVE) {
                 super.close();
 
                 if (isClosed()) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java?rev=810933&r1=810932&r2=810933&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java Thu Sep  3 13:31:45 2009
@@ -121,7 +121,7 @@
         if (!isClosed()) {
             Vote vote = sheetStateListeners.previewSheetClose(this, result);
 
-            if (vote.isApproved()) {
+            if (vote == Vote.APPROVE) {
                 super.close();
 
                 if (isClosed()) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java?rev=810933&r1=810932&r2=810933&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java Thu Sep  3 13:31:45 2009
@@ -581,9 +581,7 @@
     }
 
     /**
-     * Opens the window. Opening a window adds it to the display's component
-     * sequence. If the window is activatable, it will become the active
-     * window.
+     * Opens the window.
      *
      * @param display
      * The display on which the window will be opened.
@@ -608,26 +606,18 @@
             throw new IllegalArgumentException("Owner is opened on a different display.");
         }
 
-        if (!isOpen()
-            && !opening) {
+        if (!isOpen()) {
+            opening = true;
             Vote vote = windowStateListeners.previewWindowOpen(this, display);
 
             if (vote == Vote.APPROVE) {
-                opening = true;
-
-                // Add this as child of display
                 display.add(this);
-
-                // Notify listeners
+                opening = false;
                 windowStateListeners.windowOpened(this);
 
-                // Move this window to the front (which, unless this window is
-                // disabled or incapable of becoming active, will activate the
-                // window)
                 moveToFront();
-
+            } else if (vote == Vote.DENY) {
                 opening = false;
-            } else {
                 windowStateListeners.windowOpenVetoed(this, vote);
             }
         }
@@ -674,36 +664,37 @@
     }
 
     /**
-     * Closes the window. Closing a window closes all owned windows and
-     * removes the window from the display's component sequence. If the window
-     * was the active window, the active window will be cleared. If the window
-     * was the focus host, the focused component will be cleared.
+     * Closes the window and all of its owned windows. If any owned window fails to close,
+     * this window will also fail to close.
      */
     public void close() {
-        if (!isClosed()
-            && !closing) {
-            Vote vote = windowStateListeners.previewWindowClose(this);
-
-            if (vote.isApproved()) {
-                closing = true;
-
-                // Close all owned windows (create a copy of the owned window
-                // list so owned windows can remove themselves from the list
-                // without interrupting the iteration)
-                for (Window ownedWindow : new ArrayList<Window>(this.ownedWindows)) {
-                    ownedWindow.close();
-                }
-
-                // Detach from display
-                Display display = getDisplay();
-                display.remove(this);
+        if (!isClosed()) {
+            closing = true;
 
-                // Notify listeners
-                windowStateListeners.windowClosed(this, display);
+            // Close all owned windows (create a copy of the owned window
+            // list so owned windows can remove themselves from the list
+            // without interrupting the iteration)
+            boolean cancel = false;
+            for (Window ownedWindow : new ArrayList<Window>(this.ownedWindows)) {
+                ownedWindow.close();
+                cancel |= !(ownedWindow.isClosing() || ownedWindow.isClosed());
+            }
 
+            // Close this window only if all owned windows are closing or closed
+            if (cancel) {
                 closing = false;
             } else {
-                windowStateListeners.windowCloseVetoed(this, vote);
+                Vote vote = windowStateListeners.previewWindowClose(this);
+
+                if (vote == Vote.APPROVE) {
+                    Display display = getDisplay();
+                    display.remove(this);
+                    closing = false;
+                    windowStateListeners.windowClosed(this, display);
+                } else if (vote == Vote.DENY) {
+                    closing = false;
+                    windowStateListeners.windowCloseVetoed(this, vote);
+                }
             }
         }
     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java?rev=810933&r1=810932&r2=810933&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuItemSkin.java Thu Sep  3 13:31:45 2009
@@ -170,7 +170,7 @@
             menuItem.transferFocus(Direction.FORWARD);
             consumed = true;
         } else if (keyCode == Keyboard.KeyCode.LEFT) {
-            // If this is not a top-level menu, close the window
+            // If this is not a top-level menu, close this item's window
             Menu.Section parentSection = menuItem.getSection();
             Menu parentMenu = parentSection.getMenu();
             Menu.Item parentMenuItem = parentMenu.getItem();

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java?rev=810933&r1=810932&r2=810933&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java Thu Sep  3 13:31:45 2009
@@ -439,7 +439,8 @@
         // Don't start the transition if the sheet is being closed as a result
         // of the owner closing
         Window owner = sheet.getOwner();
-        if (!owner.isClosing()) {
+        if (!(owner.isClosing()
+            || owner.isClosed())) {
             TransitionListener transitionListener = new TransitionListener() {
                 @Override
                 public void transitionCompleted(Transition transition) {