/*******************************************************************************
 * Copyright (c) 2012-2016 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.ide.ui.loaders.request;


import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;

import org.eclipse.che.ide.DelayedTask;
import org.eclipse.che.ide.rest.AsyncRequestLoader;
import org.vectomatic.dom.svg.ui.SVGImage;

/**
 * Loader that contains configurable message.
 * To obtain the instance of this loader you need to inject {@link LoaderFactory} and call one from two methods.
 * First one creates loader with default message. Second one allow to pass own loader initial message.
 * Loader will be showed to user if total operation time is more that 0.5 second.
 *
 * @author Vlad Zhukovskiy
 */
public class MessageLoader implements AsyncRequestLoader {

    public static final String DEF_MESSAGE = "Loading...";
    public static final int    SHOW_DELAY  = 500; //500ms

    private boolean showing = false;

    private final MessageLoaderResources resources;
    private final Label     label  = new Label();
    private final FlowPanel glass  = new FlowPanel();
    private final FlowPanel loader = new FlowPanel();

    //show loader if it works more than 0.5 second
    private final DelayedTask showLoader = new DelayedTask() {
        @Override
        public void onExecute() {
            RootPanel.get().add(glass);
            showing = true;
        }
    };

    @AssistedInject
    public MessageLoader(MessageLoaderResources resources) {
        this(DEF_MESSAGE, resources);
    }

    @AssistedInject
    public MessageLoader(@Assisted String message, MessageLoaderResources resources) {
        this.resources = resources;

        label.setText(message == null || message.isEmpty() ? DEF_MESSAGE : message);
        label.setStyleName(resources.Css().label());
        loader.setStyleName(resources.Css().loader());

        FlowPanel loaderSvg = new FlowPanel();
        loaderSvg.setStyleName(resources.Css().loaderSvg());
        loaderSvg.add(new SVGImage(resources.loader()));

        loader.add(loaderSvg);
        loader.add(label);

        glass.add(loader);
        glass.setStyleName(resources.Css().glass());
    }

    /** {@inheritDoc} */
    @Override
    public void show() {
        show(null);
    }

    /** {@inheritDoc} */
    @Override
    public void show(String message) {
        setMessage(message);

        if (!showing) {
            showLoader.delay(SHOW_DELAY);
        }
    }

    /** {@inheritDoc} */
    @Override
    public void hide() {
        if (showing) {
            glass.removeFromParent();
            showing = false;
            return;
        }

        showLoader.cancel();
    }

    /** {@inheritDoc} */
    @Override
    public void setMessage(String message) {
        if (message != null && !message.isEmpty()) {
            label.setText(message);
        }
    }
}

@@ -1433,16 +1433,19 @@
 MESSAGE 
+   
 = %22Loadi
@@ -1452,16 +1452,209 @@
 ng...%22;%0A
+    public static final String MESSAGE_DBG_ID = %22loader-message%22;%0A    public static final String GLASS_DBG_ID   = %22glass-panel%22;%0A    public static final String LOADER_DBG_ID  = %22loader-panel%22;%0A
     publ
@@ -1688,16 +1688,19 @@
 _DELAY  
+   
 = 500; /
@@ -1749,60 +1749,8 @@
 e;%0A%0A
-    private final MessageLoaderResources resources;%0A
     
@@ -2401,36 +2401,44 @@
     
-this.resources = resources;%0A
+label.ensureDebugId(MESSAGE_DBG_ID);
 %0A   
@@ -2790,24 +2790,69 @@
 oader()));%0A%0A
+        loader.ensureDebugId(LOADER_DBG_ID);%0A
         load
@@ -2894,24 +2894,67 @@
 dd(label);%0A%0A
+        glass.ensureDebugId(GLASS_DBG_ID);%0A
         glas

Add debug id for the testing purpose