<commit_before>/*******************************************************************************
 * Copyright (c) 2006-2008 VecTrace (<NAME>) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     VecTrace (Zingo Andersen) - implementation
 *     Software Balm Consulting Inc (<NAME> <peter_hge at softwarebalm dot com>) - some updates
 *     StefanC                   - some updates, code cleanup
 *     <NAME>          - logError
 *******************************************************************************/
package com.vectrace.MercurialEclipse.team;


import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import com.vectrace.MercurialEclipse.MercurialEclipsePlugin;

public class ActionChangeLog implements IWorkbenchWindowActionDelegate {

  //    private IWorkbenchPart targetPart;
    private IStructuredSelection selection;
    
  public ActionChangeLog() {
    super();
  }

  /**
   * We can use this method to dispose of any system
   * resources we previously allocated.
   * @see IWorkbenchWindowActionDelegate#dispose
   */
  public void dispose() {

  }


  /**
   * We will cache window object in order to
   * be able to provide parent shell for the message dialog.
   * @see IWorkbenchWindowActionDelegate#init
   */
  public void init(IWorkbenchWindow window) {
  }

  /**
   * The action has been activated. The argument of the
   * method represents the 'real' action sitting
   * in the workbench UI.
   * @see IWorkbenchWindowActionDelegate#run
   */
  

  public void run(IAction action) 
  {
    final IWorkbenchPage activePage = MercurialEclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final Shell shell = Display.getDefault().getActiveShell();
    try 
    {
      new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress() 
        {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException 
          {
            final IResource resource = (IResource) selection.getFirstElement();
            Runnable r = new Runnable() 
              {
              public void run() 
                {
                  TeamUI.showHistoryFor(activePage, resource, null);
                }
              };
              Display.getDefault().asyncExec(r);
          }
        });
    } 
    catch (InvocationTargetException e) 
    {
    	MercurialEclipsePlugin.logError(e);
//      System.out.println( e.getMessage() );
    } 
    catch (InterruptedException e) 
    {
    	MercurialEclipsePlugin.logError(e);
//      System.out.println( e.getMessage() );
    }

/*    
    IProject proj;
    String Repository;
    Shell shell;
    IWorkbench workbench;
    
    proj=MercurialUtilities.getProject(selection);
    Repository=MercurialUtilities.getRepositoryPath(proj);
    if(Repository==null)
    {<commit_msg>Use TeamUI.getHistoryView().showHistoryFor(resource); instead of TeamUI.showHistoryFor(activePage, resource, null); This compiles under both eclipse 3.2 and 3.3, but I don't know whether it works under 3.3.<commit_after>/*******************************************************************************
 * Copyright (c) 2006-2008 VecTrace (<NAME>) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     VecTrace (<NAME>) - implementation
 *     Software Balm Consulting Inc (<NAME> <pe<EMAIL>>) - some updates
 *     StefanC                   - some updates, code cleanup
 *     <NAME>          - logError
 *******************************************************************************/
package com.vectrace.MercurialEclipse.team;


import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.ui.TeamUI;
//import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import com.vectrace.MercurialEclipse.MercurialEclipsePlugin;

public class ActionChangeLog implements IWorkbenchWindowActionDelegate {

  //    private IWorkbenchPart targetPart;
    private IStructuredSelection selection;
    
  public ActionChangeLog() {
    super();
  }

  /**
   * We can use this method to dispose of any system
   * resources we previously allocated.
   * @see IWorkbenchWindowActionDelegate#dispose
   */
  public void dispose() {

  }


  /**
   * We will cache window object in order to
   * be able to provide parent shell for the message dialog.
   * @see IWorkbenchWindowActionDelegate#init
   */
  public void init(IWorkbenchWindow window) {
  }

  /**
   * The action has been activated. The argument of the
   * method represents the 'real' action sitting
   * in the workbench UI.
   * @see IWorkbenchWindowActionDelegate#run
   */
  

  public void run(IAction action) 
  {
//    final IWorkbenchPage activePage = MercurialEclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final Shell shell = Display.getDefault().getActiveShell();
    try 
    {
      new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress() 
        {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException 
          {
            final IResource resource = (IResource) selection.getFirstElement();
            Runnable r = new Runnable() 
              {
              public void run() 
                {
                  TeamUI.getHistoryView().showHistoryFor(resource);
//                  TeamUI.showHistoryFor(activePage, resource, null);
                }
              };
              Display.getDefault().asyncExec(r);
          }
        });
    } 
    catch (InvocationTargetException e) 
    {
    	MercurialEclipsePlugin.logError(e);
//      System.out.println( e.getMessage() );
    } 
    catch (InterruptedException e) 
    {
    	MercurialEclipsePlugin.logError(e);
//      System.out.println( e.getMessage() );
    }

/*    
    IProject proj;
    String Repository;
    Shell shell;
    IWorkbench workbench;
    
    proj=MercurialUtilities.getProject(selection);
    Repository=MercurialUtilities.getRepositoryPath(proj);
    if(Repository==null)
    {
{'fraction_non_alphanumeric': 0.12950971322849214, 'fraction_numerical': 0.003964583058015066, 'mean_word_length': 3.2781232334652346, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7587791', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2024, 'n_words': 491}