From 05fd737e03c63fd9d69a4169c7130f64d8868f9b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Risto=20Yrj=C3=A4n=C3=A4?= Date: Thu, 28 Aug 2008 12:19:56 +0000 Subject: [PATCH] Fixed out of sync bug + refactoring svn changeset:5288/svn branch:trunk --- .../terminal/gwt/client/ui/IPopupView.java | 70 ++++++------------- src/com/itmill/toolkit/ui/PopupView.java | 21 ++++-- 2 files changed, 37 insertions(+), 54 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java index b169f23d4e..eded7610ad 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java @@ -16,13 +16,13 @@ import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; +import com.itmill.toolkit.terminal.gwt.client.Container; import com.itmill.toolkit.terminal.gwt.client.ICaption; import com.itmill.toolkit.terminal.gwt.client.ICaptionWrapper; -import com.itmill.toolkit.terminal.gwt.client.Container; import com.itmill.toolkit.terminal.gwt.client.Paintable; import com.itmill.toolkit.terminal.gwt.client.UIDL; -public class IPopupView extends HTML implements Paintable, Container { +public class IPopupView extends HTML implements Paintable { public static final String CLASSNAME = "i-popupview"; @@ -86,7 +86,6 @@ public class IPopupView extends HTML implements Paintable, Container { if (client.updateComponent(this, uidl, false)) { return; } - // These are for future server connections this.client = client; uidlId = uidl.getId(); @@ -100,16 +99,17 @@ public class IPopupView extends HTML implements Paintable, Container { setTitle(uidl.getStringAttribute("description")); } - // Render the popup if visible and show it. The component inside can - // change dynamically. + // Render the popup if visible and show it. if (hostPopupVisible) { UIDL popupUIDL = uidl.getChildUIDL(0); popup.updateFromUIDL(popupUIDL, client); showPopupOnTop(popup, hostReference); - } else { // The popup isn't visible so we should remove its child - popup.setWidget(null); + // The popup isn't visible so we should remove its child. The popup + // handles hiding so we don't need to hide it here. + } else { + popup.clear(); } }// updateFromUIDL @@ -166,35 +166,11 @@ public class IPopupView extends HTML implements Paintable, Container { windowBottom = windowTop + RootPanel.get().getOffsetHeight(); } - public boolean hasChildComponent(Widget component) { - return popup.equals(component); - } - - public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - if (newComponent == null || newComponent instanceof CustomPopup) { - popup.hide(); - - if (popup != null) { - client.unregisterPaintable(popup); - } - popup = (CustomPopup) newComponent; - - } else { - throw new IllegalArgumentException( - "PopupPanel only supports components of type CustomPopup"); - } - - } - - public void updateCaption(Paintable component, UIDL uidl) { - - } - public static native void nativeBlur(Element e) /*-{ - if(e.focus) { - e.blur(); - } - }-*/; + if(e.focus) { + e.blur(); + } + }-*/; private class CustomPopup extends IToolkitOverlay implements Container { @@ -245,26 +221,25 @@ public class IPopupView extends HTML implements Paintable, Container { ((HasFocus) popupComponentWidget).setFocus(false); } + // Notify children that have used the keyboard for (Iterator iterator = activeChildren.iterator(); iterator .hasNext();) { nativeBlur((Element) iterator.next()); } activeChildren.clear(); - + remove(popupComponentWidget); super.hide(); } - public void setWidget(Widget w) { - super.setWidget(w); + public boolean remove(Widget w) { - if (w == null) { + unregisterPaintables(); - unregisterPaintables(); + popupComponentPaintable = null; + popupComponentWidget = null; + captionWrapper = null; - popupComponentPaintable = null; - popupComponentWidget = null; - captionWrapper = null; - } + return super.remove(w); } public boolean hasChildComponent(Widget component) { @@ -277,7 +252,7 @@ public class IPopupView extends HTML implements Paintable, Container { public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - // System.out.println("CustomPopup replacechildcomponent"); + if (oldComponent != null) { client.unregisterPaintable((Paintable) oldComponent); } @@ -320,10 +295,11 @@ public class IPopupView extends HTML implements Paintable, Container { popup.setWidget(popupComponentWidget); popupComponentPaintable = newPopupComponent; - popupComponentPaintable.updateFromUIDL(uidl.getChildUIDL(0), - client); } + popupComponentPaintable + .updateFromUIDL(uidl.getChildUIDL(0), client); + } private void unregisterPaintables() { diff --git a/src/com/itmill/toolkit/ui/PopupView.java b/src/com/itmill/toolkit/ui/PopupView.java index c3ccb8f088..73f1e583ef 100644 --- a/src/com/itmill/toolkit/ui/PopupView.java +++ b/src/com/itmill/toolkit/ui/PopupView.java @@ -45,9 +45,9 @@ public class PopupView extends AbstractComponentContainer { * @param content * the PopupView.Content that contains the information for this */ - public PopupView(final PopupView.Content content) { + public PopupView(PopupView.Content content) { super(); - itsContent = content; + this.itsContent = content; popupVisible = false; componentList = new ArrayList(1); } @@ -61,8 +61,8 @@ public class PopupView extends AbstractComponentContainer { * PopupView * */ - public void setContent(PopupView.Content newContent) { - itsContent = newContent; + public void setContent(PopupView.Content content) { + this.itsContent = content; requestRepaint(); } @@ -87,7 +87,7 @@ public class PopupView extends AbstractComponentContainer { /* * Methods inherited from AbstractComponentContainer. These are unnecessary - * (but mandatory). They are not supported in this implementation. + * (but mandatory). Most of them are not supported in this implementation. */ /** @@ -200,12 +200,19 @@ public class PopupView extends AbstractComponentContainer { */ public void changeVariables(Object source, Map variables) { if (variables.containsKey("popupVisibility")) { + + // TODO we could use boolean allowPopup here to prevent popups from + // showing + popupVisible = ((Boolean) variables.get("popupVisibility")) .booleanValue(); if (popupVisible) { - componentList.add(itsContent.getPopupComponent()); - } else { + Component c = itsContent.getPopupComponent(); + componentList.add(c); + super.addComponent(c); + } else if (!componentList.isEmpty()) { + super.removeComponent((Component) componentList.get(0)); componentList.clear(); } requestRepaint(); -- 2.39.5