/**
 * 
 */
package org.mwc.cmap.plotViewer.actions;

import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.mwc.cmap.core.CorePlugin;
import org.mwc.cmap.plotViewer.editors.CorePlotEditor;

import MWC.GUI.PlainChart;

/**
 * @author ian.mayo
 */
abstract public class CoreEditorAction implements IEditorActionDelegate
{

	protected CorePlotEditor _myEditor = null;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction,
	 *      org.eclipse.ui.IEditorPart)
	 */
	public void setActiveEditor(IAction action, IEditorPart targetEditor)
	{
		if(targetEditor == null)
			return;
		
		if (targetEditor instanceof CorePlotEditor)
		{
			_myEditor = (CorePlotEditor) targetEditor;
		}
		else
		{
			CorePlugin.logError(Status.ERROR,
					"Debrief action being triggered by wrong type of editor", null);
		}

	}
	
	protected CorePlotEditor getPlot()
	{
		return _myEditor;
	}
	
	protected PlainChart getChart()
	{
		return _myEditor.getChart();
	}
	
	protected void redrawChart()
	{
		getChart().getCanvas().updateMe();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction action)
	{
		run();
	}

	/** perform our operation
	 */
	abstract protected void run();

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
	 *      org.eclipse.jface.viewers.ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection)
	{
		// TODO Auto-generated method stub

	}

}

@@ -169,24 +169,49 @@
 ISelection;%0A
+import org.eclipse.ui.*;%0A
 import org.e
@@ -1050,16 +1050,428 @@
 );%0A%09%09%7D%0A%0A
+%09%7D%0A%09%0A%09private CorePlotEditor getEditor()%0A%09%7B%0A%09%09// do we know our editor?%0A%09%09if(_myEditor == null)%0A%09%09%7B%0A%09%09%09// nope, better generate it%0A%09%09%09IWorkbench wb = PlatformUI.getWorkbench();%0A%09%09%09IWorkbenchWindow win = wb.getActiveWorkbenchWindow();%0A%09%09%09IWorkbenchPage page = win.getActivePage();%0A%09%09%09IEditorPart editor = page.getActiveEditor();%0A%09%09%09setActiveEditor(null, editor);%0A%09%09%7D%0A%09%09%0A%09%09// ok, give it a go.%0A%09%09return _myEditor;%0A
 %09%7D%0A%09%0A%09pr
@@ -1511,33 +1511,35 @@
 %09%7B%0A%09%09return 
-_my
+get
 Editor
+()
 ;%0A%09%7D%0A%09%0A%09prot
@@ -1578,25 +1578,27 @@
 %09return 
-_my
+get
 Editor
+()
 .getChar

Handle when we don't know our editor