Package org.vaadin.alump.fancylayouts.gwt.client

Source Code of org.vaadin.alump.fancylayouts.gwt.client.GwtFancyTimedCssLayout

package org.vaadin.alump.fancylayouts.gwt.client;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
import com.google.gwt.user.client.ui.Widget;

/**
* Adds optinal automatic removal timer to FancyCssLayout
*/
public class GwtFancyTimedCssLayout extends GwtFancyCssLayout {

    protected int removeTimeMs = 0;

    public GwtFancyTimedCssLayout() {
        super();
    }

    /**
     * Set automatic fancyRemove handling timeout
     *
     * @param millisecs
     *            Timeout in millisecs, if 0 automatic fancyremoval isn't used.
     */
    public void setAutomaticRemoveTimeout(int millisecs) {
        if (millisecs < 0) {
            throw new IllegalArgumentException("invalid time");
        }
        removeTimeMs = millisecs;
    }

    @Override
    public void add(Widget widget, int index) {
        super.add(widget, index);

        if (removeTimeMs > 0) {
            final Widget removeWidget = widget;

            Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {
                @Override
                public boolean execute() {
                    GwtFancyTimedCssLayout.this.fancyRemove(removeWidget);
                    return false;
                }

            }, removeTimeMs);
        }
    }
}
TOP

Related Classes of org.vaadin.alump.fancylayouts.gwt.client.GwtFancyTimedCssLayout

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.