Den 24.06.2011 15:16, skrev Greg Brown:
My patch seems to work good, but I see that I have IntelliJ IDEA setup to
optimize imports.
What do you mean by "optimize imports"?
http://www.jetbrains.com/idea/webhelp/optimizing-imports.html
Basically, it removes redundant imports, but it also "compresses", if
you have more than X imports for the same package, it will remove all
those and import package.* instead.
I guess the patch should touch as little as possible when it doesn't have to do
with the actual functionality right?
Yes, minimizing the surface area of a patch is always good since it makes it
easier to see the non-trivial changes.
OK, I understand. Here is my patch, without the IDEA wizardry :) Should
I create an issue and refer to the usecase in this thread? PS: As you
know, I have no deep knowledge of Pivot yet, but this seemed very clear
cut. I might have missed something though... I basically added the
methods, made sure Window#open calls the listeners and if voted down,
respects the Veto and notifies listeners about the veto. I added default
implementations to the Adapter and let implementations use the Adapter
where appropriate.
-- Edvin
Index: wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java
(revision 1081752)
+++ wtk/src/org/apache/pivot/wtk/skin/ColorChooserButtonSkin.java
(revision )
@@ -110,7 +110,7 @@
}
};
- private WindowStateListener colorChooserPopupWindowStateListener = new
WindowStateListener() {
+ private WindowStateListener colorChooserPopupWindowStateListener = new
WindowStateListener.Adapter() {
@Override
public void windowOpened(Window window) {
Display display = window.getDisplay();
Index: wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
===================================================================
--- wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
(revision 1003722)
+++ wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
(revision )
@@ -54,7 +54,7 @@
* 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
Index: wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java (revision 995323)
+++ wtk/src/org/apache/pivot/wtk/skin/WindowSkin.java (revision )
@@ -177,4 +177,15 @@
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
+ }
+
+}
Index: wtk/src/org/apache/pivot/wtk/WindowStateListener.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/WindowStateListener.java (revision
983418)
+++ wtk/src/org/apache/pivot/wtk/WindowStateListener.java (revision )
@@ -36,10 +36,19 @@
}
@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 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 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
Index: wtk/src/org/apache/pivot/wtk/Window.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/Window.java (revision 1101054)
+++ wtk/src/org/apache/pivot/wtk/Window.java (revision )
@@ -369,6 +369,25 @@
}
@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);
@@ -620,23 +639,34 @@
}
if (!isOpen()) {
+ Vote vote = windowStateListeners.previewWindowOpen(this);
+
+ if (vote == Vote.APPROVE) {
- // Set the owner and add to the owner's owned window list
- this.owner = owner;
+ // Set the owner and add to the owner's owned window list
+ this.owner = owner;
- if (owner != null) {
- owner.ownedWindows.add(this);
- }
+ if (owner != null) {
+ owner.ownedWindows.add(this);
+ }
- // Add the window to the display
- display.add(this);
+ // Add the window to the display
+ display.add(this);
- // Notify listeners
- windowStateListeners.windowOpened(this);
+ // Notify listeners
+ windowStateListeners.windowOpened(this);
- moveToFront();
+ moveToFront();
+ } else {
+ if (vote == Vote.DENY) {
+ closing = false;
- }
+ }
+
+ windowStateListeners.windowOpenVetoed(this, vote);
- }
+ }
+ }
+ }
+
/**
* Returns this window's closed state.
*
Index:
wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
===================================================================
--- wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
(revision 1003722)
+++ wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraCalendarButtonSkin.java
(revision )
@@ -51,7 +51,7 @@
* 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();
Index: wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java (revision
1097524)
+++ wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java (revision )
@@ -113,7 +113,7 @@
}
};
- private WindowStateListener listViewPopupWindowStateListener = new
WindowStateListener() {
+ private WindowStateListener listViewPopupWindowStateListener = new
WindowStateListener.Adapter() {
@Override
public void windowOpened(Window window) {
Display display = window.getDisplay();
Index: wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java (revision
1097524)
+++ wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java (revision )
@@ -103,7 +103,7 @@
}
};
- private WindowStateListener calendarPopupWindowStateListener = new
WindowStateListener() {
+ private WindowStateListener calendarPopupWindowStateListener = new
WindowStateListener.Adapter() {
@Override
public void windowOpened(Window window) {
Display display = window.getDisplay();