<commit_before>/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 */
package org.mwc.cmap.naturalearth.ui;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.mwc.cmap.naturalearth.Activator;
import org.mwc.cmap.naturalearth.wrapper.NELayer;

import MWC.GUI.Layers;

/**
 * @author ian.mayo
 */
public class InsertNaturalEarth extends AbstractHandler
{

	public Layers getLayers()
	{
		// nope, better generate it
		final IWorkbench wb = PlatformUI.getWorkbench();
		final IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
		final IWorkbenchPage page = win.getActivePage();
		IEditorPart editor = page.getActiveEditor();
		return (Layers) editor.getAdapter(Layers.class);
	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException
	{
		// check if we have a data path, and check it exists
		if (!NELayer.hasGoodPath())
		{
			System.err.println("Don't have good path assigned");
		}
		else
		{
			Layers layers = getLayers();
			if (layers != null)
			{
				//
				NELayer ne = new NELayer(Activator.getDefault().getDefaultStyleSet());
				layers.addThisLayer(ne);
			}
		}

		return null;
	}

}<commit_msg>Overcome threading issues in creating Natural Earth<commit_after>/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 */
package org.mwc.cmap.naturalearth.ui;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.mwc.cmap.naturalearth.Activator;
import org.mwc.cmap.naturalearth.wrapper.NELayer;

import MWC.GUI.Layers;

/**
 * @author ian.mayo
 */
public class InsertNaturalEarth extends AbstractHandler
{

  public Layers getLayers()
  {
    final Layers[] answer = new Layers[1];
    Display.getDefault().syncExec(new Runnable()
    {
      @Override
      public void run()
      {
        // nope, better generate it
        final IWorkbench wb = PlatformUI.getWorkbench();
        final IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
        final IWorkbenchPage page = win.getActivePage();
        IEditorPart editor = page.getActiveEditor();
        answer[0] = (Layers) editor.getAdapter(Layers.class);
      }
    });
    return answer[0];
  }

  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException
  {
    // check if we have a data path, and check it exists
    if (!NELayer.hasGoodPath())
    {
      System.err.println("Don't have good path assigned");
    }
    else
    {
      Layers layers = getLayers();
      if (layers != null)
      {
        //
        NELayer ne = new NELayer(Activator.getDefault().getDefaultStyleSet());
        layers.addThisLayer(ne);
      }
    }
    return null;
  }
}
{'fraction_non_alphanumeric': 0.10233566096797496, 'fraction_numerical': 0.006501324343847821, 'mean_word_length': 3.4097664543524417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7663848', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1260, 'n_words': 339}