<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.debrief.core;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.internal.WorkbenchWindow;
import org.eclipse.ui.part.WorkbenchPart;
import org.eclipse.ui.views.contentoutline.ContentOutline;
import org.eclipse.ui.views.navigator.ResourceNavigator;
import org.eclipse.ui.views.properties.PropertySheet;

@SuppressWarnings({"deprecation", "restriction"})
public class Startup implements IStartup
{

  private IPartListener partListener = new IPartListener()
  {

    @Override
    public void partOpened(IWorkbenchPart part)
    {
      if (part instanceof ContentOutline || part instanceof PropertySheet
          || part instanceof ResourceNavigator)
      {
        changeIcon(part);
      }
    }

    @Override
    public void partDeactivated(IWorkbenchPart part)
    {
    }

    @Override
    public void partClosed(IWorkbenchPart part)
    {
    }

    @Override
    public void partBroughtToTop(IWorkbenchPart part)
    {
    }

    @Override
    public void partActivated(IWorkbenchPart part)
    {
    }
  };
  private static Image outlineImage, propertiesImage, navigatorImage;

  @Override
  public void earlyStartup()
  {
    removePerspective();
    removePreferencePages();
    updateMenuIcons();
    updateViewIcons();
    new ResetPerspective().resetPerspective();
    if (DebriefPlugin.getDefault().getCreateProject())
    {
      new CreateDebriefProject().createStartProject();
    }
  }

  private void updateMenuIcons()
  {

    Display.getDefault().asyncExec(new Runnable()
    {

      @Override
      public void run()
      {

        ActionAccessSupport accessSupport = new ActionAccessSupport();
        IAction saveall = accessSupport.getAction("saveAll");
        if (saveall != null)
        {
          saveall.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/save_all.png"));
        }
        IAction saveas = accessSupport.getAction("saveAs");
        if (saveas != null)
        {
          saveas.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/save_as.png"));
        }
        IAction save = accessSupport.getAction("save");
        if (save != null)
        {
          save.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/save.png"));
        }
        IAction redo = accessSupport.getAction("redo");
        if (redo != null)
        {
          redo.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/redo.png"));
        }
        IAction undo = accessSupport.getAction("undo");
        if (undo != null)
        {
          undo.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/undo.png"));
        }
      }
    });
  }

  private void updateViewIcons()
  {
    Display.getDefault().asyncExec(new Runnable()
    {

      @Override
      public void run()
      {
        IWorkbenchPage page =
            PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                .getActivePage();
        page.addPartListener(partListener);
        IViewPart view = page.findView(IPageLayout.ID_OUTLINE);
        if (view instanceof ContentOutline)
        {
          changeIcon(view);
        }
        view = page.findView(IPageLayout.ID_PROP_SHEET);
        if (view instanceof PropertySheet)
        {
          changeIcon(view);
        }
        view = page.findView(IPageLayout.ID_RES_NAV);
        if (view instanceof ResourceNavigator)
        {
          changeIcon(view);
        }
      }
    });
  }
  
  protected void changeIcon(IWorkbenchPart part)
  {
    try
    {
      Class<?> clazz = WorkbenchPart.class;
      Method method = clazz.getDeclaredMethod("setTitleImage", new Class[]
      {Image.class});
      method.setAccessible(true);
      Image image = null;
      if (part instanceof ContentOutline)
      {
        if (outlineImage == null)
        {
          ImageDescriptor descriptor =
              DebriefPlugin.getImageDescriptor("icons/16/outline.png");
          outlineImage =
              JFaceResources.getResources().createImageWithDefault(descriptor);
        }
        image = outlineImage;
      }
      if (part instanceof PropertySheet)<commit_msg>By default, remember the last 10 files<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.debrief.core;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.internal.IPreferenceConstants;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.WorkbenchWindow;
import org.eclipse.ui.part.WorkbenchPart;
import org.eclipse.ui.views.contentoutline.ContentOutline;
import org.eclipse.ui.views.navigator.ResourceNavigator;
import org.eclipse.ui.views.properties.PropertySheet;

@SuppressWarnings(
{"deprecation", "restriction"})
public class Startup implements IStartup
{

  private IPartListener partListener = new IPartListener()
  {

    @Override
    public void partOpened(IWorkbenchPart part)
    {
      if (part instanceof ContentOutline || part instanceof PropertySheet
          || part instanceof ResourceNavigator)
      {
        changeIcon(part);
      }
    }

    @Override
    public void partDeactivated(IWorkbenchPart part)
    {
    }

    @Override
    public void partClosed(IWorkbenchPart part)
    {
    }

    @Override
    public void partBroughtToTop(IWorkbenchPart part)
    {
    }

    @Override
    public void partActivated(IWorkbenchPart part)
    {
    }
  };
  private static Image outlineImage, propertiesImage, navigatorImage;

  @Override
  public void earlyStartup()
  {
    removePerspective();
    removePreferencePages();
    updateMenuIcons();
    updateViewIcons();
    initialisePrefs();
    new ResetPerspective().resetPerspective();
    if (DebriefPlugin.getDefault().getCreateProject())
    {
      new CreateDebriefProject().createStartProject();
    }
  }

  private void initialisePrefs()
  {
    WorkbenchPlugin.getDefault().getPreferenceStore().setValue(
        IPreferenceConstants.RECENT_FILES, 10);
  }

  private void updateMenuIcons()
  {

    Display.getDefault().asyncExec(new Runnable()
    {

      @Override
      public void run()
      {

        ActionAccessSupport accessSupport = new ActionAccessSupport();
        IAction saveall = accessSupport.getAction("saveAll");
        if (saveall != null)
        {
          saveall.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/save_all.png"));
        }
        IAction saveas = accessSupport.getAction("saveAs");
        if (saveas != null)
        {
          saveas.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/save_as.png"));
        }
        IAction save = accessSupport.getAction("save");
        if (save != null)
        {
          save.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/save.png"));
        }
        IAction redo = accessSupport.getAction("redo");
        if (redo != null)
        {
          redo.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/redo.png"));
        }
        IAction undo = accessSupport.getAction("undo");
        if (undo != null)
        {
          undo.setImageDescriptor(DebriefPlugin
              .getImageDescriptor("icons/16/undo.png"));
        }
      }
    });
  }

  private void updateViewIcons()
  {
    Display.getDefault().asyncExec(new Runnable()
    {

      @Override
      public void run()
      {
        IWorkbenchPage page =
            PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                .getActivePage();
        page.addPartListener(partListener);
        IViewPart view = page.findView(IPageLayout.ID_OUTLINE);
        if (view instanceof ContentOutline)
        {
          changeIcon(view);
        }
        view = page.findView(IPageLayout.ID_PROP_SHEET);
        if (view instanceof PropertySheet)
        {
          changeIcon(view);
        }
        view = page.findView(IPageLayout.ID_RES_NAV);
        if (view instanceof ResourceNavigator)
        {
          changeIcon(view);
        }
      }
    });
  }

  protected void changeIcon(IWorkbenchPart part)
  {
    try
    {
      Class<?> clazz = WorkbenchPart.class;
      Method method = clazz.getDeclaredMethod("setTitleImage", new Class[]
      {Image.class});
      method.setAccessible(true);
      Image image = null;
      if (part instanceof ContentOutline)
      {
        if (outlineImage == null)
        {
          ImageDescriptor descriptor =
              DebriefPlugin.getImageDescriptor("icons/16/outline.png");
          outlineImage =
              JFaceResources.getResources().createImageWithDefault(descriptor);
        }
        image = outlineImage;
      }
      if (part instanceof PropertySheet)
{'fraction_non_alphanumeric': 0.09867172675521822, 'fraction_numerical': 0.004485078488873555, 'mean_word_length': 2.786740692357936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5829057', 'n_tokens_mistral': 3359, 'n_tokens_neox': 3277, 'n_words': 647}