blob: f159c48b30dfb015f6e49477b97d258dea2ff4d0 (
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
80
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.vaadin.tests.book;
import com.vaadin.ui.Button;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseEvent;
/** Component contains a button that allows opening a window. */
public class WindowOpener extends CustomComponent implements
Window.CloseListener {
Window mainwindow; // Reference to main window
Window mywindow; // The window to be opened
Button openbutton; // Button for opening the window
Button closebutton; // A button in the window
Label explanation; // A descriptive text
public WindowOpener(String label, Window main) {
mainwindow = main;
/* The component consists of a button that opens the window. */
final VerticalLayout layout = new VerticalLayout();
openbutton = new Button("Open Window", this, "openButtonClick");
explanation = new Label("Explanation");
layout.addComponent(openbutton);
layout.addComponent(explanation);
setCompositionRoot(layout);
}
/** Handle the clicks for the two buttons. */
public void openButtonClick(Button.ClickEvent event) {
/* Create a new window. */
mywindow = new Window("My Dialog");
mywindow.setPositionX(200);
mywindow.setPositionY(100);
mywindow.getLayout().setSizeUndefined();
/* Add the window inside the main window. */
mainwindow.addWindow(mywindow);
/* Listen for close events for the window. */
mywindow.addListener(this);
/* Add components in the window. */
mywindow.addComponent(new Label("A text label in the window."));
closebutton = new Button("Close", this, "closeButtonClick");
mywindow.addComponent(closebutton);
/* Allow opening only one window at a time. */
openbutton.setEnabled(false);
explanation.setValue("Window opened");
}
/** Handle Close button click and close the window. */
public void closeButtonClick(Button.ClickEvent event) {
/* Windows are managed by the application object. */
mainwindow.removeWindow(mywindow);
/* Return to initial state. */
openbutton.setEnabled(true);
explanation.setValue("Closed with button");
}
/** In case the window is closed otherwise. */
public void windowClose(CloseEvent e) {
/* Return to initial state. */
openbutton.setEnabled(true);
explanation.setValue("Closed with window controls");
}
}
|