How to increase Vaadin notification / warning time?

How to increase Vaadin notification / warning time? I use the Vaadin Valo theme. Nothing from the Vaadin Notifications page helps.

+4
source share
1 answer

Default Delays

First of all, note that the five types Notification have different delays by default.

  • Notification.Type.HUMANIZED_MESSAGE
    It is displayed until the user moves the mouse pointer.
  • Notification.Type.TRAY_NOTIFICATION
    It is displayed up to 3 seconds after the user moves the mouse cursor.
  • Notification.Type.WARNING_MESSAGE
    It is displayed up to 1.5 seconds after the user moves the mouse cursor.
  • Notification.Type.ERROR_MESSAGE
    , . ( ​​ )
  • Notification.Type.ASSISTIVE_NOTIFICATION
    Safari Mac OS X Mountain Lion.

. , .

Notification : getDelayMsec setDelayMsec.

, , .

notification.setDelayMsec( 7 * 1_000 );

"" TimeUnit. long, int Vaadin.

notification.setDelayMsec( ( int ) TimeUnit.SECONDS.toMillis( 7 ) );

. ERROR_MESSAGE, ""; .

. , .

Vaadin 7.5.3. Vaadin. Vaadin .

/ Vaadin. ( JRebel, .)

five-button example screenshot

package com.example.vaadinnotifs;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.Page;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import java.util.concurrent.TimeUnit;

/**
 *  By Basil Bourque. 
 *
 * Source code provided under MIT License. 
 * http://opensource.org/licenses/MIT
 */
@Theme ( "mytheme" )
@Widgetset ( "com.example.vaadinnotifs.MyAppWidgetset" )
@SuppressWarnings ( "serial" )
public class MyUI extends UI
{

    @Override
    protected void init ( VaadinRequest vaadinRequest ) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin( true );
        layout.setSpacing( true );
        setContent( layout );

        layout.addComponent( this.makeButton( Notification.Type.HUMANIZED_MESSAGE ) );
        layout.addComponent( this.makeButton( Notification.Type.TRAY_NOTIFICATION ) );
        layout.addComponent( this.makeButton( Notification.Type.WARNING_MESSAGE ) );
        layout.addComponent( this.makeButton( Notification.Type.ERROR_MESSAGE ) );
        layout.addComponent( this.makeButton( Notification.Type.ASSISTIVE_NOTIFICATION ) );
    }

    @WebServlet ( urlPatterns = "/*" , name = "MyUIServlet" , asyncSupported = true )
    @VaadinServletConfiguration ( ui = MyUI.class , productionMode = false )
    public static class MyUIServlet extends VaadinServlet
    {
    }

    private Button makeButton ( Notification.Type typeArg ) {
        // Taking advantage of Java’s nifty Enum capability to generically produce each Button instance.
        Button b = new Button( typeArg.name() );
        b.setData( typeArg );  // "setData" and "getData" are accessors for a little hiding place for any object you wish to carry with a Vaadin widget.
        b.addClickListener( new Button.ClickListener()
        {
            @Override
            public void buttonClick ( ClickEvent event ) {
                Notification.Type t = ( Notification.Type ) event.getButton().getData();  // Cast from Object type used by the widget’s hiding place to the `Notification.Type` type we know we used.
                Notification notification = new Notification( "This is a Notification message." , t );
                //notification.setDelayMsec( ( int ) TimeUnit.SECONDS.toMillis( 7 ) );
                Integer delayMillis = notification.getDelayMsec();
                String description = "Notification.Type: " + t.name() + " has delay of " + delayMillis + " ms.";
                notification.setDescription( description );
                notification.show( Page.getCurrent() );
            }
        } );
        return b;
    }

}
+10

All Articles