Vaadin

Join Vaadin Log In

An application-level window can have a number of floating child windows. They are managed by the client-side JavaScript runtime of Vaadin using HTML features. Vaadin allows opening and closing child windows, refreshing one window from another, resizing windows, and scrolling the window content. Child windows are typically used for Dialog Windows and Multiple Document Interface applications. Child windows are by default not modal; you can set them modal as described in Section 4.3.3, “Modal Windows”.

As with all user interface components, the appearance of a window and its contents is defined with themes.

User control of a child window is limited to moving, resizing, and closing the window. Maximizing or minimizing are not yet supported.

You can open a new window by creating a new Window object and adding it to the main window with addWindow() method of the Application class.

mywindow = new Window("My Window");
mainwindow.addWindow(mywindow);

You close the window in a similar fashion, by calling the removeWindow() of the Application class:

myapplication.removeWindow (mywindow);

The user can, by default, close a child window by clicking the close button in the upper-right corner of the window. You can disable the button by setting the window as read-only with setReadOnly(true). Notice that you could disable the button also by making it invisible in CSS with a "display: none" formatting. The problem with such a cosmetic disabling is that a malicious user might re-enable the button and close the window, which might cause problems and possibly be a security hole. Setting the window as read-only not only disables the close button on the client side, but also prevents processing the close event on the server side.

The following example demonstrates the use of a child window in an application. The example manages the window using a custom component that contains a button for opening and closing the window.

/** 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 contains 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);
        /* 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");
    }
}

The example implements a custom component that inherits the CustomComponent class. It consists of a Button that it uses to open a window and a Label to describe the state of the window. When the window is open, the button is disabled. When the window is closed, the button is enabled again.

You can use the above custom component in the application class with:

 public void init() { 
    Window main = new Window("The Main Window"); 
    setMainWindow(main);
    addComponent(new WindowOpener("Window Opener", main));
}

When added to an application, the screen will look as illustrated in the following screenshot:


Table of Contents

Preface
1. Introduction
1.1. Overview
1.2. Example Application Walkthrough
1.3. Support for the Eclipse IDE
1.4. Goals and Philosophy
1.5. Background
2. Getting Started with Vaadin
2.1. Installing Vaadin
2.2. Setting up the Development Environment
2.3. QuickStart with Eclipse
2.4. Your First Project with Vaadin
3. Architecture
3.1. Overview
3.2. Technological Background
3.3. Applications as Java Servlet Sessions
3.4. Client-Side Engine
3.5. Events and Listeners
4. Writing a Web Application
4.1. Overview
4.2. Managing the Main Window
4.3. Child Windows
4.4. Handling Events with Listeners
4.5. Referencing Resources
4.6. Shutting Down an Application
4.7. Handling Errors
4.8. Setting Up the Application Environment
5. User Interface Components
5.1. Overview
5.2. Interfaces and Abstractions
5.3. Common Component Features
5.4. Label
5.5. Link
5.6. TextField
5.7. RichTextArea
5.8. Date and Time Input
5.9. Button
5.10. CheckBox
5.11. Selecting Items
5.12. Table
5.13. Tree
5.14. MenuBar
5.15. Embedded
5.16. Upload
5.17. Form
5.18. ProgressIndicator
5.19. Slider
5.20. Component Composition with CustomComponent
6. Managing Layout
6.1. Overview
6.2. Window and Panel Root Layout
6.3. VerticalLayout and HorizontalLayout
6.4. GridLayout
6.5. FormLayout
6.6. Panel
6.7. SplitPanel
6.8. TabSheet
6.9. Accordion
6.10. Layout Formatting
6.11. Custom Layouts
7. Visual User Interface Design with Eclipse (experimental)
7.1. Overview
7.2. Creating a New CustomComponent
7.3. Using The Visual Editor
7.4. Structure of a Visually Editable Component
8. Themes
8.1. Overview
8.2. Introduction to Cascading Style Sheets
8.3. Creating and Using Themes
8.4. Creating a Theme in Eclipse
9. Binding Components to Data
9.1. Overview
9.2. Properties
9.3. Holding properties in Items
9.4. Collecting items in Containers
10. Developing Custom Components
10.1. Overview
10.2. Doing It the Simple Way in Eclipse
10.3. Google Web Toolkit Widgets
10.4. Integrating a GWT Widget
10.5. Defining a Widget Set
10.6. Server-Side Components
10.7. Using a Custom Component
10.8. GWT Widget Development
11. Advanced Web Application Topics
11.1. Special Characteristics of AJAX Applications
11.2. Application-Level Windows
11.3. Embedding Applications in Web Pages
11.4. Debug and Production Mode
11.5. Resources
11.6. Shortcut Keys
11.7. Printing
11.8. Portal Integration
11.9. Google App Engine Integration
11.10. Common Security Issues
11.11. URI Fragment and History Management with UriFragmentUtility
11.12. Capturing HTTP Requests
A. User Interface Definition Language (UIDL)
A.1. API for Painting Components
A.2. JSON Rendering
B. Songs of Vaadin
Index