package am.extension.multiUserFeedback.selection;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.SwingUtilities;
import javax.swing.event.EventListenerList;

import am.app.mappingEngine.Mapping;
import am.app.mappingEngine.AbstractMatcher.alignType;
import am.extension.multiUserFeedback.experiment.MUExperiment;
import am.extension.userfeedback.experiments.UFLExperiment;
import am.extension.userfeedback.selection.CandidateSelection;
import am.extension.userfeedback.ui.UFLControlGUI;

public abstract class MUCandidateSelection<T extends MUExperiment> extends CandidateSelection<T> {
	EventListenerList listeners;  // list of listeners for this class
	public Mapping selectedMapping;
	
	public MUCandidateSelection() {
		listeners = new EventListenerList();
	}
	
	public abstract void rank( T exp, String id );
	
	public abstract List<Mapping> getRankedMappings(alignType typeOfRanking, String id);
	public abstract List<Mapping> getRankedMappings(String id);
	
	public abstract Mapping getCandidateMapping(String id);
	
	@Override
	public Mapping getCandidateMapping() {
		throw new RuntimeException("Use getCandidateMapping(String id)");
	}
	
	@Override
	public List<Mapping> getRankedMappings() {
		throw new RuntimeException("Use getRankedMappings(String id)");
	}
	
	@Override
	public List<Mapping> getRankedMappings(alignType typeOfRanking) {
		throw new RuntimeException("Use getRankedMappings(alignType typeOfRanking, String id)");
	}
	
	public void addActionListener( ActionListener l ) {
		listeners.add(ActionListener.class, l);
	}
	
	/**
	 * This method fires an action event.
	 * @param e Represents the action that was performed.
	 */
	protected void fireEvent( ActionEvent e ) {
		final ActionEvent evt = e;
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				ActionListener[] actionListeners = listeners.getListeners(ActionListener.class);
				
				for( int i = actionListeners.length-1; i >= 0; i-- ) {
					actionListeners[i].actionPerformed(evt);
				}
			}
		});
		
	}
	
	protected void done() {
		ActionEvent e = new ActionEvent(this, 0, UFLControlGUI.ActionCommands.CANDIDATE_SELECTION_DONE.name() );
		fireEvent(e);
	}
}

@@ -253,133 +253,70 @@
 ine.
-Mapping;%0Aimport am.app.mappingEngine.AbstractMatcher.alignType;%0Aimport am.extension.multiUserFeedback.experiment.MUExperiment
+AbstractMatcher.alignType;%0Aimport am.app.mappingEngine.Mapping
 ;%0Aim
@@ -325,37 +325,42 @@
 rt am.extension.
-userf
+multiUserF
 eedback.experime
@@ -365,13 +365,11 @@
 ment
-s.UFL
+.MU
 Expe
@@ -815,24 +815,128 @@
 ing id );%0A%09%0A
+%09@Override%0A%09public void rank( T exp ) %7B%0A%09%09throw new RuntimeException(%22Use rank(experiment, id).%22);%0A%09%7D%0A%09%0A
 %09public abst

Work in progress.