package org.xtest.runner.statusbar;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.HandlerEvent;
import org.xtest.runner.RunAllJob;
import org.xtest.runner.events.TestsCanceled;
import org.xtest.runner.events.TestsFinished;
import org.xtest.runner.events.TestsStarted;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;

/**
 * Handler for stop-test events
 * 
 * @author Michael Barry
 */
public class StopHandler extends AbstractHandler {
    private final EventBus bus;
    private boolean enabled = false;
    private final RunAllJob job;

    @Inject
    public StopHandler(RunAllJob job, EventBus bus) {
        this.bus = bus;
        bus.register(this);
        this.job = job;
    }

    @Subscribe
    public void disable(TestsCanceled canceled) {
        enabled = false;
        fireHandlerChanged(new HandlerEvent(this, true, false));
    }

    @Subscribe
    public void disable(TestsFinished finished) {
        enabled = false;
        fireHandlerChanged(new HandlerEvent(this, true, false));
    }

    @Override
    public void dispose() {
        super.dispose();
        bus.unregister(this);
    }

    @Subscribe
    public void enable(TestsStarted started) {
        enabled = true;
        fireHandlerChanged(new HandlerEvent(this, true, false));
    }

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        job.cancel();
        return null;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}

@@ -570,22 +570,98 @@
 op-test 
-events
+button events and events that influence whether that button is enabled or%0D%0A * not.
 %0D%0A * %0D%0A 
@@ -845,24 +845,255 @@
 Job job;%0D%0A%0D%0A
+    /**%0D%0A     * SHOULD ONLY BE CALLED BY GUICE%0D%0A     * %0D%0A     * @param job%0D%0A     *            %7B@link RunAllJob%7D instance provided by Guice%0D%0A     * @param bus%0D%0A     *            %7B@link EventBus%7D instance provided by Guice%0D%0A     */%0D%0A
     @Inject%0D
@@ -1228,32 +1228,173 @@
  job;%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * SHOULD ONLY BE CALLED BY %7B@link EventBus%7D%0D%0A     * %0D%0A     * @param canceled%0D%0A     *            Tests canceled event%0D%0A     */%0D%0A
     @Subscribe%0D%0A
@@ -1537,32 +1537,173 @@
 se));%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * SHOULD ONLY BE CALLED BY %7B@link EventBus%7D%0D%0A     * %0D%0A     * @param finished%0D%0A     *            Tests finished event%0D%0A     */%0D%0A
     @Subscribe%0D%0A
@@ -1960,24 +1960,163 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * SHOULD ONLY BE CALLED BY %7B@link EventBus%7D%0D%0A     * %0D%0A     * @param started%0D%0A     *            Tests started event%0D%0A     */%0D%0A
     @Subscri

Update comments on StopHandler