diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2008-03-06 09:26:14 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2008-03-06 09:26:14 +0000 |
commit | 6a9c8ca46b52ce9e298d110304a126a192872c49 (patch) | |
tree | 4c9d104cecbfe19a49a6a818e4a8f3e8e523128d | |
parent | b03100154f48b99b8f35cd8f40c2511cf0fa64b2 (diff) | |
download | vaadin-framework-6a9c8ca46b52ce9e298d110304a126a192872c49.tar.gz vaadin-framework-6a9c8ca46b52ce9e298d110304a126a192872c49.zip |
fixes #1202, #1465
svn changeset:3984/svn branch:trunk
3 files changed, 130 insertions, 35 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java index 85d0f74e41..bb280172c6 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java @@ -7,12 +7,15 @@ package com.itmill.toolkit.terminal.gwt.client.ui; import java.util.Iterator; import java.util.Vector; +import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.DeferredCommand; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Frame; import com.google.gwt.user.client.ui.PopupPanel; +import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.ScrollListener; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.Widget; @@ -96,6 +99,8 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { private boolean modal = false; + private Element modalityCurtain; + private Element headerText; public IWindow() { @@ -103,7 +108,6 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { final int order = windowOrder.size(); setWindowOrder(order); windowOrder.add(this); - setStyleName(CLASSNAME); constructDOM(); setPopupPosition(order * STACKING_OFFSET_PIXELS, order * STACKING_OFFSET_PIXELS); @@ -131,8 +135,12 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { } public void setWindowOrder(int order) { - DOM.setStyleAttribute(getElement(), "zIndex", "" - + (order + Z_INDEX_BASE)); + int zIndex = (order + Z_INDEX_BASE); + if (modal) { + zIndex += 1000; + DOM.setStyleAttribute(modalityCurtain, "zIndex", "" + zIndex); + } + DOM.setStyleAttribute(getElement(), "zIndex", "" + zIndex); } protected void constructDOM() { @@ -160,6 +168,7 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { final Element wrapper = DOM.createDiv(); DOM.setElementProperty(wrapper, "className", CLASSNAME + "-wrap"); + final Element wrapper2 = DOM.createDiv(); DOM.setElementProperty(wrapper2, "className", CLASSNAME + "-wrap2"); @@ -171,7 +180,9 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { DOM.appendChild(wrapper2, contents); DOM.appendChild(wrapper2, footer); DOM.appendChild(wrapper, wrapper2); - DOM.appendChild(getElement(), wrapper); + DOM.appendChild(super.getContainerElement(), wrapper); + DOM.setElementProperty(getElement(), "className", CLASSNAME); + setWidget(contentPanel); // set default size @@ -312,10 +323,53 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { } + public void show() { + if (modal) { + showModalityCurtain(); + } + super.show(); + } + + public void hide() { + if (modal) { + hideModalityCurtain(); + } + super.hide(); + } + private void setModal(boolean modality) { - // TODO create transparent curtain to create visual clue that window is - // modal modal = modality; + if (modal) { + modalityCurtain = DOM.createDiv(); + DOM.setElementProperty(modalityCurtain, "className", CLASSNAME + + "-modalitycurtain"); + if (isAttached()) { + showModalityCurtain(); + bringToFront(); + } else { + DeferredCommand.addCommand(new Command() { + public void execute() { + // modal window must on top of others + bringToFront(); + } + }); + } + } else { + if (modalityCurtain != null) { + if (isAttached()) { + hideModalityCurtain(); + } + modalityCurtain = null; + } + } + } + + private void showModalityCurtain() { + DOM.appendChild(RootPanel.getBodyElement(), modalityCurtain); + } + + private void hideModalityCurtain() { + DOM.removeChild(RootPanel.getBodyElement(), modalityCurtain); } public void setPopupPosition(int left, int top) { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Notification.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Notification.java index 447230367e..97aaa08480 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/Notification.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/Notification.java @@ -38,6 +38,8 @@ public class Notification extends ToolkitOverlay { private EventPreview eventPreview;
private String temporaryStyle;
+ private int x = -1;
+ private int y = -1;
public Notification() {
setStylePrimaryName(STYLENAME);
@@ -57,7 +59,7 @@ public class Notification extends ToolkitOverlay { }
public void startDelay() {
- DOM.removeEventPreview(eventPreview);
+ DOM.releaseCapture(getElement());
if (delayMsec > 0) {
delay = new Timer() {
public void run() {
@@ -102,39 +104,33 @@ public class Notification extends ToolkitOverlay { super.show();
setPosition(position);
- if (eventPreview == null) {
- eventPreview = new EventPreview() {
- int x = -1;
- int y = -1;
-
- public boolean onEventPreview(Event event) {
- switch (DOM.eventGetType(event)) {
- case Event.ONMOUSEMOVE:
- if (x < 0) {
- x = DOM.eventGetClientX(event);
- y = DOM.eventGetClientY(event);
- } else if (Math.abs(DOM.eventGetClientX(event) - x) > mouseMoveThreshold
- || Math.abs(DOM.eventGetClientY(event) - y) > mouseMoveThreshold) {
+ DOM.setCapture(getElement());
+
+ if (style.equals("error")) {
+ if (eventPreview == null) {
+ eventPreview = new EventPreview() {
+ public boolean onEventPreview(Event event) {
+ Element target = DOM.eventGetTarget(event);
+ if (DOM.isOrHasChild(getElement(), target)
+ && DOM.eventGetType(event) == Event.ONCLICK) {
startDelay();
+ DOM.removeEventPreview(this);
+ return true;
+ } else {
+ DOM.eventCancelBubble(event, true);
+ return false;
}
- break;
- case Event.KEYEVENTS:
- case Event.ONCLICK:
- case Event.ONDBLCLICK:
- case Event.ONSCROLL:
- default:
- startDelay();
}
- return true;
- }
- };
+ };
+ }
+
+ DOM.addEventPreview(eventPreview);
}
- DOM.addEventPreview(eventPreview);
}
public void hide() {
- DOM.removeEventPreview(eventPreview);
+ DOM.releaseCapture(getElement());
cancelDelay();
cancelFade();
if (temporaryStyle != null) {
@@ -145,6 +141,7 @@ public class Notification extends ToolkitOverlay { }
public void fade() {
+ DOM.releaseCapture(getElement());
cancelDelay();
fader = new Timer() {
int opacity = startOpacity;
@@ -223,9 +220,21 @@ public class Notification extends ToolkitOverlay { }
public void onBrowserEvent(Event event) {
- DOM.removeEventPreview(eventPreview);
- if (fader == null) {
- fade();
+ switch (DOM.eventGetType(event)) {
+ case Event.ONMOUSEMOVE:
+ if (x < 0) {
+ x = DOM.eventGetClientX(event);
+ y = DOM.eventGetClientY(event);
+ } else if (Math.abs(DOM.eventGetClientX(event) - x) > mouseMoveThreshold
+ || Math.abs(DOM.eventGetClientY(event) - y) > mouseMoveThreshold) {
+ startDelay();
+ }
+ break;
+ default:
+ if (fader == null) {
+ fade();
+ }
+ break;
}
}
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1465ModalNotification.java b/src/com/itmill/toolkit/tests/tickets/Ticket1465ModalNotification.java index a32a3ab63f..3e941643f3 100644 --- a/src/com/itmill/toolkit/tests/tickets/Ticket1465ModalNotification.java +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1465ModalNotification.java @@ -28,6 +28,38 @@ public class Ticket1465ModalNotification extends Application { }); modal.addComponent(b); + b = new Button("click to warning notification", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + modal.showNotification( + "Try clicking the button in main window!", + Window.Notification.TYPE_WARNING_MESSAGE); + } + }); + modal.addComponent(b); + + b = new Button("click to Humanized notification", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + modal.showNotification( + "Try clicking the button in main window!", + Window.Notification.TYPE_HUMANIZED_MESSAGE); + } + }); + modal.addComponent(b); + + b = new Button("click to test modality!", new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + mainWin.addComponent(new Label("clicked")); + + } + }); + + modal.addComponent(b); + mainWin.addWindow(modal); b = new Button("click to test modality!", new Button.ClickListener() { |