package com.planetmayo.debrief.satc_rcp.views;


import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IActionBars;

import com.planetmayo.debrief.satc.model.generator.TrackGenerator;
import com.planetmayo.debrief.satc.support.TestSupport;

/**
 * This sample class demonstrates how to plug-in a new workbench view. The view
 * shows data obtained from the model. The sample creates a dummy model on the
 * fly, but a real implementation would connect to the model available either in
 * this or another plug-in (e.g. the workspace). The view is connected to the
 * model using a content provider.
 * <p>
 * The view uses a label provider to define how model objects should be
 * presented in the view. Each view can present the same model objects using
 * different labels and icons, if needed. Alternatively, a single label provider
 * can be shared between views in order to ensure that objects of the same type
 * are presented in the same way everywhere.
 * <p>
 */

public class TestHarnessView extends CoreView
{
	
	/**
	 * The ID of the view as specified by the extension.
	 */
	public static final String ID = "com.planetmayo.debrief.satc.views.SampleView";

	/*
	 * The content provider class is responsible for providing objects to the
	 * view. It can wrap existing objects in adapters or simply return objects
	 * as-is. These objects may be sensitive to the current input of the view, or
	 * ignore it and always show the same content (like Task List, for example).
	 */

	private Action _restartAction;
	private Action _stepAction;
	private Action _clearAction;
	private Action _playAction;
	private Action _populateTinyAction;
	private Action _populateShortAction;
	private Action _populateLongAction;
	private Action _liveAction;
	private Action _testOne;

	private TestSupport _testSupport;

	/**
	 * The constructor.
	 */
	public TestHarnessView()
	{
	}

	private void contributeToActionBars()
	{
		IActionBars bars = getViewSite().getActionBars();
		fillLocalToolBar(bars.getToolBarManager());
	}

	/**
	 * This is a callback that will allow us to create the viewer and initialize
	 * it.
	 */
	@Override
	public void createPartControl(Composite parent)
	{
		new Label(parent, SWT.None);

		 _testSupport = new TestSupport();
		
		makeActions();
		contributeToActionBars();

		// disable our controls, until we find a genny
		stopListeningTo(null);

		/**
		 * and listen out for track generators
		 * 
		 */
		setupMonitor();
	}


	private void fillLocalToolBar(IToolBarManager manager)
	{
		manager.add(_clearAction);
		manager.add(_restartAction);
		manager.add(_populateTinyAction);
		manager.add(_populateShortAction);
		manager.add(_populateLongAction);
		manager.add(_stepAction);
		manager.add(_playAction);
		manager.add(_liveAction);
		manager.add(_testOne);
	}


	private void makeActions()
	{
		_populateShortAction = new Action()
		{
			@Override
			public void run()
			{
				loadSampleData(false);
			}
		};
		_populateShortAction.setText("Populate Short");
		_populateShortAction.setToolTipText("Load some sample data");

		_populateTinyAction = new Action()
		{
			@Override
			public void run()
			{
				loadSampleData(false);
			}
		};
		_populateTinyAction.setText("Pop Tiny");
		_populateTinyAction.setToolTipText("Load a tiny amount of sample data");

		_populateLongAction = new Action()
		{
			@Override
			public void run()
			{
				loadTinyData();
			}
		};
		_populateLongAction.setText("Populate");
		_populateLongAction.setToolTipText("Load some sample data");

		_clearAction = new Action()
		{
			@Override
			public void run()
			{
				// clear the bounded states
				getGenerator().clear();
			}
		};
		_clearAction.setText("Clear");
		_clearAction.setToolTipText("Clear the track generator contributions");

		_testOne = new Action()
		{
			@Override
			public void run()
			{
				_testSupport.nextTest();
			}
		};
		_testOne.setText("1");
		
		_liveAction = new Action("Live", SWT.TOGGLE)
		{

			@Override
			public void run()
			{
				getGenerator().setLiveRunning(_liveAction.isChecked());
			}
		};
		_liveAction.setChecked(false);

		_restartAction = new Action()
		{
			@Override
			public void run()
			{
				// clear the bounded states
				getGenerator().restart();
			}
		};
		_restartAction.setText("Restart");
		_restartAction.setToolTipText("Reset the track generator");

		_stepAction = new Action()
		{
			@Override
			public void run()
			{
				getGenerator().step();
			}
		};
		_stepAction.setText("Step");
		_stepAction.setToolTipText("Process the next contribution");

		_playAction = new Action()
		{
			@Override
			public void run()
			{
				getGenerator().run();
			}
		};
		_playAction.setText("Play");
		_playAction.setToolTipText("Process all contributions");

	}

	protected void loadTinyData()
	{
		_testSupport.loadTinyData();
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	@Override
	public void setFocus()
	{
	}

	private void loadSampleData(boolean useLong)
	{
		_testSupport.loadSampleData(useLong);
	}

	@Override
	protected void stopListeningTo(TrackGenerator genny)
	{
		// ok, we can disable our buttons
		enableControls(false);
		
		_testSupport.setGenerator(genny);

	}

	@Override
	protected void startListeningTo(TrackGenerator genny)
	{
		enableControls(true);
		
		_testSupport.setGenerator(genny);

		// sort out the 'live' setting
		_liveAction.setChecked(genny.isLiveEnabled());
	}

	private void enableControls(boolean enabled)
	{
		_clearAction.setEnabled(enabled);
		_populateTinyAction.setEnabled(enabled);
		_populateShortAction.setEnabled(enabled);
		_populateLongAction.setEnabled(enabled);
		_restartAction.setEnabled(enabled);
		_stepAction.setEnabled(enabled);
		_playAction.setEnabled(enabled);
		_liveAction.setEnabled(enabled);

	}

}
@@ -3304,32 +3304,25 @@
 %09%09%09%09load
-SampleData(false
+TinyData(
 );%0A%09%09%09%7D%0A
@@ -3529,33 +3529,39 @@
 %09%09%7B%0A%09%09%09%09load
-Tiny
+Sample
 Data(
+true
 );%0A%09%09%09%7D%0A%09%09%7D;

load the correct datafiles