From: Matti Tahvonen Date: Mon, 20 Dec 2010 16:07:33 +0000 (+0000) Subject: bring to front now somewhat supports several updating order of several windows at... X-Git-Tag: 6.7.0.beta1~631 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=21b0129b45eebe3cac5a6676f6fcd8f6d70943e5;p=vaadin-framework.git bring to front now somewhat supports several updating order of several windows at one uidl update svn changeset:16587/svn branch:6.5 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java index 18c41d2e4a..68501ae082 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java @@ -5,11 +5,12 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; import java.util.Iterator; import java.util.Set; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; import com.google.gwt.event.dom.client.DomEvent.Type; @@ -65,6 +66,8 @@ public class VWindow extends VOverlay implements Container, private static ArrayList windowOrder = new ArrayList(); + private static boolean orderingDefered; + public static final String CLASSNAME = "v-window"; /** @@ -172,6 +175,8 @@ public class VWindow extends VOverlay implements Container, private boolean visibilityChangesDisabled; + private int bringToFrontSequence = -1; + public VWindow() { super(false, false, true); // no autohide, not modal, shadow // Different style of shadow for windows @@ -189,7 +194,7 @@ public class VWindow extends VOverlay implements Container, contentPanel.addBlurHandler(this); } - private void bringToFront() { + public void bringToFront() { int curIndex = windowOrder.indexOf(this); if (curIndex + 1 < windowOrder.size()) { windowOrder.remove(this); @@ -201,7 +206,7 @@ public class VWindow extends VOverlay implements Container, } /** - * Returns true if window is the topmost window + * Returns true if this window is the topmost VWindow * * @return */ @@ -209,7 +214,7 @@ public class VWindow extends VOverlay implements Container, return windowOrder.get(windowOrder.size() - 1).equals(this); } - public void setWindowOrder(int order) { + private void setWindowOrder(int order) { setZIndex(order + Z_INDEX); } @@ -506,19 +511,56 @@ public class VWindow extends VOverlay implements Container, * server side. */ contentPanel.focus(); - /* - * Modal windows bring them self the front with scheduleFinally(), - * deferred is used here so possible (additional) bringToFront - * brings the right modal window to top. If this window is not - * modal, scheduleFinally would be ok too. - */ - Scheduler.get().scheduleDeferred(new ScheduledCommand() { + bringToFrontSequence = uidl.getIntAttribute("bringToFront"); + deferOrdering(); + } + } + + /** + * Calling this method will defer ordering algorithm, to order windows based + * on servers bringToFront and modality instructions. Non changed windows + * will be left intact. + */ + private static void deferOrdering() { + if (!orderingDefered) { + orderingDefered = true; + Scheduler.get().scheduleFinally(new Command() { public void execute() { - bringToFront(); + doServerSideOrdering(); } }); } + } + private static void doServerSideOrdering() { + orderingDefered = false; + VWindow[] array = windowOrder.toArray(new VWindow[windowOrder.size()]); + Arrays.sort(array, new Comparator() { + public int compare(VWindow o1, VWindow o2) { + /* + * Order by modality, then by bringtofront sequence. + */ + + if (o1.vaadinModality && !o2.vaadinModality) { + return 1; + } else if (!o1.vaadinModality && o2.vaadinModality) { + return -1; + } else if (o1.bringToFrontSequence > o2.bringToFrontSequence) { + return 1; + } else if (o1.bringToFrontSequence < o2.bringToFrontSequence) { + return -1; + } else { + return 0; + } + } + }); + for (int i = 0; i < array.length; i++) { + VWindow w = array[i]; + if (w.bringToFrontSequence != -1 || w.vaadinModality) { + w.bringToFront(); + w.bringToFrontSequence = -1; + } + } } @Override @@ -704,15 +746,8 @@ public class VWindow extends VOverlay implements Container, + "-modalitycurtain"); if (isAttached()) { showModalityCurtain(); - bringToFront(); - } else { - Scheduler.get().scheduleFinally(new Command() { - public void execute() { - // vaadinModality window must on top of others - bringToFront(); - } - }); } + deferOrdering(); } else { if (modalityCurtain != null) { if (isAttached()) { diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index 911d00217a..b31255cb26 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -566,9 +566,9 @@ public class Window extends Panel implements URIHandler, ParameterHandler, target.addAttribute("fixedposition", true); } - if (bringToFront) { - target.addAttribute("bringToFront", true); - bringToFront = false; + if (bringToFront != null) { + target.addAttribute("bringToFront", bringToFront.intValue()); + bringToFront = null; } if (centerRequested) { @@ -1458,7 +1458,16 @@ public class Window extends Panel implements URIHandler, ParameterHandler, return true; } - private boolean bringToFront = false; + private Integer bringToFront = null; + + /* + * This sequesnce is used to keep the right order of windows if multiple + * windows are brought to front in a single changeset. Incremented and saved + * by childwindows. If sequence is not used, the order is quite random + * (depends on the order getting to dirty list. e.g. which window got + * variable changes). + */ + private int bringToFrontSequence = 0; /** * If there are currently several sub windows visible, calling this method @@ -1483,9 +1492,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler, throw new IllegalStateException( "There are modal windows currently visible, non-modal window cannot be brought to front."); } - w.bringToFront = false; } - bringToFront = true; + bringToFront = getParent().bringToFrontSequence++; requestRepaint(); }