aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/ModalWindow.java
blob: 8b27faa011102b62a3abba8e6dc9dc1560bd69cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.itmill.toolkit.demo;

import com.itmill.toolkit.event.Action;
import com.itmill.toolkit.ui.*;
import com.itmill.toolkit.ui.Button.ClickEvent;
import com.itmill.toolkit.ui.Button.ClickListener;

/**
 * Simple program that demonstrates "modal windows" that block all access other
 * windows.
 * 
 * @author IT Mill Ltd.
 * @since 4.0.1
 * @see com.itmill.toolkit.Application
 * @see com.itmill.toolkit.ui.Window
 * @see com.itmill.toolkit.ui.Label
 */
public class ModalWindow extends com.itmill.toolkit.Application implements
		Action.Handler, ClickListener {

	private Window test;

	public void init() {
	
		// Create main window
		Window main = new Window("ModalWindow demo");
		setMainWindow(main);
		main.addComponent(new Label("ModalWindow demo"));

		// Main window textfield
		TextField f = new TextField();
		f.setTabIndex(1);
		main.addComponent(f);

		// Main window button
		Button b = new Button("Button on main window");
		b.addListener(this);
		b.setTabIndex(2);
		main.addComponent(b);

		// Modal window
		test = new Window("Modal window");
		test.setStyle("modal");
		this.addWindow(test);
		test.addComponent(new Label(
				"You have to close this window before accessing others."));

		// Textfield for modal window
		f = new TextField();
		f.setTabIndex(4);
		test.addComponent(f);
		f.focus();

		// Modal window button
		b = new Button("Button on modal window");
		b.setTabIndex(3);
		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) {
		this.test.addComponent(new Label(action.getCaption() + " clicked on "
				+ target));

	}

	public void buttonClick(ClickEvent event) {
		this.test.addComponent(new Label("Clicked " + event));

	}
}