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";
if (client.updateComponent(this, uidl, false)) {
return;
}
-
// These are for future server connections
this.client = client;
uidlId = uidl.getId();
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
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 {
((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) {
public void replaceChildComponent(Widget oldComponent,
Widget newComponent) {
- // System.out.println("CustomPopup replacechildcomponent");
+
if (oldComponent != null) {
client.unregisterPaintable((Paintable) oldComponent);
}
popup.setWidget(popupComponentWidget);
popupComponentPaintable = newPopupComponent;
- popupComponentPaintable.updateFromUIDL(uidl.getChildUIDL(0),
- client);
}
+ popupComponentPaintable
+ .updateFromUIDL(uidl.getChildUIDL(0), client);
+
}
private void unregisterPaintables() {
* @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);
}
* PopupView
*
*/
- public void setContent(PopupView.Content newContent) {
- itsContent = newContent;
+ public void setContent(PopupView.Content content) {
+ this.itsContent = content;
requestRepaint();
}
/*
* 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.
*/
/**
*/
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();