package com.planetmayo.debrief.satc.model.manager;

import java.util.ArrayList;
import java.util.List;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.planetmayo.debrief.satc.SATC_Activator;
import com.planetmayo.debrief.satc.model.VehicleType;
import com.planetmayo.debrief.satc.model.contributions.BaseContribution;
import com.planetmayo.debrief.satc.model.contributions.BearingMeasurementContribution;
import com.planetmayo.debrief.satc.model.contributions.CourseForecastContribution;
import com.planetmayo.debrief.satc.model.contributions.SpeedForecastContribution;
import com.planetmayo.debrief.satc.model.generator.ContributionsChangedListener;
import com.planetmayo.debrief.satc.model.generator.TrackGenerator;
import com.planetmayo.debrief.satc.services.VehicleTypesRepository;

public class MaintainContributions
{

	/**
	 * our track generator
	 * 
	 */
	TrackGenerator _genny;

	public MaintainContributions(MyView myView)
	{
		// sort out our generator
		_genny = new TrackGenerator();

		// ok, let the view start listening to the genny
		_genny.addContributionsListener(myView);

		// ok, config the view
		myView.setRemoveContributionListener(new ChangeListener()
		{
			@Override
			public void stateChanged(ChangeEvent arg0)
			{
				BaseContribution theCont = (BaseContribution) arg0.getSource();
				_genny.removeContribution(theCont);
			}
		});

		// populate the dropdowns in the view
		ArrayList<Object> items = getContributions();
		myView.populateContributionList(items);
		myView.populatePrecisionsList(getPrecisions());
		VehicleTypesRepository vehiclesRepository = SATC_Activator.getDefault()
				.getService(VehicleTypesRepository.class, true);
		myView.populateVehicleTypesList(vehiclesRepository.getAllTypes());

		// ok, now start listening to the view
		myView.setAddContributionListener(new ChangeListener()
		{
			@Override
			public void stateChanged(ChangeEvent arg0)
			{
				@SuppressWarnings("unused")
				String theCont = (String) arg0.getSource();

				// TODO: find out how to create a new contribution from this name
				CourseForecastContribution newCont = new CourseForecastContribution();

				// ok, create a new one of these
				_genny.addContribution(newCont);
			}
		});
		myView.setPrecisionChangeListener(new ChangeListener()
		{
			@Override
			public void stateChanged(ChangeEvent e)
			{
				// TODO support precision change
			}
		});
		myView.setVehicleChangeListener(new ChangeListener()
		{
			@Override
			public void stateChanged(ChangeEvent e)
			{
				// TODO support vehicle change
			}
		});

	}

	private List<String> getPrecisions()
	{
		List<String> precisions = new ArrayList<String>();
		precisions.add("Fine");
		precisions.add("Medium");
		precisions.add("Coarse");
		return precisions;
	}

	private ArrayList<Object> getContributions()
	{
		ArrayList<Object> res = new ArrayList<Object>();
		res.add(CourseForecastContribution.class);
		res.add(SpeedForecastContribution.class);
		res.add(BearingMeasurementContribution.class);

		return res;
	}

	public static interface MyView extends ContributionsChangedListener
	{

		/**
		 * show the list of available contributions
		 * 
		 * @param _items
		 */
		public void populateContributionList(ArrayList<Object> items);

		/**
		 * populate the list of vehicle types
		 * 
		 * @param vehicles
		 */
		public void populateVehicleTypesList(List<VehicleType> vehicles);

		/**
		 * populate the list of precisions
		 * 
		 * @param vehicles
		 */
		public void populatePrecisionsList(List<String> precisions);

		/**
		 * allow us to listen to user asking to remove a contribution
		 * 
		 * @param listener
		 */
		public void setRemoveContributionListener(ChangeListener listener);

		/**
		 * allow us to listen to user asking to remove a contribution
		 * 
		 * @param listener
		 */
		public void setAddContributionListener(ChangeListener listener);

		/**
		 * allow us to listen to user asking to remove a contribution
		 * 
		 * @param listener
		 */
		public void setVehicleChangeListener(ChangeListener listener);

		/**
		 * allow us to listen to user asking to remove a contribution
		 * 
		 * @param listener
		 */
		public void setPrecisionChangeListener(ChangeListener listener);

	}

	public TrackGenerator getGenerator()
	{
		return _genny;
	}
}

@@ -224,24 +224,76 @@
 _Activator;%0A
+import com.planetmayo.debrief.satc.model.Precision;%0A
 import com.p
@@ -2661,28 +2661,27 @@
 private 
-List%3CString%3E
+Precision%5B%5D
  getPrec
@@ -2698,160 +2698,33 @@
 %7B%0A%09%09
-List%3CString%3E precisions = new ArrayList%3CString%3E();%0A%09%09precisions.add(%22Fine%22);%0A%09%09precisions.add(%22Medium%22);%0A%09%09precisions.add(%22Coarse%22);%0A%09%09return precisions
+return Precision.values()
 ;%0A%09%7D
@@ -3469,20 +3469,19 @@
 ist(
-List%3CString%3E
+Precision%5B%5D
  pre

correctly define data