<commit_before>package com.vaadin.client;

import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;

/**
 * Class representing the loading indicator for Vaadin applications. The loading
 * indicator has four states: "triggered", "initial", "delay" and "wait". When
 * {@link #trigger()} is called the indicator moves to its "triggered" state and
 * then transitions from one state to the next when the timeouts specified using
 * the set*StateDelay methods occur.
 * 
 * @author <NAME>
 * @since 7.1
 */
public class VLoadingIndicator {

    private static final String PRIMARY_STYLE_NAME = "v-loading-indicator";

    private ApplicationConnection connection;

    private int initialStateDelay = 300;
    private int delayStateDelay = 1500;
    private int waitStateDelay = 5000;

    private Timer initialTimer = new Timer() {
        @Override
        public void run() {
            show();
        }
    };
    private Timer delayStateTimer = new Timer() {
        @Override
        public void run() {
            getElement().setClassName(PRIMARY_STYLE_NAME + "-delay");
        }
    };
    private Timer waitStateTimer = new Timer() {
        @Override
        public void run() {
            getElement().setClassName(PRIMARY_STYLE_NAME + "-wait");
        }
    };<commit_msg>Fixed issue with IE8 showing loading indicator when it should not (#7448)<commit_after>package com.vaadin.client;

import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;

/**
 * Class representing the loading indicator for Vaadin applications. The loading
 * indicator has four states: "triggered", "initial", "delay" and "wait". When
 * {@link #trigger()} is called the indicator moves to its "triggered" state and
 * then transitions from one state to the next when the timeouts specified using
 * the set*StateDelay methods occur.
 * 
 * @author <NAME>
 * @since 7.1
 */
public class VLoadingIndicator {

    private static final String PRIMARY_STYLE_NAME = "v-loading-indicator";

    private ApplicationConnection connection;

    private int initialStateDelay = 300;
    private int delayStateDelay = 1500;
    private int waitStateDelay = 5000;

    /**
     * Timer with method for checking if it has been cancelled. This class is a
     * workaround for a IE8 problem which causes a timer to be fired even if it
     * has been cancelled.
     * 
     * @author <NAME>
     * @since 7.1
     */
    private abstract static class LoadingIndicatorTimer extends Timer {
        private boolean cancelled = false;

        @Override
        public void cancel() {
            super.cancel();
            cancelled = true;
        }

        @Override
        public void schedule(int delayMillis) {
            super.schedule(delayMillis);
            cancelled = false;
        }

        @Override
        public void scheduleRepeating(int periodMillis) {
            super.scheduleRepeating(periodMillis);
            cancelled = false;
        }

        /**
         * Checks if this timer has been cancelled.
         * 
         * @return true if the timer has been cancelled, false otherwise
         */
        public boolean isCancelled() {
            return cancelled;
        }
    }

    private Timer initialTimer = new LoadingIndicatorTimer() {
        @Override
        public void run() {
            if (isCancelled()) {
                // IE8 does not properly cancel the timer in all cases.
                return;
            }
            show();
        }
    };
    private Timer delayStateTimer = new LoadingIndicatorTimer() {
        @Override
        public void run() {
            if (isCancelled()) {
                // IE8 does not properly cancel the timer in all cases.
                return;
            }
            getElement().setClassName(PRIMARY_STYLE_NAME + "-delay");
        }
    };
    private Timer waitStateTimer = new LoadingIndicatorTimer() {
        @Override
        public void run() {
            if (isCancelled()) {
                // IE8 does not properly cancel the timer in all cases.
                return;
            }
            getElement().setClassName(PRIMARY_STYLE_NAME + "-wait");
        }
    };
{'fraction_non_alphanumeric': 0.08955223880597014, 'fraction_numerical': 0.008242370238360436, 'mean_word_length': 2.284564740307242, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3220873', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1160, 'n_words': 384}