Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.fatalix.lighty.web.component; import com.vaadin.cdi.UIScoped; import com.vaadin.ui.Alignment; import com.vaadin.ui.CustomComponent; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; import de.fatalix.lighty.web.LightyTheme; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.enterprise.event.Observes; import javax.inject.Qualifier; import org.vaadin.jouni.animator.AnimatorProxy; import org.vaadin.jouni.animator.shared.AnimType; /** * * @author Fatalix */ @UIScoped public class LightyNotificationBar extends CustomComponent { private AnimatorProxy proxy = new AnimatorProxy(); private final VerticalLayout layout; public LightyNotificationBar() { addStyleName(LightyTheme.BACKGROUND); layout = new VerticalLayout(); layout.setWidth(100, Unit.PERCENTAGE); setCompositionRoot(layout); } public void showNotification(@Observes @ShowNotification final String message) { Label notificationLabel = new Label(""); notificationLabel.setSizeUndefined(); layout.removeAllComponents(); layout.addComponents(proxy, notificationLabel); layout.setComponentAlignment(notificationLabel, Alignment.MIDDLE_CENTER); addStyleName(LightyTheme.NOTIFICATION); proxy.animate(notificationLabel, AnimType.FADE_IN).setDuration(500); notificationLabel.setValue(message); } @Qualifier @Target(value = { ElementType.FIELD, ElementType.PARAMETER }) @Retention(RetentionPolicy.RUNTIME) public static @interface ShowNotification { } }