package com.itmill.toolkit.demo;
-import com.itmill.toolkit.event.Action;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.TextField;
* @see com.itmill.toolkit.ui.Label
*/
public class ModalWindow extends com.itmill.toolkit.Application implements
- Action.Handler, ClickListener {
+ ClickListener {
private Window test;
+ private Button reopen;
public void init() {
main.addComponent(f);
// Main window button
- Button b = new Button("Button on main window");
+ Button b = new Button("Test Button in main window");
b.addListener(this);
b.setTabIndex(2);
main.addComponent(b);
+ reopen = new Button("Open modal subwindow");
+ reopen.addListener(this);
+ reopen.setTabIndex(3);
+ main.addComponent(reopen);
+
+ }
+
+ public void buttonClick(ClickEvent event) {
+ if (event.getButton() == reopen) {
+ openSubWindow();
+ }
+ getMainWindow().addComponent(
+ new Label("Button click: " + event.getButton().getCaption()));
+ }
+
+ private void openSubWindow() {
// Modal window
test = new Window("Modal window");
- test.setStyle("modal");
- addWindow(test);
+ test.setModal(true);
+ getMainWindow().addWindow(test);
test.addComponent(new Label(
"You have to close this window before accessing others."));
// Textfield for modal window
- f = new TextField();
+ TextField f = new TextField();
f.setTabIndex(4);
test.addComponent(f);
f.focus();
// Modal window button
- b = new Button("Button on modal window");
- b.setTabIndex(3);
+ Button b = new Button("Test Button in modal window");
+ b.setTabIndex(5);
b.addListener(this);
test.addComponent(b);
-
- }
-
- public Action[] getActions(Object target, Object sender) {
- Action actionA = new Action("Action A for " + target.toString());
- Action actionB = new Action("Action B for " + target.toString());
- Action[] actions = new Action[] { actionA, actionB };
- return actions;
- }
-
- public void handleAction(Action action, Object sender, Object target) {
- test.addComponent(new Label(action.getCaption() + " clicked on "
- + target));
-
- }
-
- public void buttonClick(ClickEvent event) {
- test.addComponent(new Label("Clicked " + event));
-
}
}
/** Last known positiony read from UIDL or updated to application connection */
private int uidlPositionY = -1;
+ private boolean modal = false;
+
public IWindow() {
super();
int order = windowOrder.size();
return;
}
+ if (uidl.getBooleanAttribute("modal") != modal) {
+ setModal(!modal);
+ }
+
// Initialize the width from UIDL
if (uidl.hasVariable("width")) {
String width = uidl.getStringVariable("width");
}
+ private void setModal(boolean modality) {
+ // TODO create transparent curtain to create visual clue that window is
+ // modal
+ modal = modality;
+ }
+
public void setPopupPosition(int left, int top) {
super.setPopupPosition(left, top);
if (left != uidlPositionX && client != null) {
} else if (resizing) {
onResizeEvent(event);
return false;
+ } else if (modal) {
+ // return false when modal and outside window
+ Element target = DOM.eventGetTarget(event);
+ if (!DOM.isOrHasChild(getElement(), target)) {
+ return false;
+ }
}
- // TODO return false when modal
return true;
}
private LinkedList notifications;
+ private boolean modal;
+
/* ********************************************************************* */
/**
String theme = getTheme();
target.addAttribute("theme", theme == null ? "" : theme);
+ if (modal) {
+ target.addAttribute("modal", true);
+ }
+
// Marks the main window
if (getApplication() != null
&& this == getApplication().getMainWindow()) {
return styleName;
}
}
+
+ /**
+ * Sets sub-window modal, so that widgets behind it cannot be accessed.
+ *
+ * @param modality
+ * true if modality is to be turned on
+ */
+ public void setModal(boolean modality) {
+ modal = modality;
+ }
}