pivot-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ed...@apache.org
Subject svn commit: r1186166 - in /pivot/trunk: tests/src/org/apache/pivot/tests/issues/ wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/skin/
Date Wed, 19 Oct 2011 12:29:42 GMT
Author: edvin
Date: Wed Oct 19 12:29:42 2011
New Revision: 1186166

URL: http://svn.apache.org/viewvc?rev=1186166&view=rev
Log:
Resolve PIVOT-765: Reintroduce WindowStateListener#previewWindowOpen

Added:
    pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot765.java
Modified:
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/WindowStateListener.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java

Added: pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot765.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot765.java?rev=1186166&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot765.java (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/issues/Pivot765.java Wed Oct 19 12:29:42
2011
@@ -0,0 +1,63 @@
+package org.apache.pivot.tests.issues;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.util.Vote;
+import org.apache.pivot.wtk.*;
+
+/**
+ * This test will check that the previewWindowOpen method is called
+ * before the ListPopup of the MenuButton is opened. This is crucial because
+ * one need to populate the Menu before the Window opens, so that correct sizing
+ * and layout can be performed.
+ */
+public class Pivot765 implements Application {
+    private boolean menuPopulated = false;
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main( new String[] { Pivot765.class.getName() });
+    }
+    
+    public void startup(final Display display, Map<String, String> properties) throws
Exception {
+        final MenuButton button = new MenuButton();
+        button.setButtonData("Populate menu and open!");
+        Window window = new Window(button);
+
+        button.getListPopup().getWindowStateListeners().add(new WindowStateListener.Adapter()
{
+            public Vote previewWindowOpen(Window window) {
+                Menu menu = new Menu();
+                Menu.Section section = new Menu.Section();
+                menu.getSections().add(section);
+                section.add(new Menu.Item("A dynamically added menu item"));
+                button.setMenu(menu);
+
+                menuPopulated = true;
+                return Vote.APPROVE;
+            }
+
+            public void windowOpened(Window window) {
+                if (!menuPopulated)
+                    Alert.alert("Window was opened before the menu was populated." +
+                            "Either previewWindowOpen threw an exception, or it wasn't called
before the Window was opened.", window);
+            }
+
+            public void windowClosed(Window window, Display display, Window owner) {
+                // Remove menu for subsequent open attempt
+                button.setMenu(null);
+                menuPopulated = false;
+            }
+        });
+
+
+        window.open(display);
+    }
+
+    public boolean shutdown(boolean optional) throws Exception {
+        return false;
+    }
+
+    public void suspend() throws Exception {
+    }
+
+    public void resume() throws Exception {
+    }
+}

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
(original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
Wed Oct 19 12:29:42 2011
@@ -51,7 +51,7 @@ import org.apache.pivot.wtk.skin.Calenda
  * TODO Calendar pass-through styles.
  */
 public class TerraCalendarButtonSkin extends CalendarButtonSkin {
-    private WindowStateListener calendarPopupStateListener = new WindowStateListener() {
+    private WindowStateListener calendarPopupStateListener = new WindowStateListener.Adapter()
{
         @Override
         public void windowOpened(Window window) {
             CalendarButton calendarButton = (CalendarButton)getComponent();

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java Wed
Oct 19 12:29:42 2011
@@ -54,7 +54,7 @@ import org.apache.pivot.wtk.skin.ListBut
  * Terra list button skin.
  */
 public class TerraListButtonSkin extends ListButtonSkin {
-    private WindowStateListener listViewPopupStateListener = new WindowStateListener() {
+    private WindowStateListener listViewPopupStateListener = new WindowStateListener.Adapter()
{
         @Override
         public void windowOpened(Window window) {
             // Adjust for list size

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Window.java Wed Oct 19 12:29:42 2011
@@ -369,6 +369,25 @@ public class Window extends Container {
         }
 
         @Override
+        public Vote previewWindowOpen(Window window) {
+            Vote vote = Vote.APPROVE;
+
+            for (WindowStateListener listener : this) {
+                vote = vote.tally(listener.previewWindowOpen(window));
+            }
+
+            return vote;
+        }
+
+
+        @Override
+        public void windowOpenVetoed(Window window, Vote reason) {
+            for (WindowStateListener listener : this) {
+                listener.windowOpenVetoed(window, reason);
+            }
+        }
+
+        @Override
         public void windowClosed(Window window, Display display, Window owner) {
             for (WindowStateListener listener : this) {
                 listener.windowClosed(window, display, owner);
@@ -432,6 +451,7 @@ public class Window extends Container {
     private Component content = null;
     private Component focusDescendant = null;
 
+    private boolean opening = false;
     private boolean closing = false;
 
     private Point restoreLocation = null;
@@ -563,6 +583,16 @@ public class Window extends Container {
     }
 
     /**
+     * Returns this window's opening state.
+     *
+     * @return
+     * <tt>true</tt> if the window is opening; <tt>false</tt>, otherwise.
+     */
+    public boolean isOpening() {
+        return opening;
+    }
+
+    /**
      * Opens the window.
      *
      * @param display
@@ -620,20 +650,33 @@ public class Window extends Container {
         }
 
         if (!isOpen()) {
-            // Set the owner and add to the owner's owned window list
-            this.owner = owner;
+            opening = true;
+            Vote vote = windowStateListeners.previewWindowOpen(this);
 
-            if (owner != null) {
-                owner.ownedWindows.add(this);
-            }
+            if (vote == Vote.APPROVE) {
+                // Set the owner and add to the owner's owned window list
+                this.owner = owner;
 
-            // Add the window to the display
-            display.add(this);
+                if (owner != null) {
+                    owner.ownedWindows.add(this);
+                }
 
-            // Notify listeners
-            windowStateListeners.windowOpened(this);
+                // Add the window to the display
+                display.add(this);
+
+                // Notify listeners
+                opening = false;
+                windowStateListeners.windowOpened(this);
+
+                moveToFront();
+            } else {
+                if (vote == Vote.DENY) {
+                    opening = false;
+                }
+
+                windowStateListeners.windowOpenVetoed(this, vote);
+            }
 
-            moveToFront();
         }
     }
 

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/WindowStateListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/WindowStateListener.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/WindowStateListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/WindowStateListener.java Wed Oct 19 12:29:42
2011
@@ -36,10 +36,19 @@ public interface WindowStateListener {
         }
 
         @Override
+        public Vote previewWindowOpen(Window window) {
+            return Vote.APPROVE;
+        }
+
+        @Override
         public void windowCloseVetoed(Window window, Vote reason) {
         }
 
         @Override
+        public void windowOpenVetoed(Window window, Vote reason) {
+        }
+
+        @Override
         public void windowClosed(Window window, Display display, Window owner) {
         }
     }
@@ -59,6 +68,13 @@ public interface WindowStateListener {
     public Vote previewWindowClose(Window window);
 
     /**
+     * Called to preview a window open event.
+     *
+     * @param window
+     */
+    public Vote previewWindowOpen(Window window);
+
+    /**
      * Called when a window close event has been vetoed.
      *
      * @param window
@@ -67,6 +83,14 @@ public interface WindowStateListener {
     public void windowCloseVetoed(Window window, Vote reason);
 
     /**
+     * Called when a window open event has been vetoed.
+     *
+     * @param window
+     * @param reason
+     */
+    public void windowOpenVetoed(Window window, Vote reason);
+
+    /**
      * Called when a window has closed.
      *
      * @param window

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java Wed Oct 19 12:29:42
2011
@@ -103,7 +103,7 @@ public abstract class CalendarButtonSkin
         }
     };
 
-    private WindowStateListener calendarPopupWindowStateListener = new WindowStateListener()
{
+    private WindowStateListener calendarPopupWindowStateListener = new WindowStateListener.Adapter()
{
         @Override
         public void windowOpened(Window window) {
             Display display = window.getDisplay();

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java Wed Oct 19 12:29:42
2011
@@ -110,7 +110,7 @@ public abstract class ColorChooserButton
         }
     };
 
-    private WindowStateListener colorChooserPopupWindowStateListener = new WindowStateListener()
{
+    private WindowStateListener colorChooserPopupWindowStateListener = new WindowStateListener.Adapter()
{
         @Override
         public void windowOpened(Window window) {
             Display display = window.getDisplay();

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java Wed Oct 19 12:29:42
2011
@@ -113,7 +113,7 @@ public abstract class ListButtonSkin ext
         }
     };
 
-    private WindowStateListener listViewPopupWindowStateListener = new WindowStateListener()
{
+    private WindowStateListener listViewPopupWindowStateListener = new WindowStateListener.Adapter()
{
         @Override
         public void windowOpened(Window window) {
             Display display = window.getDisplay();

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java?rev=1186166&r1=1186165&r2=1186166&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java Wed Oct 19 12:29:42 2011
@@ -177,4 +177,15 @@ public class WindowSkin extends Containe
     public void windowClosed(Window window, Display display, Window owner) {
         // No-op
     }
+
+    @Override
+    public Vote previewWindowOpen(Window window) {
+        return Vote.APPROVE;
+    }
+
+    @Override
+    public void windowOpenVetoed(Window window, Vote reason) {
+        // No-op
+    }
+
 }



Mime
View raw message