<commit_before>package org.mwc.cmap.core;

import interfaces.IEarthModelProvider;

import java.awt.Color;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.util.Iterator;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.commands.operations.ObjectUndoContext;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.mwc.cmap.gridharness.data.base60.Sexagesimal;
import org.mwc.cmap.gridharness.data.base60.SexagesimalFormat;
import org.mwc.cmap.gridharness.data.base60.SexagesimalSupport;
import org.osgi.framework.BundleContext;

import Debrief.GUI.Frames.Application;
import Debrief.ReaderWriter.Replay.ImportReplay;
import Debrief.Tools.Tote.Calculations.rangeCalc;
import Debrief.Wrappers.Track.TrackSegment;
import MWC.Algorithms.EarthModel;
import MWC.GUI.ToolParent;
import MWC.GUI.Chart.Painters.CoastPainter;
import MWC.GUI.Tools.Palette.CreateTOPO;
import MWC.GUI.Tools.Palette.CreateVPFLayers;
import MWC.GenericData.WorldLocation;
import MWC.Utilities.Errors.Trace;
import MWC.Utilities.ReaderWriter.XML.MWCXMLReader;
import MWC.Utilities.ReaderWriter.XML.Features.VPFDatabaseHandler;

/**
 * The main plugin class to be used in the desktop.
 */
public class CorePlugin extends AbstractUIPlugin implements ClipboardOwner
{

	/**
	 * how many UI operations to remember in the undo buffer
	 * 
	 */
	private static final int LENGTH_OF_UNDO_BUFFER = 10;

	public static final String PLUGIN_ID = "org.mwc.cmap.core";

	public static final String LAYER_MANAGER = "org.mwc.cmap.layer_manager.views.LayerManagerView";

	public static final String NARRATIVES = "org.mwc.cmap.narrative.views.NarrativeView";
	public static final String NARRATIVES2 = "com.borlander.ianmayo.nviewer.app.view";

	public static final String TOTE = "org.mwc.cmap.tote.views.ToteView";

	public static final String TIME_CONTROLLER = "org.mwc.cmap.TimeController.views.TimeController";
	public static final String TIME_BAR = "org.mwc.cmap.timebar.views.TimeBarView";

	public static final String XY_PLOT = "org.mwc.cmap.xyplot.views.XYPlotView";

	public static final String OVERVIEW_PLOT = "org.mwc.cmap.overview.views.ChartOverview";

	public static final String STACKED_DOTS = "org.mwc.debrief.track_shift.views.StackedDotsView";
	public static final String FREQ_RESIDUALS = "org.mwc.debrief.track_shift.views.FrequencyResidualsView";
	public static final String GRID_EDITOR = "com.pml.grid.editor";

	public static final String POLYGON_EDITOR = "org.mwc.cmap.core.editor_views.PolygonEditorView";
	public static final String LIVE_DATA_MONITOR = "org.mwc.cmap.LiveDataMonitor";
	private static final String EARTH_MODEL_PROVIDER = "org.mwc.cmap.core.EarthModelProvider";

	/**
	 * support for lat/long editor in grid editor
	 * 
	 */
	static final public String PREF_BASE60_FORMAT_NO_SECONDS = PLUGIN_ID
			+ ".base60-no-seconds";

	// The shared instance.
	private static CorePlugin plugin;

	// Resource bundle.
	private ResourceBundle resourceBundle;

	/**
	 * the Debrief tool-parent used to provide legacy access to properties
	 */
	private static ToolParent _toolParent;

	/**
	 * where we cache our images
	 */
	private ImageRegistry _imageRegistry;

	/**
	 * our CMAP-wide clipboard
	 */
	private Clipboard _myClipboard;

	/**
	 * the undo buffer we manage/support
	 */
	private static IOperationHistory _myHistory;

	/**
	 * and the context used to describe our undo list
	 */
	public final static IUndoContext CMAP_CONTEXT = new ObjectUndoContext("CMAP");

	/**
	 * fixed string used to indicate a string is in our location format
	 */
	public static final String LOCATION_STRING_IDENTIFIER = "LOC:";

	private IWorkbenchListener workbenchListener = new IWorkbenchListener()
	{

		@Override
		public boolean preShutdown(IWorkbench workbench, boolean forced)
		{
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
			for (IWorkbenchWindow window:windows) {
				IWorkbenchPage page = window.getActivePage();
				IViewReference[] viewReferences = page.getViewReferences();
				for (IViewReference viewReference:viewReferences) {
					String id = viewReference.getId();
					if (XY_PLOT.equals(id)) {
						page.hideView(viewReference);
					}
				}
			}
			return true;
		}

		@Override
		public void postShutdown(IWorkbench workbench)
		{
		}
	};

	/**
	 * The constructor.
	 */
	public CorePlugin()
	{
		super();
		plugin = this;

		// store our color property editor
		java.beans.PropertyEditorManager.registerEditor(Color.class,
				MWC.GUI.Properties.ColorPropertyEditor.class);
	}

	/**
	 * This method is called upon plug-in activation
	 */
	public void start(final BundleContext context) throws Exception
	{
		super.start(context);
		PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);

		// hack to initialise the TIFF importers. I believe we're having classpath
		// issues,
		// if we don't try to get an image reader right at the start of the app,
		// we can't get a TIFF loader later on.
		final Iterator<ImageReader> iter2 = ImageIO.getImageReadersBySuffix("tif");<commit_msg>insert comments<commit_after>package org.mwc.cmap.core;

import interfaces.IEarthModelProvider;

import java.awt.Color;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.util.Iterator;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.commands.operations.ObjectUndoContext;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.mwc.cmap.gridharness.data.base60.Sexagesimal;
import org.mwc.cmap.gridharness.data.base60.SexagesimalFormat;
import org.mwc.cmap.gridharness.data.base60.SexagesimalSupport;
import org.osgi.framework.BundleContext;

import Debrief.GUI.Frames.Application;
import Debrief.ReaderWriter.Replay.ImportReplay;
import Debrief.Tools.Tote.Calculations.rangeCalc;
import Debrief.Wrappers.Track.TrackSegment;
import MWC.Algorithms.EarthModel;
import MWC.GUI.ToolParent;
import MWC.GUI.Chart.Painters.CoastPainter;
import MWC.GUI.Tools.Palette.CreateTOPO;
import MWC.GUI.Tools.Palette.CreateVPFLayers;
import MWC.GenericData.WorldLocation;
import MWC.Utilities.Errors.Trace;
import MWC.Utilities.ReaderWriter.XML.MWCXMLReader;
import MWC.Utilities.ReaderWriter.XML.Features.VPFDatabaseHandler;

/**
 * The main plugin class to be used in the desktop.
 */
public class CorePlugin extends AbstractUIPlugin implements ClipboardOwner
{

	/**
	 * how many UI operations to remember in the undo buffer
	 * 
	 */
	private static final int LENGTH_OF_UNDO_BUFFER = 10;

	public static final String PLUGIN_ID = "org.mwc.cmap.core";

	public static final String LAYER_MANAGER = "org.mwc.cmap.layer_manager.views.LayerManagerView";

	public static final String NARRATIVES = "org.mwc.cmap.narrative.views.NarrativeView";
	public static final String NARRATIVES2 = "com.borlander.ianmayo.nviewer.app.view";

	public static final String TOTE = "org.mwc.cmap.tote.views.ToteView";

	public static final String TIME_CONTROLLER = "org.mwc.cmap.TimeController.views.TimeController";
	public static final String TIME_BAR = "org.mwc.cmap.timebar.views.TimeBarView";

	public static final String XY_PLOT = "org.mwc.cmap.xyplot.views.XYPlotView";

	public static final String OVERVIEW_PLOT = "org.mwc.cmap.overview.views.ChartOverview";

	public static final String STACKED_DOTS = "org.mwc.debrief.track_shift.views.StackedDotsView";
	public static final String FREQ_RESIDUALS = "org.mwc.debrief.track_shift.views.FrequencyResidualsView";
	public static final String GRID_EDITOR = "com.pml.grid.editor";

	public static final String POLYGON_EDITOR = "org.mwc.cmap.core.editor_views.PolygonEditorView";
	public static final String LIVE_DATA_MONITOR = "org.mwc.cmap.LiveDataMonitor";
	private static final String EARTH_MODEL_PROVIDER = "org.mwc.cmap.core.EarthModelProvider";

	/**
	 * support for lat/long editor in grid editor
	 * 
	 */
	static final public String PREF_BASE60_FORMAT_NO_SECONDS = PLUGIN_ID
			+ ".base60-no-seconds";

	// The shared instance.
	private static CorePlugin plugin;

	// Resource bundle.
	private ResourceBundle resourceBundle;

	/**
	 * the Debrief tool-parent used to provide legacy access to properties
	 */
	private static ToolParent _toolParent;

	/**
	 * where we cache our images
	 */
	private ImageRegistry _imageRegistry;

	/**
	 * our CMAP-wide clipboard
	 */
	private Clipboard _myClipboard;

	/**
	 * the undo buffer we manage/support
	 */
	private static IOperationHistory _myHistory;

	/**
	 * and the context used to describe our undo list
	 */
	public final static IUndoContext CMAP_CONTEXT = new ObjectUndoContext("CMAP");

	/**
	 * fixed string used to indicate a string is in our location format
	 */
	public static final String LOCATION_STRING_IDENTIFIER = "LOC:";

	/** special-case handler that ensures that XY Plot views are 
	 * closed when the app closes. XY-Plot views are "special" views
	 * because we don't wish them to persist between sessions.
	 */
	private  IWorkbenchListener workbenchListener = new IWorkbenchListener()
	{

		@Override
		public boolean preShutdown(IWorkbench workbench, boolean forced)
		{
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
			for (IWorkbenchWindow window:windows) {
				IWorkbenchPage page = window.getActivePage();
				IViewReference[] viewReferences = page.getViewReferences();
				for (IViewReference viewReference:viewReferences) {
					String id = viewReference.getId();
					if (XY_PLOT.equals(id)) {
						page.hideView(viewReference);
					}
				}
			}
			return true;
		}

		@Override
		public void postShutdown(IWorkbench workbench)
		{
		}
	};

	/**
	 * The constructor.
	 */
	public CorePlugin()
	{
		super();
		plugin = this;

		// store our color property editor
		java.beans.PropertyEditorManager.registerEditor(Color.class,
				MWC.GUI.Properties.ColorPropertyEditor.class);
	}

	/**
	 * This method is called upon plug-in activation
	 */
	public void start(final BundleContext context) throws Exception
	{
		super.start(context);
		
		// we have an ongoing problem with the window that RCP provides for a floated XY
		// Plot staying behind after the view itself has closed, and 
		// after the app has closed/re-opened.
		PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);

		// hack to initialise the TIFF importers. I believe we're having classpath
		// issues,
		// if we don't try to get an image reader right at the start of the app,
		// we can't get a TIFF loader later on.
		final Iterator<ImageReader> iter2 = ImageIO.getImageReadersBySuffix("tif");
{'fraction_non_alphanumeric': 0.09574617436473395, 'fraction_numerical': 0.0019654639898918995, 'mean_word_length': 4.9836203275934485, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6646123', 'n_tokens_mistral': 4693, 'n_tokens_neox': 4384, 'n_words': 986}