public class EventBus {

    private static final Log logger = LogFactory.getLog(EventBus.class);

    HashMap<ClientEventType<?>, List<? extends ClientEventHandler>> eventMap = new HashMap<ClientEventType<?>, List<? extends ClientEventHandler>>();

    @SuppressWarnings("unchecked")
    public <T extends ClientEventHandler> void addHandler(ClientEventType<T> eventType, T handler) {
        if (!this.eventMap.containsKey(eventType)) {
            this.eventMap.put(eventType, new ArrayList<T>());
        }
        ((ArrayList<T>) this.eventMap.get(eventType)).add(0, handler);
    }

    @SuppressWarnings("unchecked")
    public <T extends ClientEventHandler> void fireEvent(final ClientEvent<T> event) {
        if (!this.eventMap.containsKey(event.getHandlerType())) {
            return;
        }
        for (final ClientEventHandler handler : this.eventMap.get(event.getHandlerType())) {
            try {
                Runnable runner = new Runnable() {

                    @Override
                    public void run() { 
                        event.dispatch((T) handler);

                    }
                };

                Thread thread = new Thread(runner);
                thread.start();

                logger.trace("event dispatched to the handler " + handler.getId());
            } catch (Exception e) {
                logger.error("An event could not be dispatched to the handler " + handler.getId(), e);
            }
        }
    }
} public class FilesIdentifiedEvent implements ClientEvent<FilesIdentifiedEventHandler> {

    public static final ClientEventType<FilesIdentifiedEventHandler> TYPE = new ClientEventType<FilesIdentifiedEventHandler>();

    private final TreeSet<File> fileSet;

    public FilesIdentifiedEvent(TreeSet<File> fileSet) {
        this.fileSet = fileSet;
    }

    @Override
    public ClientEventType<FilesIdentifiedEventHandler> getHandlerType() {
        return TYPE;
    }

    @Override
    public void dispatch(FilesIdentifiedEventHandler handler) {
        handler.handle(this.fileSet);

    }

    public TreeSet<File> getFileSet() {
        return this.fileSet;
    }

} public class FilesScannedEvent implements ClientEvent<FilesScannedEventHandler> {

    public static final ClientEventType<FilesScannedEventHandler> TYPE = new ClientEventType<FilesScannedEventHandler>();

    private final int count;

    public FilesScannedEvent(int count) {
        super();
        this.count = count;
    }

    @Override
    public ClientEventType<FilesScannedEventHandler> getHandlerType() {
        return TYPE;
    }

    @Override
    public void dispatch(FilesScannedEventHandler handler) {
        handler.handle(this.count);

    }

    public int getCount() {
        return this.count;
    }

} public class OSFilesFoundEvent implements ClientEvent<OSFilesFoundEventHandler> {

    public static final ClientEventType<OSFilesFoundEventHandler> TYPE = new ClientEventType<OSFilesFoundEventHandler>();

    private final Set<String> fileSet;

    public OSFilesFoundEvent(Set<String> fileSet) {
        this.fileSet = fileSet;
    }

    @Override
    public ClientEventType<OSFilesFoundEventHandler> getHandlerType() {
        return TYPE;
    }

    @Override
    public void dispatch(OSFilesFoundEventHandler handler) {
        handler.handle(this.fileSet);
    }

    public Set<String> getFileSet() {
        return this.fileSet;
    }

} public class ScanCompleteEvent implements ClientEvent<ScanCompleteEventHandler> {

    public static final ClientEventType<ScanCompleteEventHandler> TYPE = new ClientEventType<ScanCompleteEventHandler>();

    
    ArrayList<Integer> levels;
    
    public ScanCompleteEvent(ArrayList<Integer> levels){
    	this.levels=levels;
    }
    @Override
    public ClientEventType<ScanCompleteEventHandler> getHandlerType() {
        return TYPE;
    }

    @Override
    public void dispatch(ScanCompleteEventHandler handler) {
        handler.handle(levels);
    }

} public interface FilesIdentifiedEventHandler extends ClientEventHandler {

    public void handle(TreeSet<File> fileSet);

} public interface FilesScannedEventHandler extends ClientEventHandler {

    public void handle(int count);

} public interface OSFilesFoundEventHandler extends ClientEventHandler {

    public void handle(Set<String> fileSet);

} public interface ScanCompleteEventHandler extends ClientEventHandler {

    public void handle(ArrayList<Integer> levels);
} public interface StartScanEventHandler extends ClientEventHandler {

    public void handle(File toScan);

}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.antelink.sourcesquare.event.base.EventBus;
import com.antelink.sourcesquare.event.events.FilesIdentifiedEvent;
import com.antelink.sourcesquare.event.events.FilesScannedEvent;
import com.antelink.sourcesquare.event.events.OSFilesFoundEvent;
import com.antelink.sourcesquare.event.events.ScanCompleteEvent;
import com.antelink.sourcesquare.event.handlers.FilesIdentifiedEventHandler;
import com.antelink.sourcesquare.event.handlers.FilesScannedEventHandler;
import com.antelink.sourcesquare.event.handlers.OSFilesFoundEventHandler;
import com.antelink.sourcesquare.event.handlers.ScanCompleteEventHandler;
import com.antelink.sourcesquare.event.handlers.StartScanEventHandler;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;
/**
 * Copyright (C) 2009-2012 Antelink SAS
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License Version 3 as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License Version 3
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License Version
 * 3 along with this program. If not, see http://www.gnu.org/licenses/agpl.html
 *
 * Additional permission under GNU AGPL version 3 section 7
 *
 * If you modify this Program, or any covered work, by linking or combining it with
 * Eclipse Java development tools (JDT) or Jetty (or a modified version of these
 * libraries), containing parts covered by the terms of Eclipse Public License 1.0,
 * the licensors of this Program grant you additional permission to convey the
 * resulting work. Corresponding Source for a non-source form of such a combination
 * shall include the source code for the parts of Eclipse Java development tools
 * (JDT) or Jetty used as well as that of the covered work.
 */
package com.antelink.sourcesquare.client.scan;




public class ScanStatusManager {

    private final static Log logger = LogFactory.getLog(ScanStatusManager.class);

    private final EventBus eventbus;

    public ScanStatusManager(EventBus eventbus) {
        super();
        this.eventbus = eventbus;

    }

    public void bind() {

        this.eventbus.addHandler(FilesIdentifiedEvent.TYPE, new FilesIdentifiedEventHandler() {